Advertisement
ggoebel

AoC2020 Day 15

Dec 15th, 2020
374
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. my @n = 20,9,11,0,1,2;
  2. my %l; %l{@n} = ^@n;
  3.  
  4. for @n.end..29_999_999 -> $t {
  5.     if $t == %l{@n[$t]} { # first time spoken
  6.         @n[$t+1] = 0;
  7.     }
  8.     else {
  9.         @n[$t+1] = $t - %l{@n[$t]};
  10.         %l{@n[$t]} = $t;
  11.     }
  12.     %l{@n[$t+1]} //= $t+1;
  13. }
  14.  
  15. say "Part One: " ~ @n[2019];
  16. say "Part Two: " ~ @n[29_999_999];
Advertisement
RAW Paste Data Copied
Advertisement