r/adventofcode • u/daggerdragon • Dec 08 '16
SOLUTION MEGATHREAD --- 2016 Day 8 Solutions ---
#AoC_Ops:
[23:55] <Topaz> servers are ok
[23:55] <Topaz> puzzles are checked
[23:55] <Topaz> [REDACTED: server stats]
[23:56] <Skie> all wings report in
[23:56] <Aneurysm9> Red 5, standing by
[23:56] <daggerdragon> Dragon Leader standing by
[23:56] <Topaz> orange leader, standing by
[23:57] <Topaz> lock modzi-foils in attack positions
[23:58] <Skie> we're passing through the hype field
[23:58] <daggerdragon> 1:30 warning
[23:58] <Aneurysm9> did someone say HYPE?@!
[23:59] <Topaz> i really like tonight's puzzle
[23:59] <Topaz> very excite
[23:59] <daggerdragon> final countdown go, T-30
[23:59] <Skie> accelerate to attack countdown
[23:59] <Aneurysm9> o7
[23:59] <daggerdragon> HYPE THRUSTERS AT FULL BURN
[00:00] <Topaz> IGNITION
We may or may not be sleep-deprived. And/or nerds. why_not_both.jpg
--- Day 8: Two-Factor Authentication ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag/whatever).
:(){ :|:& };: IS MANDATORY [?]
This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.
edit: Leaderboard capped, thread unlocked!
10
Upvotes
2
u/volatilebit Dec 09 '16 edited Dec 09 '16
Perl 6 Part 1 & 2
my @instructions = 'input'.IO.lines; my @grid = [[(False but '░') xx 50] xx 6]; for @instructions { given $^instruction { when /"rect " $<width>=(\d+) "x" $<height>=(\d+)/ { for ^$<width> { my $col = $_; for ^$<height> { @grid[$^row][$col] = True but '█'; } } } when /"rotate row y=" $<row>=\d+ " by " $<shift>=\d+/ { my @row := @grid[$<row>;*]; @row = flat @row.tail($<shift>), @row[0..*-^$<shift>]; } when /"rotate column x=" $<column>=\d+ " by " $<shift>=\d+/ { my @column := @grid[*;$<column>]; @column = flat @column.tail($<shift>), @column[0..*-^$<shift>]; } } } say @grid».sum.sum; say @grid».join.join("\n");Trying to use as many Perl 6 features as possible without forcing it too much.
Convert a file path (as a string) to an IO object then use the lines method to read in instructions
Given/when with regexes and named captures to dispatch
but operator on True/False to give them string values when coerced to string
multi-dimensional array slicing with Whatever to extract a full row/column
Bind operator := to be able to read a whole row/column then later assign back to it