Skip to content

Instantly share code, notes, and snippets.

@mcreenan
Last active December 8, 2015 21:55
Show Gist options
  • Save mcreenan/ed9459d2dc5339c4ea37 to your computer and use it in GitHub Desktop.
Save mcreenan/ed9459d2dc5339c4ea37 to your computer and use it in GitHub Desktop.
Advent of Code - Day 8 - Perl6 Solution
#!/usr/bin/env perl6
# Part 1
say [+] 'input'.IO.lines.map: { (m:g/ \\x<[a..f0..9]>**2 /.list.elems * 3) + (m:g/ \\(\"|\\) /.list.elems) + 2 }
# Part 2
say [+] 'input'.IO.lines.map: { (m:g/ \\x<[a..f0..9]>**2 /.list.elems) + (m:g/ \\ (\"|\\) /.list.elems * 2) + 4 }
# Things I learned:
# 1. Using .IO.lines on a filename string to read line-by-line
# 2. Regex modifiers go before first / now
# 3. Hyper operator for doing reduce operations
# 4. Using .list to get group matches
# 5. Using .elems to get number of items in list/array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment