aboutsummaryrefslogtreecommitdiff
path: root/challenge-059/markus-holzer/raku/ch-1.p6
blob: c84d1ab897f915a5d9ac8f1774f2b9f89f24a0cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use LinkedList::Simple;

multi sub MAIN( Bool :$t )
{
	test();
}

multi sub MAIN( Int:D :$k, *@n where { .elems > 1 && .all ~~ Int } )
{
	say LinkedList::Simple
		.from( |@n )
		.roughsort( * < $k )
		.flat
		.join( '→' );
}

sub test
{
	use Test;

	my %tests =
		'2-5-6-7-13-14-18'    => [ 10, ( 2, 5, 13, 14, 6, 7, 18 ) ],
		'2-5-6-7-13-14-18'    => [ 10, ( 13, 2, 5, 14, 6, 7, 18 ) ],
		'1-2-3-4-11-12-13-14' => [ 10, ( 1, 11, 2, 12, 3, 13, 4, 14 ) ],
		'1-1-1-1-2-2-2-2'     => [ 2,  ( 1, 2, 1, 2, 1, 2, 1, 2 ) ],
		'1-2-2-4-3-5'         => [ 3,  ( 1, 4, 3, 2, 5, 2 ) ]
	;

	my &test = {
		ok LinkedList::Simple
			.from( $^test.value[1].flat )
			.roughsort( * < $^test.value[0] )
			.flat
			.join('-') eq $^test.key, $^test.key }
	;

	.&test for %tests;
}