aboutsummaryrefslogtreecommitdiff
path: root/challenge-058/simon-proctor/raku/ch-2.p6
blob: 9159dc5b177553b631155b2b772c5f8effa6a89c (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
#!/usr/bin/env raku

use v6;

#= Reads in user data and finds an ordering.
multi sub MAIN (
    Str $data where *.IO.f #= list of comma seperated heights and expected number before
) {
    my @heights = $data.IO.lines[0].split(",").map( *.Int );
    my @higher = $data.IO.lines[1].split(",").map( *.Int );

    say "Heights      {@heights}";
    say "Requirements {@higher}";

    my @combined = (@heights Z @higher).sort;
    my @final;
    my @indexes = ^@combined.elems;

    for @combined -> ( $height, $pos ) {
        @final[@indexes.splice( $pos, 1 )] = $height;
    }

    say "Final List   {@final}";
}