Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
adding 2010 advent days 6, 7, 8 10
  • Loading branch information
dwarring committed May 11, 2014
1 parent b5e0541 commit 52e0238
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 0 deletions.
40 changes: 40 additions & 0 deletions integration/advent2010-day06.t
@@ -0,0 +1,40 @@
# http://perl6advent.wordpress.com/2010/12/06/the-x-and-z-metaoperators/
use v6;

use Test;

plan 12;

is_deeply [(1, 2) X, (10, 11)], [(1, 10), (1, 11), (2, 10), (2, 11)], 'infix:<X>';
is_deeply [(1, 2) X+ (10, 11)], [11, 12, 12, 13], 'X+';
is_deeply [(1, 2) X~ (10, 11)], ["110", "111", "210", "211"], 'X~';
is_deeply [(1, 2) X== (1, 1)], [Bool::True, Bool::True, Bool::False, Bool::False], 'X==';
is_deeply [(1, 2) Z, (3, 4)], [(1, 3), (2, 4)], 'Z,';
is_deeply [(1, 2) Z+ (3, 4)], [4, 6], 'Z+';
is_deeply [(1, 2) Z== (1, 1)], [Bool::True, Bool::False], 'Z==';
# Z mentioned as being 'buggy' in 2010.12
is_deeply [(1, 2) Z (3, 4)], [(1, 3), (2, 4)], 'infix:<Z>';

my @keys = <a b c>;
my @values = 10, 20, 30;
my %hash = @keys Z=> @values;
is_deeply %hash, {a => 10, b=> 20, c => 30}, 'Z=>';

my @a = (2, 4, 6);
my @b = (5, 10, 15);
my @c = (3, 5, 7);

my @Z-ab = gather for @a Z @b -> $a, $b { take [$a, $b] };
is_deeply @Z-ab, [[2, 5], [4, 10], [6, 15]], '@a Z @b';

my @Z-abc = gather for @a Z @b Z @c -> $a, $b, $c{ take [$a, $b, $c] };
is_deeply @Z-abc, [[2, 5, 3], [4, 10, 5], [6, 15, 7]], '@a Z @b Z @c';

# just do a three sided dice
my @d3 = 1 ... 3;
my @scores = (@d3 X+ @d3) X+ @d3;

is_deeply @scores, [3, 4, 5, 4, 5, 6, 5, 6, 7, 4,
5, 6, 5, 6, 7, 6, 7, 8, 5, 6,
7, 6, 7, 8, 7, 8, 9], 'dice totals';

25 changes: 25 additions & 0 deletions integration/advent2010-day07.t
@@ -0,0 +1,25 @@
# http://perl6advent.wordpress.com/2010/12/07/day-7-lexical-variables/

use v6;

use Test;

plan 8;

dies_ok {EVAL '{ $var = 42 }'};
lives_ok {EVAL '{ my $var = 42 }'};
dies_ok {EVAL '{ my $var = 42 }; say $var'};

sub counter($start_value) {
my $count = $start_value;
return { $count++ };
}

my $c1 = counter(5);
is $c1(), 5;
is $c1(), 6;

my $c2 = counter(42);
is $c2(), 42;
is $c1(), 7;
is $c2(), 43;
24 changes: 24 additions & 0 deletions integration/advent2010-day08.t
@@ -0,0 +1,24 @@
# http://perl6advent.wordpress.com/2010/12/08/different-names-of-different-things/

use v6;

use Test;

plan 7;

is do {flip "hello"}, "olleh";
is do {join ", ", reverse <ab cd ef>}, "ef, cd, ab";

my %capitals = France => "Paris", UK => "London";
is_deeply %capitals.invert, ("Paris" => "France", "London" => "UK").list.item;

my %original := %capitals;
my %inverse;
%inverse.push( %original.invert );

is_deeply %inverse, {"Paris" => "France", "London" => "UK"};

my %h;
%h.push('foo' => 1); is_deeply %h, {foo => 1};
%h.push('foo' => 2); is_deeply %h, {foo => [1, 2]};
%h.push('foo' => 3); is_deeply %h, {foo => [1, 2, 3]};
29 changes: 29 additions & 0 deletions integration/advent2010-day10.t
@@ -0,0 +1,29 @@
# http://perl6advent.wordpress.com/2010/12/10/day-10-feed-operators/

use v6;
use Test;
plan 4;

my @random-nums = (1..100).pick(*);

my $odds-squared-expected = '1 9 25 49 81 121 169 225 289 361 441 529 625 729 841 961 1089 1225 1369 1521 1681 1849 2025 2209 2401 2601 2809 3025 3249 3481 3721 3969 4225 4489 4761 5041 5329 5625 5929 6241 6561 6889 7225 7569 7921 8281 8649 9025 9409 9801';

#?rakudo skip "RT121843"
{
# advent example
my @result;
lives_ok {@result = EVAL q:to"END-CODE"}, 'compiles';
my @odds-squares <== sort <== map { $_ ** 2 } <== grep { $_ % 2 } <== @random-nums;
END-CODE
is ~@result, $odds-squared-expected, 'left feed';
}
{
# watered down - paramterised sortt
my @odds-squared <== sort {$^a <=> $^b} <== map { $_ ** 2 } <== grep { $_ % 2 } <== @random-nums;
is ~@odds-squared, $odds-squared-expected, 'left feed';
}
my @rakudo-people = <scott patrick carl moritz jonathan jerry stephen>;
@rakudo-people ==> grep { /at/ } ==> map { .tc } ==> my @who-it's-at;
is ~@who-it's-at, 'Patrick Jonathan', 'right feed';

0 comments on commit 52e0238

Please sign in to comment.