Skip to content

Instantly share code, notes, and snippets.

@arodland
Created December 7, 2021 06:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arodland/9fb200941da85ddbc252d69e21c6ba39 to your computer and use it in GitHub Desktop.
Save arodland/9fb200941da85ddbc252d69e21c6ba39 to your computer and use it in GitHub Desktop.
use Math::Matrix;
my Int @by_age[9] = (0) xx 9;
for "input.txt".IO.split(",") -> $line {
@by_age[0+$line] += 1;
}
my $mat = Math::Matrix.new([
< 0 0 0 0 0 0 1 0 1 >,
< 1 0 0 0 0 0 0 0 0 >,
< 0 1 0 0 0 0 0 0 0 >,
< 0 0 1 0 0 0 0 0 0 >,
< 0 0 0 1 0 0 0 0 0 >,
< 0 0 0 0 1 0 0 0 0 >,
< 0 0 0 0 0 1 0 0 0 >,
< 0 0 0 0 0 0 1 0 0 >,
< 0 0 0 0 0 0 0 1 0 >,
]);
my $mat80 = $mat ** 80;
my $mat256 = $mat ** 256;
my $in = Math::Matrix.new( [ @by_age, ] );
say ($in dot $mat80).list.sum;
say ($in dot $mat256).list.sum;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment