Before you leave, the Elves in accounting just need you to fix your expense report (your puzzle input); apparently, something isn't quite adding up.
Specifically, they need you to find the two entries that sum to 2020 and then multiply those two numbers together.
For example, suppose your expense report contained the following:
1721
979
366
299
675
1456
In this list, the two entries that sum to 2020 are 1721 and 299. Multiplying them together produces 1721 * 299 = 514579, so the correct answer is 514579.
Of course, your expense report is much larger. Find the two entries that sum to 2020; what do you get if you multiply them together?
*** Input
#+NAME: input-1a
#+begin_example
1664
1939
1658
1791
1011
1600
1587
1930
1846
1955
1885
1793
1876
1905
1997
1900
1956
1981
1890
1612
638
1897
1888
1742
1613
1982
1932
1923
1065
1827
1919
1236
1195
1917
1990
1764
1902
1911
1999
1906
1817
1841
368
747
1881
1941
1894
1898
1887
1958
1862
1940
1819
1873
1959
1977
1301
1945
1961
1673
1879
1889
1872
155
1718
1637
1899
1988
1720
1856
1816
1866
1963
1880
1884
1970
1985
1869
1686
1832
1697
1381
1585
1993
2000
587
1891
1928
1721
1904
1708
1934
1912
1927
1575
1802
2009
1871
1867
1882
1974
1994
784
1868
1967
1842
1771
2001
1843
1621
1926
1978
2003
1921
1815
1757
2005
1699
1960
2007
1626
1944
2008
1611
2004
1991
1924
1875
1915
1920
1810
1805
1936
1968
882
1976
1874
1987
1826
1910
1483
1964
1855
1979
1996
438
1863
1952
1929
1986
1937
1773
1861
1909
1870
1922
1623
1948
1984
1957
1755
1655
1950
1635
2006
1618
1966
1735
1935
1908
1589
1886
1971
1949
1707
1995
1992
1953
1925
1783
1954
1998
1980
1644
1916
1883
1913
1962
1972
1602
1896
1969
1596
1680
1907
1983
1784
1671
1807
1943
#+end_example
*** Solution
#+NAME: solution-1a
#+begin_src emacs-lisp :var input=input-1a
;; Find the numbers that sum to 2020, then multiply them together
(let* ((strlist (split-string input))
(list (seq-map #'string-to-number strlist))
(result 0))
(catch 'return
(while list
(setq n (pop list))
(dolist (m list result)
(when (= (+ n m) 2020)
(message "%d, %d" n m)
(throw 'return (* n m)))))))
#+end_src
#+RESULTS: solution-1a
: 969024
** B
*** Problem
The Elves in accounting are thankful for your help; one of them even offers you a starfish coin they had left over from a past vacation. They offer you a second one if you can find three numbers in your expense report that meet the same criteria.
Using the above example again, the three entries that sum to 2020 are 979, 366, and 675. Multiplying them together produces the answer, 241861950.
In your expense report, what is the product of the three entries that sum to 2020?
*** Solution
#+NAME: solution-1b
#+begin_src emacs-lisp :var input=input-1a
;; Find three numbers this time
(let* ((strlist (split-string input))
(list (seq-map #'string-to-number strlist)))
(catch 'return
(while list
(setq n (pop list))
(setq rest list)
(while list
(setq m (pop list))
(dolist (o list)
(when (= (+ n m o) 2020)
(message "%d, %d, %d" n m o)
(throw 'return (* n m o)))))
(setq list rest))))
#+end_src
#+RESULTS: solution-1b
: 230057040
** Commentary
Today was a decent start, if a little bumpy. I had to go with =elisp= because Org-Mode can't find my =bash= interpreter at work. Which, I mean, this is a good opportunity to get pretty good at elisp.
The hardest part of [[*A][A]] was figuring out how to get the input to a usable state, and finding out about ~catch~ and ~throw~. Once I realized I could walk through the list by ~pop~-ing ~n~ off the front each time and adding it to all the others.
Once I got to [[*B][B]], I thought I could do the same, but I was a little naive -- when I ~pop~-ed ~m~ for the inner loop, I used up the list (of course) before I was able to test for successive values of ~n~. Saving the ~cdr~ of the list and restoring it after the inner ~while~ loop.
At some point, I'm sure, I'll need to figure out the ~loop~ (or ~cl-loop~ ?) macro.
To try to debug the problem, they have created a list (your puzzle input) of passwords (according to the corrupted database) and the corporate policy when that password was set.
For example, suppose you have the following list:
1-3 a: abcde
1-3 b: cdefg
2-9 c: ccccccccc
Each line gives the password policy and then the password. The password policy indicates the lowest and highest number of times a given letter must appear for the password to be valid. For example, 1-3 a means that the password must contain a at least 1 time and at most 3 times.
In the above example, 2 passwords are valid. The middle password, cdefg, is not; it contains no instances of b, but needs at least 1. The first and third passwords are valid: they contain one a or nine c, both within the limits of their respective policies.
How many passwords are valid according to their policies?
I think I've formatted the regex wrong; I also need to throw an error if there are too /many/ of the character! So the regex for =2-7 b= should look more like ... =^[^b]*b.*b.*b?.*b?.*[^b]*$=
While it appears you validated the passwords correctly, they don't seem to be what the Official Toboggan Corporate Authentication System is expecting.
The shopkeeper suddenly realizes that he just accidentally explained the password policy rules from his old job at the sled rental place down the street! The Official Toboggan Corporate Policy actually works a little differently.
Each policy actually describes two positions in the password, where 1 means the first character, 2 means the second character, and so on. (Be careful; Toboggan Corporate Policies have no concept of "index zero"!) Exactly one of these positions must contain the given letter. Other occurrences of the letter are irrelevant for the purposes of policy enforcement.
Given the same example list from above:
1-3 a: abcde is valid: position 1 contains a and position 3 does not.
1-3 b: cdefg is invalid: neither position 1 nor position 3 contains b.
2-9 c: ccccccccc is invalid: both position 2 and position 9 contain c.
How many passwords are valid according to the new interpretation of the policies?
*** Solution
Okay, I can reuse some code from part A here. Namely, the parsing part (which I should break out into its own function) of the spec.
#+NAME:solution-2b
#+begin_src emacs-lisp :var input=input-2
(defun test-pw (spec password)
"Return whether a PASSWORD works with the SPEC.
PASSWORD is a string.
SPEC is a string of the form <min>-<max> <char>."
(let* ((split-spec (split-string spec "[ -]"))
(min-string (car split-spec))
(max-string (cadr split-spec))
(chr-string (caddr split-spec))
(min (string-to-number min-string))
(max (string-to-number max-string))
(chr (string-to-char chr-string)))
(if (xor (found-at chr password min)
(found-at chr password max))
1
0)))
(defun found-at (item sequence position &optional eq-func)
"Determine whether ITEM occurs at POSITION in SEQUENCE."
Today was trickier, as of course it would be. Once I figured out the counting thing, instead of the /awful/ regex (as cYmen said, "Some people, when confronted with a problem, will decide 'hey, i can solve this using regular expressions'. Now they have two problems."), it wasn't so bad. I need to make sure not to stay up so late tonight.
With the toboggan login problems resolved, you set off toward the airport. While travel by toboggan might be easy, it's certainly not safe: there's very minimal steering and the area is covered in trees. You'll need to see which angles will take you near the fewest trees.
Due to the local geology, trees in this area only grow on exact integer coordinates in a grid. You make a map (your puzzle input) of the open squares (.) and trees (#) you can see. For example:
#+begin_example
..##.......
#...#...#..
.#....#..#.
..#.#...#.#
.#...##..#.
..#.##.....
.#.#.#....#
.#........#
#.##...#...
#...##....#
.#..#...#.#
#+end_example
These aren't the only trees, though; due to something you read about once involving arboreal genetics and biome stability, the same pattern repeats to the right many times:
You start on the open square (.) in the top-left corner and need to reach the bottom (below the bottom-most row on your map).
The toboggan can only follow a few specific slopes (you opted for a cheaper model that prefers rational numbers); start by counting all the trees you would encounter for the slope right 3, down 1:
From your starting position at the top-left, check the position that is right 3 and down 1. Then, check the position that is right 3 and down 1 from there, and so on until you go past the bottom of the map.
The locations you'd check in the above example are marked here with O where there was an open square and X where there was a tree:
In this example, traversing the map using this slope would cause you to encounter 7 trees.
Starting at the top-left corner of your map and following a slope of right 3 and down 1, how many trees would you encounter?
*** Input
#+NAME: input-3
#+begin_example
.#...#.......#...#...#.#.#.....
####.....#.#..#...#...........#
.....#...........#......#....#.
......#..#......#.#..#...##.#.#
............#......#...........
...........#.#.#....#.......##.
....#.......#..............#...
........##...#.#.....##...##.#.
.#.#.....##................##..
.##................##..#...##..
....#...###...##.........#....#
.##......#.........#...........
...#.#.#....#....#...#...##...#
..#....##...#..#.#..#.....#.#..
.......#...#..#..#.....#...#..#
.....#......#.......#.....#.#..
....#..#...#..#####....##......
.#...........#......#....#....#
#......#.###.....#....#....#...
....#..#.#.#..#...........##...
..#..#..#.#...#......#....#.##.
.##....#......#...#.#..#.......
..###.#...#.........#.#.#...#.#
#....###.........#...#...#...#.
...##.#............#...##......
...#.........#............#....
......##...#...##..#...........
........##..#.#.####...#.....#.
.##.........#......#..#..#...#.
..........#...#..........#.....
#..........#........#..#..#.#..
..#....#.#.#.#.#..#.##.........
##.#.#.##.....#..#......###....
##....#...#.....#..............
.#..#...#...#....###......#....
#....#......#.#..#.#........###
.#....#..#...###....#...##.....
.#....#.....#.....#..##..#.....
#....#.##...#...#..#.##.##.#...
.#.#.#.##...#####.............#
......##..#.....##..#...####...
#.##..#.#....#..##.......###..#
..#.......##....#........#.##..
#.....#......#.....#....#..#...
.......##...#.....##.......#..#
.......#...#.#.#.........#####.
#.......#.##..##........##.....
##..#...#........##....#.......
.......#...##......##...##.##..
......#..##..#.#...#...#....##.
....#.#..#.....#.##.#.....#.#..
#..#.#.#........#...#.......##.
##...........#..#........#.....
....##....#....#.#.......#.....
....##.#.#.....#.#.....#.....#.
..........#.#..##..#..#.......#
#....#.......##...#...#.....#..
.........##.....#.#....#......#
..........#........#..#..#.#...
..#......#.....#......#......#.
..#...###..##..#.....##..#..##.
..#.#..###.........#.#...##.#.#
#.........#..#......#...##.....
...#...#.#..#...##.#...##.#..#.
#.....#.....#.##....#.#......#.
#....##..##..#.#..##....#.....#
.#..........#..#...#..#.......#
#.#.....#..##..##..#.#.........
....#..##...#.....#.....#.#.#.#
...#.#....#........#...#.#.....
.#............#.......#.##.#...
..##.......#.#...#........##..#
..................##.#...#.#..#
.#.........#.......#.....#.....
....##...##..#..........#......
..#.##..#....#..#............#.
....####...#.##....##.#....#.##
#..#....#......##........##....
..###...........##..#......#...
#..#.......#........#.......#..
.....#....#..#..##.....#.......
.###.####.#....#....#..#.......
.............#...............#.
.#..........#.#....#..#.#......
..............##....#..#....##.
.......#.#..#........#.......##
#..#...#..#.#........#..#....#.
...#.........#...#..#..........
...#....##...#..#..........#...
.#......#......##..##...#.#....
.#.........#..###..............
.................#.#.....##....
...#............#..............
#..#................#.......#..
...#.......#......#.#.#........
#.....#.##....#.....#........#.
......##.#....#........#....#..
.#..#.##...##........#.#.....#.
..#...#....#...#..#..##..#.#..#
#.................#.#.......##.
..........#........#.#.....#..#
#....##....#........##..##.#...
#...#....#.....#.....#.....#...
#..#..........#....##....#....#
..#.#..#..#....#.#....#....#..#
#....#..#.......#..........#...
.#...#.#...#..#...#.......#....
###........#......##..#...##...
...#..........##..............#
.......#........##......#.....#
.#..........#...#...##....###.#
.#...#....#..#.....##...#..##..
.#.#.#...##..........##...#...#
.#.....#...#........#........##
#.......#......##.#.#..#....#..
##..#.##........#....#..#......
...#.......................#...
..#....#..##........##.#.##.#..
.............#.......#....#.#.#
...#...........##..#.....#.....
..#....##....#.....#...........
..#.....#......#..#.###.##....#
.#.......#...........#...#....#
#............##...#...#.....#..
##...#.....#.........##...##...
...#...........#....##.........
#.##..#..........##..#......#..
.......#.#.......##.......#....
..#.....##..#...#.......#......
.#........#....##...........#..
#.......#...#.#.###...#....#...
..........##..#..#..##........#
#....#....#...#....#....#......
...........#....#...#...##.#...
.........#.#.....#.............
..####...........##..........#.
.....#...................#.....
#..##...#........#.###.#.##....
....##...#.##................#.
.#........###.#............#.#.
..............#.##.........#...
##............#.#..###....#...#
#.....#........####....#....##.
....##..#...##..##...##.....#..
##..#....#.##.....####.....#.##
##..#....#.##.##.#.#........#..
....#..........##.....#..#..#..
...#.......#........#.........#
#..##.######.......##........#.
###...#...####.......#.....#...
#......#..#.....#......#.....#.
..................##...#.......
....#.#....#......#...#.....##.
..#..#..#..#..#....#.#...#....#
......#....###.................
#.##......#...#......#.........
#..#.#...##..#.......#..#...#..
.#....#.#........#.........#...
#.......##..#..#...............
........#..##....#.....#..#....
....#......##..#....#...#..#...
#.....#...##..#...#......#.....
.....#.....#.........##...#..#.
........#...##.#...#.#....#..##
....#....#...#.....##..#...#...
#....#..#.........#.........###
..###.....##...#.#....##......#
#..#.#..#.......#..#....##.....
###...#.##..#.......#......#...
.....#.....##.......#...##..#..
......#.......#.#.#......#..#..
.................##..#.###.....
..........#....#...#..........#
...#.#...#.#..##.....#.#.##..#.
.......#..#....#...#......###..
...##..........#..#.....#....#.
.#..##..###...#....##.....#....
..#.#..............#....#...#..
.....####.......#.#.##....#....
#.#.#..##.##.#..#.##.#....#..#.
........#....#.......##........
...#...#....#...###.....###....
.....#..#..........##.#...##.##
..#.#.#..#....#...#..##...#...#
..#......#..#.#.....#....#....#
.#.....#.......#............#..
#..##....#...#....##....#......
#..#.........#...#...###.#..#..
..#.#.#..#.#..#.......##.......
...##...............#..#...#.#.
.......####.#.....#..#..#......
......#..#.....#..##....#......
....#...#.........##.......#.#.
#.#.#...#.....#...#..#.#..#....
........#..#.........#..#..##..
........###.#............#.#...
#..#.......#.#..#.......#...#.#
..##..............#.#.....#...#
..##...........................
..#.....#.......#......##......
#...#......##.#....#.#.#...##.#
#...#.#......#.#..##.........#.
.##..#...#.#.....#.#.#...#.#..#
.#..#...#.#.........#......#...
...........#...#...#...#..#.#..
.#........#...#......##...#.###
#........#..#.#..#...........##
.#...#...####.......#..........
......#...............#........
.....#.#.....#.#...#......#....
.#........#...........#..##.#..
....#..#.....###.......#...#...
#.#.........#...##..#.#.##.#...
................##.#....#.#...#
.......#.......#......#...#....
#....#.#..............#.##..###
..##.##..#.....#............#..
#....#..##........#....#.......
.#.#........#.#................
......##..#..#..........#..#.#.
.....##.#..#....##.#......##...
........###.#................#.
#..###.....#.###.#...#.#.......
.#..#.#.#.#..#..#.#.....#.#....
#....#.....#..#......##...#..##
........#...##..#.#.....#....#.
.......#..#..#..#....#.....##..
....#..##..#...#....#.........#
#.#....#..#.#...#.#...#....#...
.....#......###.......#..##.#.#
.......##.....#....#........#.#
.##.##..#..###.#....#.#.....#..
..##.#.......###.........#.....
.#...#......#..#....#..........
.....#........#.....##...#.....
..#......#.#.#..#.#....##.#...#
#.#...#...........##......#....
.................##.....#.#.##.
###..#....#..................#.
##..#.#.#...#....###.#.#...##.#
#.#.#..#....#..............#...
.....#....#......#..#.##.......
#...#...#..###.......#.......#.
.....#.#........#..#...#.#.....
.....#..........#.###.......#..
...#.##.....#....###.....#.....
####........#....#..#.#.##.#...
#......#...##.....#.#..##.#.#.#
.....##....#..#.........##.....
..##....##................##..#
#.....#...##...##.#.....#...#..
..#..#.#.#....#.#.......#......
##.....##......#...#.........#.
#..........#........#.#......#.
.#..#.......#.#.....#..........
.........#.#.......#.#..#..#..#
#......#....#....#..##..##...##
.....#..#...#.......#.....##...
..#.##........#.###...#...#...#
..#..#...........#..........#..
.#.#.#...#.##.#..............#.
....#..##.......#.....#..##..#.
.#.##.#....##........#...##.##.
...#.#...#....#....#......#####
.....#.....##...........#......
#........#.##.......#.#.......#
#...#.......##.#.......#..#.#..
#...##..#....#............#.#..
........#.#..#...#..#...##..##.
#...#....#............#........
#.#.#.#.#....##.....##.........
......##.........#.......#.#..#
...#.#....#........#...........
...#.#.......#.....#...........
##....####......##.##..#.......
#......#...#..#.#..#......#..#.
#......#.#....#....#..#........
..#.###...#.....#........#.#...
..#.....##.....###....#.....#..
#.##.#.....##....#...###.......
###.#....###.#..##.#.......##.#
#..#..##...#.#..........##.##..
.......####.#..#.....##..###...
#...#...##..#..##.......###....
#....#.........##..#.........#.
.....#.#..........#..#...#.#..#
..........#......##..#..#.#....
.#...#...#...#........###....##
#....#.##..........#.#.....#.#.
#....##.#.##..#.......#.#.....#
.##..##..#.#...#.#...........#.
....##..#...#.#.##.#.#...#.....
.#...#.##........#.##..#.#....#
.#.....##.........#.....#......
..#.....#.#..#.##.............#
##....##...#....##........#....
.#....#........#.#..#..#..#.##.
.#........#............#.......
.#..##..##..#..#..####....#....
..#.###....#..#.##......#.#...#
.###..#.#...##....##....#..##.#
....##........#....#.#.#...##..
...#..#....#.#....#...#.#.....#
...##....##..#....#.........#..
.....#..##.###..#.....####.....
...#..#.........#....#.#.##..#.
...#..#...............#..#....#
...........#.....#...####..##.#
..#......#...#....#..#...##.#..
.....#..#...........#.......#.#
##....###...#.........#....#...
...#..##.......#.#.....##....#.
#.#...#.#....#.....#...##.....#
.#...##....#.....#..##.......#.
...#........##..........#.....#
#...##..#.#....###...#..#......
............#.......#......#.#.
......#....#.#...#...#..#......
.#..#......#....#.......#....##
...#...#.......###..###...#....
.............#.#...#..###.....#
.#.....#........#...##....#..#.
.....#.......#######.#.#...#...
#+end_example
*** Solution
Okay, let's think this through first. The map loops horizontally, which means I can use modulus math for some of it. The sled will encounter a new line every 3 steps ... so I /think/ that's the ... moderand? The thing I'm modding against.
#+NAME: 3a-lib
#+begin_src emacs-lisp :var input=input-3
(defun calc-position (slope line-number line)
"Calculate where we are in the line."
(mod (* slope n) (length l)))
(defun replace-char (line position char)
"Replace character in LINE at POSITION with CHAR."
(let ((pre (if (= position 0)
""
(substring line 0 position)))
(post (if (= position 0)
(substring line 1)
(substring line (+ 1 position)))))
(concat pre (string char) post)))
(defun collisionp (line position char)
"If the character at POSITION in LINE is CHAR, return t."
Time to check the rest of the slopes - you need to minimize the probability of a sudden arboreal stop, after all.
Determine the number of trees you would encounter if, for each of the following slopes, you start at the top-left corner and traverse the map all the way to the bottom:
- Right 1, down 1.
- Right 3, down 1. (This is the slope you already checked.)
- Right 5, down 1.
- Right 7, down 1.
- Right 1, down 2.
In the above example, these slopes would find 2, 7, 3, 4, and 2 tree(s) respectively; multiplied together, these produce the answer 336.
What do you get if you multiply together the number of trees encountered on each of the listed slopes?
Okay, my solution so far is general enough that I can easily figure out the answers for 1-1, 5-1, and 7-1. 1-2 will be trickier though, since I'm skipping rows. Still, shouldn't be too too difficult. It has to do with /n/, I think.
I'm sure there's a way to grab all the results and multply them together, but I don't know what it is. For now, I'll just /look/ at them all and .. multiply em.
You arrive at the airport only to realize that you grabbed your North Pole Credentials instead of your passport. While these documents are extremely similar, North Pole Credentials aren't issued by a country and therefore aren't actually valid documentation for travel in most of the world.
It seems like you're not the only one having problems, though; a very long line has formed for the automatic passport scanners, and the delay could upset your travel itinerary.
Due to some questionable network security, you realize you might be able to solve both of these problems at the same time.
The automatic passport scanners are slow because they're having trouble detecting which passports have all required fields. The expected fields are as follows:
#+begin_example
byr (Birth Year)
iyr (Issue Year)
eyr (Expiration Year)
hgt (Height)
hcl (Hair Color)
ecl (Eye Color)
pid (Passport ID)
cid (Country ID)
#+end_example
Passport data is validated in batch files (your puzzle input). Each passport is represented as a sequence of key:value pairs separated by spaces or newlines. Passports are separated by blank lines.
Here is an example batch file containing four passports:
#+begin_example
ecl:gry pid:860033327 eyr:2020 hcl:#fffffd
byr:1937 iyr:2017 cid:147 hgt:183cm
iyr:2013 ecl:amb cid:350 eyr:2023 pid:028048884
hcl:#cfa07d byr:1929
hcl:#ae17e1 iyr:2013
eyr:2024
ecl:brn pid:760753108 byr:1931
hgt:179cm
hcl:#cfa07d eyr:2025 pid:166559648
iyr:2011 ecl:brn hgt:59in
#+end_example
The first passport is valid - all eight fields are present. The second passport is invalid - it is missing hgt (the Height field).
The third passport is interesting; the only missing field is cid, so it looks like data from North Pole Credentials, not a passport at all! Surely, nobody would mind if you made the system temporarily ignore missing cid fields. Treat this "passport" as valid.
The fourth passport is missing two fields, cid and byr. Missing cid is fine, but missing any other field is not, so this passport is invalid.
According to the above rules, your improved system would report 2 valid passports.
Count the number of valid passports - those that have all required fields. Treat cid as optional. In your batch file, how many passports are valid?
The line is moving more quickly now, but you overhear airport security talking about how passports with invalid data are getting through. Better add some data validation, quick!
You can continue to ignore the cid field, but each other field has strict rules about what values are valid for automatic validation:
#+begin_example
byr (Birth Year) - four digits; at least 1920 and at most 2002.
iyr (Issue Year) - four digits; at least 2010 and at most 2020.
eyr (Expiration Year) - four digits; at least 2020 and at most 2030.
hgt (Height) - a number followed by either cm or in:
If cm, the number must be at least 150 and at most 193.
If in, the number must be at least 59 and at most 76.
hcl (Hair Color) - a # followed by exactly six characters 0-9 or a-f.
ecl (Eye Color) - exactly one of: amb blu brn gry grn hzl oth.
pid (Passport ID) - a nine-digit number, including leading zeroes.
cid (Country ID) - ignored, missing or not.
#+end_example
Your job is to count the passports where all required fields are both present and valid according to the above rules. Here are some example values:
Count the number of valid passports - those that have all required fields and valid values. Continue to treat cid as optional. In your batch file, how many passports are valid?
*** Solution
Okay, this shouldn't be /too/ bad. I just need to add to my =validate-record= function.
#+NAME: 4b
#+begin_src emacs-lisp
<<aoc>>
;; required fields
(setq *rqfs*
'(byr
iyr
eyr
hgt
hcl
ecl
pid))
;; optional fields
(setq *opfs*
'(cid))
(defun parse-record (rec)
"Parse a record of form KEY:VAL [KEY:VAL]... into an alist."
(let ((fields (split-string rec))
(result))
(dolist (f fields result)
(let ((p (split-string f ":")))
(add-to-list 'result (cons (car p) (cadr p)))))))
(defun validate-byr (byr)
"BYR should be four digits; between 1920 and 2002."
(<= 1920 (string-to-number byr) 2002))
(defun validate-iyr (iyr)
"IYR should be four digits; between 2010 and 2020."
(<= 2010 (string-to-number iyr) 2020))
(defun validate-eyr (eyr)
"EYR should be four digits; between 2020 and 2030."
(<= 2020 (string-to-number eyr) 2030))
(defun validate-hgt (hgt)
"HGT should be a number followed by CM or IN.
If CM, the number should be between 150 and 193.
If IN, the number should be between 59 and 76."
(cond ((string-match (rx "cm" eos) hgt)
(<= 150 (string-to-number hgt) 193))
((string-match (rx "in" eos) hgt)
(<= 59 (string-to-number hgt) 76))
(t nil)))
(defun validate-hcl (hcl)
"HCL should be six hexadecimal digits preceded by a #."
"ECL should be one of AMB BLU BRN GRY GRN HZL OTH."
(string-match (rx bos
(or "amb"
"blu"
"brn"
"gry"
"grn"
"hzl"
"oth")
eos) ecl))
(defun validate-pid (pid)
"PID should be nine decimal digits."
(string-match (rx bos (repeat 9 digit) eos) pid))
(defun validate-record (record)
"Validate a RECORD -- does it have all required fields?"
(let ((result '()))
(dolist (required-field *rqfs* result)
(if-let ((field (car (assoc-string required-field record t)))
(value (cdr (assoc-string required-field record t))))
(progn
(push (cond ((string= field "byr")
(message "%S %S %S" field value (validate-byr value))
(validate-byr value))
((string= field "iyr")
(message "%S %S %S" field value (validate-iyr value))
(validate-iyr value))
((string= field "eyr")
(message "%S %S %S" field value (validate-eyr value))
(validate-eyr value))
((string= field "hgt")
(message "%S %S %S" field value (validate-hgt value))
(validate-hgt value))
((string= field "hcl")
(message "%S %S %S" field value (validate-hcl value))
(validate-hcl value))
((string= field "ecl")
(message "%S %S %S" field value (validate-ecl value))
(validate-ecl value))
((string= field "pid")
(message "%S %S %S" field value (validate-pid value))
(validate-pid value))
(t "WHAT"))
result))
(push nil result)))
(every (lambda (i) (not (eq i nil))) result)))
(aoc
input "\n\n"
(let ((records)
(result 0))
(dolist (record lines result)
(let ((rec (parse-record record)))
(if (validate-record rec)
(incf result))))))
#+end_src
#+RESULTS: 4b
: 160
Damn, *203* is too high. At least I'm getting a somewhat /meaningful/ number; it turns out regexen in Emacs are totally fucked. That's why there's a whole macro to make them easier to write, I guess.
Okay, too high -- that means that I'm getting false positives somewhere.
*** SUCCESS
OMG. I just had to ~(push nil result)~ on failure --- duh. I had removed that because I'd had ~(push result nil)~ earlier, which of course isn't the right order of operations. But that was allowing some bad things to be ignored, which made my answer too high. Ah well.
* Day 5
:PROPERTIES:
:header-args: :var input=input-5
:END:
** Input
#+NAME: input-5
#+begin_example
FFFBFBFLRR
FFBBFFFRLL
FBFBFFBRLR
FFFBBFBRRL
BFFFBBFRRL
FFBFBFFLLR
FBFBBFFRLL
FFBBFBBLLL
BFFFBBFLLR
FBBFFBBRLR
FBFBBBBLLL
BFFBBBFLLR
BBFFBFBLRR
FBBBFFBRRL
FFFBFBBLRL
FFBFBFBRLR
FBBBBFFRRL
FBBBBFBLLR
BFBBBBFRRR
BFBFFBBLRL
FBBFBBFRLL
FFBBBFBRLR
FBBFFFBRLL
FBFBBFBLRR
FFFBBBFLLL
FBFFBBFLRL
BFFFBFFLLR
FBFBBBBLRL
FBBFBFFRLR
FBFBBBBRLL
FFBFFBFLLR
BFFBFFBRLL
FBBBBFFLRL
BFFBFBBRLR
FFBFFFFLLR
BBFFBBFRLR
BFBFBBBRRL
BFFBBBBLRR
FFBBBBBRLL
FFFBBFFRLR
BBFFFFBLRL
BFBBFBFRRL
BBFFBBFRRL
FBFFFFBRLR
FBBFBBBRLR
BBFBFFFLLL
BFBFBBBRLL
BFFFFFFLRL
FBFBFBFRRR
BBFFFFFLRR
FFFBBFBLLR
FBFFBFBRLL
BFBBFBFLLR
FFBFBFFLRL
BFBFFBFRRR
FBBBBBFRLR
FBBFFBBLLR
FBFBBFFLRL
FBFFFBFRRL
BFFBFFFLRR
FFBFBFBLRL
FBFFBBBLRR
BFBBFFFLLR
FBFBBBBRLR
FBFFFBBRRL
FFFBBBFRRL
FBBBBBBLRR
FBBBFBBRRL
FBBBFBBRRR
BFFFBFBLRL
FBBBFFBR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BBBLLL
BFFFBBBLRR
BFBBFFFLLL
FBFBFBBRLL
BFFFFFBLLL
BBFBFFFLRR
BFBFFBBRLL
FFBFBBFRRL
FBFBBBFLLL
FBFFFFBLLL
FBFFBFFLLR
FBBFBBFRRL
BBFFBBFRRR
BFFFBFBRRL
BFBFFFBRLR
FBBFFBFLLR
BFBFFFFRLL
BFBFBBBRRR
BFBFFFFRLR
FFBFBFBLLR
FBFFFBFLRR
FFBBBBBRRR
FBBFFFBLRR
FFBFFFBRLR
BFFFBFBRRR
FBBFBBBLLR
BFBBBBBLRL
FBBBFFFLRL
BFFBBFFRRR
BFBBBFFRLL
BFBFFFFLLR
BFFBFFFLRL
BFBFFFFRRR
BBFFFFFRLR
FBFFFBFRLL
FFFBBBFRRR
BFFFBFBLLR
FBBFBFFRLL
FBBBFBBLLL
BFBBBBBRLL
BFFBBBFRRR
FFFBFBFRRR
BFBBBFBRRL
FBFFBFBLLL
FBBBFFFRLR
FBFBBFFRRL
FBBFFBFRRL
FBBFBFBLRR
BFFFFFBLRL
FBBBFBFRRR
BFFFBBBLLL
FFBBBFBRLL
#+end_example
** Part 1
*** Problem
--- Day 5: Binary Boarding ---
You board your plane only to discover a new problem: you dropped your boarding pass! You aren't sure which seat is yours, and all of the flight attendants are busy with the flood of people that suddenly made it through passport control.
You write a quick program to use your phone's camera to scan all of the nearby boarding passes (your puzzle input); perhaps you can find your seat through process of elimination.
Instead of zones or groups, this airline uses binary space partitioning to seat people. A seat might be specified like FBFBBFFRLR, where F means "front", B means "back", L means "left", and R means "right".
The first 7 characters will either be F or B; these specify exactly one of the 128 rows on the plane (numbered 0 through 127). Each letter tells you which half of a region the given seat is in. Start with the whole list of rows; the first letter indicates whether the seat is in the front (0 through 63) or the back (64 through 127). The next letter indicates which half of that region the seat is in, and so on until you're left with exactly one row.
For example, consider just the first seven characters of FBFBBFFRLR:
#+begin_example
Start by considering the whole range, rows 0 through 127.
F means to take the lower half, keeping rows 0 through 63.
B means to take the upper half, keeping rows 32 through 63.
F means to take the lower half, keeping rows 32 through 47.
B means to take the upper half, keeping rows 40 through 47.
B keeps rows 44 through 47.
F keeps rows 44 through 45.
The final F keeps the lower of the two, row 44.
#+end_example
The last three characters will be either L or R; these specify exactly one of the 8 columns of seats on the plane (numbered 0 through 7). The same process as above proceeds again, this time with only three steps. L means to keep the lower half, while R means to keep the upper half.
For example, consider just the last 3 characters of FBFBBFFRLR:
#+begin_example
Start by considering the whole range, columns 0 through 7.
R means to take the upper half, keeping columns 4 through 7.
L means to take the lower half, keeping columns 4 through 5.
The final R keeps the upper of the two, column 5.
#+end_example
So, decoding FBFBBFFRLR reveals that it is the seat at row 44, column 5.
Every seat also has a unique seat ID: multiply the row by 8, then add the column. In this example, the seat has ID 44 * 8 + 5 = 357.
Here are some other boarding passes:
#+begin_example
BFFFBBFRRR: row 70, column 7, seat ID 567.
FFFBBBFRRR: row 14, column 7, seat ID 119.
BBFFBBFRLL: row 102, column 4, seat ID 820.
#+end_example
As a sanity check, look through your list of boarding passes. What is the highest seat ID on a boarding pass?
*** Solution
Okay, so I might've got a few spoiler-y ideas from =#adventofcode= ... though I don't understand them. Let me think on this problem a bit. I'm definitely doing a binary search thing.
I /think/ I get the binary code thing now ... basically, you can encode the F as 0 and the B as 1 .. let's see.
#+begin_example
BFFFBBFRRR
BFFFBBF
B 1 - 128
F 0 - 64
F 0 - 32
F 0 - 16
B 1 - 8
B 1 - 4
F 0 - 2
1000110 = 70. CORRECT
FFFBBBFRRR
FFFBBBF
0001110 => 14. CORRECT
#+end_example
DOPE! Also, I'm looking at the seat ID ... "multiply the row by 8, then add the column." Multiplying a number by 8 is the same as shifting it by 3, right?
#+begin_example
0001 -> 1000
1 -> 8
000100101010 -> 100101010000
298 -> 2384
x8 = 2384
#+end_example
*DOPE*
I think I'm ready for the solution now.
#+begin_src emacs-lisp :noweb yes
<<aoc>>
(defun notation-to-binary (notation)
"Convert notation of seat to binary."
(let ((result)
(list (string-to-list notation)))
(dolist (c list result)
(push (cond ((eq c ?F)
?0)
((eq c ?B)
?1)
((eq c ?L)
?0)
((eq c ?R)
?1))
result))
(concat (reverse result))))
(aoc
input nil
(let ((result))
(dolist (line lines result)
(let ((binary-string (notation-to-binary line)))
(push (list line
binary-string
(string-to-number binary-string 2))
result)))
(reverse result)))
#+end_src
#+RESULTS:
| FFFBFBFLRR | 0001010011 | 83 |
| FFBBFFFRLL | 0011000100 | 196 |
| FBFBFFBRLR | 0101001101 | 333 |
| FFFBBFBRRL | 0001101110 | 110 |
| BFFFBBFRRL | 1000110110 | 566 |
| FFBFBFFLLR | 0010100001 | 161 |
| FBFBBFFRLL | 0101100100 | 356 |
| FFBBFBBLLL | 0011011000 | 216 |
| BFFFBBFLLR | 1000110001 | 561 |
| FBBFFBBRLR | 0110011101 | 413 |
| FBFBBBBLLL | 0101111000 | 376 |
| BFFBBBFLLR | 1001110001 | 625 |
| BBFFBFBLRR | 1100101011 | 811 |
| FBBBFFBRRL | 0111001110 | 462 |
| FFFBFBBLRL | 0001011010 | 90 |
| FFBFBFBRLR | 0010101101 | 173 |
| FBBBBFFRRL | 0111100110 | 486 |
| FBBBBFBLLR | 0111101001 | 489 |
| BFBBBBFRRR | 1011110111 | 759 |
| BFBFFBBLRL | 1010011010 | 666 |
| FBBFBBFRLL | 0110110100 | 436 |
| FFBBBFBRLR | 0011101101 | 237 |
| FBBFFFBRLL | 0110001100 | 396 |
| FBFBBFBLRR | 0101101011 | 363 |
| FFFBBBFLLL | 0001110000 | 112 |
| FBFFBBFLRL | 0100110010 | 306 |
| BFFFBFFLLR | 1000100001 | 545 |
| FBFBBBBLRL | 0101111010 | 378 |
| FBBFBFFRLR | 0110100101 | 421 |
| FBFBBBBRLL | 0101111100 | 380 |
| FFBFFBFLLR | 0010010001 | 145 |
| BFFBFFBRLL | 1001001100 | 588 |
| FBBBBFFLRL | 0111100010 | 482 |
| BFFBFBBRLR | 1001011101 | 605 |
| FFBFFFFLLR | 0010000001 | 129 |
| BBFFBBFRLR | 1100110101 | 821 |
| BFBFBBBRRL | 1010111110 | 702 |
| BFFBBBBLRR | 1001111011 | 635 |
| FFBBBBBRLL | 0011111100 | 252 |
| FFFBBFFRLR | 0001100101 | 101 |
| BBFFFFBLRL | 1100001010 | 778 |
| BFBBFBFRRL | 1011010110 | 726 |
| BBFFBBFRRL | 1100110110 | 822 |
| FBFFFFBRLR | 0100001101 | 269 |
| FBBFBBBRLR | 0110111101 | 445 |
| BBFBFFFLLL | 1101000000 | 832 |
| BFBFBBBRLL | 1010111100 | 700 |
| BFFFFFFLRL | 1000000010 | 514 |
| FBFBFBFRRR | 0101010111 | 343 |
| BBFFFFFLRR | 1100000011 | 771 |
| FFFBBFBLLR | 0001101001 | 105 |
| FBFFBFBRLL | 0100101100 | 300 |
| BFBBFBFLLR | 1011010001 | 721 |
| FFBFBFFLRL | 0010100010 | 162 |
| BFBFFBFRRR | 1010010111 | 663 |
| FBBBBBFRLR | 0111110101 | 501 |
| FBBFFBBLLR | 0110011001 | 409 |
| FBFBBFFLRL | 0101100010 | 354 |
| FBFFFBFRRL | 0100010110 | 278 |
| BFFBFFFLRR | 1001000011 | 579 |
| FFBFBFBLRL | 0010101010 | 170 |
| FBFFBBBLRR | 0100111011 | 315 |
| BFBBFFFLLR | 1011000001 | 705 |
| FBFBBBBRLR | 0101111101 | 381 |
| FBFFFBBRRL | 0100011110 | 286 |
| FFFBBBFRRL | 0001110110 | 118 |
| FBBBBBBLRR | 0111111011 | 507 |
| FBBBFBBRRL | 0111011110 | 478 |
| FBBBFBBRRR | 0111011111 | 479 |
| BFFFBFBLRL | 1000101010 | 554 |
| FBBBFFBRLR | 0111001101 | 461 |
| BFBFFFBRRR | 1010001111 | 655 |
| BFBBFBBLRL | 1011011010 | 730 |
| BBFFBBFLRR | 1100110011 | 819 |
| FFFBFBFLLR | 0001010001 | 81 |
| FFBBBBFRRL | 0011110110 | 246 |
| BFBFBFFRRR | 1010100111 | 679 |
| FBFBBBBRRR | 0101111111 | 383 |
| BFFFBFFRLL | 1000100100 | 548 |
| BFBBFBBLLL | 1011011000 | 728 |
| FBFBFBBRLR | 0101011101 | 349 |
| BFFFBFBRLL | 1000101100 | 556 |
| FFBBFFBRLL | 0011001100 | 204 |
| FBFFBBFRLL | 0100110100 | 308 |
| FBFBFFFRRR | 0101000111 | 327 |
| FFBFBBBLLL | 0010111000 | 184 |
| BBFFBBBLRR | 1100111011 | 827 |
| FBBFFBBRLL | 0110011100 | 412 |
| BFFFFFBRRL | 1000001110 | 526 |
| FBBFFBFLLL | 0110010000 | 400 |
| FBFBFBFLRL | 0101010010 | 338 |
| BFFFFBBLRL | 1000011010 | 538 |
| BFFBBFBRLL | 1001101100 | 620 |
| BFBFFBFRRL | 1010010110 | 662 |
| BFBFFFFLRR | 1010000011 | 643 |
| FBFFFBFRRR | 0100010111 | 279 |
| BBFFBBBLLR | 1100111001 | 825 |
| FBFBFBFRRL | 0101010110 | 342 |
| BFFBFBBLRL | 1001011010 | 602 |
| FFFBFBBRLR | 0001011101 | 93 |
| BBFFFBFLRL | 1100010010 | 786 |
| BFBFFBFLLR | 1010010001 | 657 |
| BBFFBFBRRL | 1100101110 | 814 |
| FBBFFFBRRL | 0110001110 | 398 |
| FFBFFFFLLL | 0010000000 | 128 |
| BFBFBFFLLL | 1010100000 | 672 |
| BFBFFFBLRR | 1010001011 | 651 |
| FBBBFFBLRR | 0111001011 | 459 |
| FFBBFFBLLR | 0011001001 | 201 |
| BBFFFBBLRR | 1100011011 | 795 |
| BBFBFFBLRL | 1101001010 | 842 |
| BFFFBBFRLL | 1000110100 | 564 |
| FBFFBFFRRR | 0100100111 | 295 |
| FFBBBFBLRL | 0011101010 | 234 |
| FFBFBFFRRR | 0010100111 | 167 |
| BFFFFFFLLR | 1000000001 | 513 |
| BFFFFBBRRL | 1000011110 | 542 |
| FBFBBBFLRL | 0101110010 | 370 |
| BFFFFBFLRL | 1000010010 | 530 |
| FBFBBBFRLL | 0101110100 | 372 |
| FFBFBFBRRR | 0010101111 | 175 |
| FFFBFBBRRR | 0001011111 | 95 |
| FBBBFFBRLL | 0111001100 | 460 |
| FBFFBBFRLR | 0100110101 | 309 |
| FFBFBBFRLR | 0010110101 | 181 |
| FBBFFFBLLL | 0110001000 | 392 |
| BBFFBBBRLR | 1100111101 | 829 |
| FBBFFFFLRR | 0110000011 | 387 |
| BBFFFBFRLL | 1100010100 | 788 |
| FBBBBBBRLR | 0111111101 | 509 |
| BFBBFFBLLR | 1011001001 | 713 |
| BFBFBBBLRR | 1010111011 | 699 |
| FFBBFBBRLL | 0011011100 | 220 |
| FFFBFBBLLL | 0001011000 | 88 |
| BFBBBFFRLR | 1011100101 | 741 |
| FBFBFFFLRL | 0101000010 | 322 |
| BFFBBFBLLR | 1001101001 | 617 |
| BFBBFFFLRL | 1011000010 | 706 |
| BFBBFFBLRR | 1011001011 | 715 |
| FBFFFFBLRL | 0100001010 | 266 |
| FBFBFBFLRR | 0101010011 | 339 |
| FBBFFFFLRL | 0110000010 | 386 |
| FFBFBBBLLR | 0010111001 | 185 |
| FBFBFBBRRR | 0101011111 | 351 |
| BFBBBBFLRL | 1011110010 | 754 |
| BFBFBFBLRL | 1010101010 | 682 |
| BFFBFBFLRL | 1001010010 | 594 |
| BBFFFFBRRL | 1100001110 | 782 |
| FFBFFFBLRR | 0010001011 | 139 |
| BBFBFFBRRL | 1101001110 | 846 |
| FFBBBFFLRR | 0011100011 | 227 |
| BFFBBBBLRL | 1001111010 | 634 |
| FBBBFFFLLR | 0111000001 | 449 |
| FFFBBBFRLR | 0001110101 | 117 |
| BBFBFBFLLR | 1101010001 | 849 |
| BFBFBFFRRL | 1010100110 | 678 |
| FBFBFFBRRR | 0101001111 | 335 |
| FBFFBFFLRL | 0100100010 | 290 |
| FFBBFFFLLL | 0011000000 | 192 |
| BFFBBFBLLL | 1001101000 | 616 |
| BBFFFFFLRL | 1100000010 | 770 |
| FFBFBBBRRR | 0010111111 | 191 |
| FFBFFBFLLL | 0010010000 | 144 |
| FFBBBBFLRL | 0011110010 | 242 |
| FFBBFFFRLR | 0011000101 | 197 |
| BFBFFFBLLL | 1010001000 | 648 |
| FBFFFFFRRR | 0100000111 | 263 |
| FBBFFBBLRL | 0110011010 | 410 |
| BFFFFBFRRL | 1000010110 | 534 |
| BFFFFBFRLR | 1000010101 | 533 |
| FFBFBFFRLL | 0010100100 | 164 |
| BBFFBFFRRL | 1100100110 | 806 |
| FBFFBBBRRR | 0100111111 | 319 |
| FFBBBFFRRR | 0011100111 | 231 |
| BFFBBBBRLR | 1001111101 | 637 |
| FFBBFBBRLR | 0011011101 | 221 |
| BFBBFBBRLR | 1011011101 | 733 |
| FBFFBBBLLR | 0100111001 | 313 |
| BFFFFBBLRR | 1000011011 | 539 |
| FBBFBFBRRL | 0110101110 | 430 |
| FBBFBFBRLR | 0110101101 | 429 |
| FBBBBFFLRR | 0111100011 | 483 |
| FBFFFFBLRR | 0100001011 | 267 |
| FFBFBBFLLL | 0010110000 | 176 |
| FBBFFBBLRR | 0110011011 | 411 |
| FBFBFFFLLL | 0101000000 | 320 |
| FBFFFBBLRR | 0100011011 | 283 |
| FBBFBFFLLL | 0110100000 | 416 |
| FBBBFBFRLL | 0111010100 | 468 |
| FFBBFBBLRL | 0011011010 | 218 |
| BFBFFBBRRR | 1010011111 | 671 |
| BFFBBBBLLR | 1001111001 | 633 |
| FBFFBFBLRR | 0100101011 | 299 |
| FBBBBBBLLR | 0111111001 | 505 |
| FBBFBBFLRL | 0110110010 | 434 |
| BFBFBFBRLR | 1010101101 | 685 |
| FBBFFFFRLR | 0110000101 | 389 |
| BFFBFBBLLL | 1001011000 | 600 |
| BFBFFFBRLL | 1010001100 | 652 |
| BFFBBBBRLL | 1001111100 | 636 |
| BFBFBBFLLR | 1010110001 | 689 |
| FBFFBFFRLR | 0100100101 | 293 |
| BFFBBFBRRR | 1001101111 | 623 |
| FBBBFFFLLL | 0111000000 | 448 |
| BFFBFBFRRL | 1001010110 | 598 |
| FBFFBFFRLL | 0100100100 | 292 |
| FFBBBFFLRL | 0011100010 | 226 |
| FBFFBFFRRL | 0100100110 | 294 |
| BBFFBFBRLR | 1100101101 | 813 |
| FBBFBBBRLL | 0110111100 | 444 |
| FBFBBFBRRL | 0101101110 | 366 |
| FBFBBFFLLR | 0101100001 | 353 |
| BFFBFFBLRR | 1001001011 | 587 |
| FFBBFBFRRR | 0011010111 | 215 |
| BFFBBBFRRL | 1001110110 | 630 |
| FFBFBFBRRL | 0010101110 | 174 |
| BBFFBFFLLR | 1100100001 | 801 |
| FBBBBFFLLR | 0111100001 | 481 |
| FBBFBFBLLL | 0110101000 | 424 |
| BFBBBBFRLL | 1011110100 | 756 |
| FFBBBBFLLL | 0011110000 | 240 |
| FBBBFBBRLL | 0111011100 | 476 |
| BFFBFBFLLR | 1001010001 | 593 |
| FBFFFFFLLR | 0100000001 | 257 |
| FBBFBFBRLL | 0110101100 | 428 |
| FBFBBBFLLR | 0101110001 | 369 |
| FBFBFBBLLL | 0101011000 | 344 |
| FFFBBBBLLR | 0001111001 | 121 |
| FFBBBBFRRR | 0011110111 | 247 |
| FBBFFFBLRL | 0110001010 | 394 |
| BBFFBFBLLR | 1100101001 | 809 |
| BFBBFFFRLR | 1011000101 | 709 |
| BBFBFFBRLL | 1101001100 | 844 |
| BFBBBFBLRL | 1011101010 | 746 |
| BFBBBFFRRL | 1011100110 | 742 |
| FBFBFFBRLL | 0101001100 | 332 |
| BBFBFFFLRL | 1101000010 | 834 |
| BFBFBFBRRL | 1010101110 | 686 |
| BFFFBFFLLL | 1000100000 | 544 |
| FBFFFFFLLL | 0100000000 | 256 |
| FBFBBBBRRL | 0101111110 | 382 |
| FBFFBFBRRL | 0100101110 | 302 |
| BFBFBFFRLR | 1010100101 | 677 |
| FBFBFFFRRL | 0101000110 | 326 |
| BFBBBBFLLR | 1011110001 | 753 |
| FBBBBBFLRL | 0111110010 | 498 |
| FBBBFFBLLL | 0111001000 | 456 |
| FBBBFFFRRL | 0111000110 | 454 |
| BBFBFBFRRR | 1101010111 | 855 |
| FFBFFBBRRL | 0010011110 | 158 |
| FFBFBBFRRR | 0010110111 | 183 |
| BBFFFBFLLL | 1100010000 | 784 |
| BBFFBFBRRR | 1100101111 | 815 |
| BFFBBBFLRR | 1001110011 | 627 |
| FBFFFFBRLL | 0100001100 | 268 |
| FBFFBBBLLL | 0100111000 | 312 |
| FFFBBBFLLR | 0001110001 | 113 |
| BBFBFFBLLL | 1101001000 | 840 |
| FBFBFBFRLR | 0101010101 | 341 |
| BFBFBFBLLL | 1010101000 | 680 |
| BBFFFFBRRR | 1100001111 | 783 |
| FBBBBFBRRR | 0111101111 | 495 |
| FBFFFBBRLR | 0100011101 | 285 |
| FFFBBFFLLL | 0001100000 | 96 |
| FBBFFBFLRR | 0110010011 | 403 |
| BFFFBBBRLL | 1000111100 | 572 |
| FBBFBFBLRL | 0110101010 | 426 |
| FFBFFFFLRL | 0010000010 | 130 |
| FFBFFFBLLR | 0010001001 | 137 |
| FBBFBBBRRL | 0110111110 | 446 |
| BFBBFBFRLL | 1011010100 | 724 |
| FFBBBBBLRR | 0011111011 | 251 |
| BFFBBFFLRR | 1001100011 | 611 |
| FFBFFFBRRR | 0010001111 | 143 |
| BFFFFFFRLL | 1000000100 | 516 |
| BFFBFFBRRR | 1001001111 | 591 |
| FFFBBBFLRL | 0001110010 | 114 |
| FFBFBFBRLL | 0010101100 | 172 |
| BBFFBBBRRL | 1100111110 | 830 |
| BBFBFFFRRR | 1101000111 | 839 |
| BBFBFBFLRL | 1101010010 | 850 |
| FBBFBBBLRR | 0110111011 | 443 |
| FFBBFBFRLR | 0011010101 | 213 |
| BFBFBFBLRR | 1010101011 | 683 |
| FFFBBBBRRL | 0001111110 | 126 |
| BFFFFBBLLL | 1000011000 | 536 |
| FFFBBBFLRR | 0001110011 | 115 |
| FFBBFFBRRL | 0011001110 | 206 |
| FBFFBFFLRR | 0100100011 | 291 |
| FBFFBBFRRL | 0100110110 | 310 |
| BFBBFBBRRL | 1011011110 | 734 |
| BBFFBFBRLL | 1100101100 | 812 |
| FBBFFFFRRL | 0110000110 | 390 |
| FFBBFFBRLR | 0011001101 | 205 |
| BBFFFFBRLR | 1100001101 | 781 |
| BBFBFBFRLL | 1101010100 | 852 |
| FBBFBBBRRR | 0110111111 | 447 |
| BFFBBBBRRL | 1001111110 | 638 |
| BFFBBBBLLL | 1001111000 | 632 |
| BFBBFBBRLL | 1011011100 | 732 |
| BFFBBBFLRL | 1001110010 | 626 |
| FBFFBFBLRL | 0100101010 | 298 |
| BFFBBFFLLL | 1001100000 | 608 |
| BFBFBBFRLL | 1010110100 | 692 |
| FBBFFFBRRR | 0110001111 | 399 |
| FFBFFBFLRL | 0010010010 | 146 |
| FFBFFFFRLR | 0010000101 | 133 |
| BFBBFBBLLR | 1011011001 | 729 |
| BFBFBFBRRR | 1010101111 | 687 |
| FBBFFFFLLR | 0110000001 | 385 |
| FFBBFBBRRL | 0011011110 | 222 |
| BFFBFFFRRL | 1001000110 | 582 |
| FBFBBBFRRL | 0101110110 | 374 |
| FBBFFFFLLL | 0110000000 | 384 |
| BFFFFFFRRL | 1000000110 | 518 |
| BFBFFFBLLR | 1010001001 | 649 |
| BFBBFFBRRR | 1011001111 | 719 |
| BFFBFFFLLR | 1001000001 | 577 |
| FFBBBFBLLL | 0011101000 | 232 |
| BFFBBBFLLL | 1001110000 | 624 |
| FBFFFBBRRR | 0100011111 | 287 |
| FBBBBBFLLL | 0111110000 | 496 |
| BFBFFFFRRL | 1010000110 | 646 |
| FFBBFFBRRR | 0011001111 | 207 |
| BFBFBFFLLR | 1010100001 | 673 |
| FFFBFBBLLR | 0001011001 | 89 |
| BFBBFFBLRL | 1011001010 | 714 |
| FBFBBFFRRR | 0101100111 | 359 |
| BFBBBFFLLR | 1011100001 | 737 |
| FBBFFFBLLR | 0110001001 | 393 |
| BFFFBBFLRR | 1000110011 | 563 |
| BFFFFBBRLR | 1000011101 | 541 |
| FBFFFBBLRL | 0100011010 | 282 |
| BFBBBFBLRR | 1011101011 | 747 |
| FBFFBFBLLR | 0100101001 | 297 |
| BFBBFFFRLL | 1011000100 | 708 |
| FFBBFBFLLL | 0011010000 | 208 |
| FFBFFFBRRL | 0010001110 | 142 |
| FFBBFBBLRR | 0011011011 | 219 |
| FFBFBBFLRL | 0010110010 | 178 |
| FFFBBFFRRR | 0001100111 | 103 |
| BFBFFBFLRR | 1010010011 | 659 |
| BBFFFFBLRR | 1100001011 | 779 |
| FFBFBBFLRR | 0010110011 | 179 |
| FFFBBFFRLL | 0001100100 | 100 |
| FBBBFBBRLR | 0111011101 | 477 |
| BBFFFBBRRL | 1100011110 | 798 |
| FFFBFBFRRL | 0001010110 | 86 |
| FBBBBBBRRR | 0111111111 | 511 |
| FFBBBFBLRR | 0011101011 | 235 |
| FBBFBFFLRL | 0110100010 | 418 |
| FBBBFFFRRR | 0111000111 | 455 |
| FBBFFBBRRR | 0110011111 | 415 |
| BFFFFBBRRR | 1000011111 | 543 |
| FBBFFBFRLR | 0110010101 | 405 |
| BFFBFBFRLR | 1001010101 | 597 |
| BFBBBFFLRR | 1011100011 | 739 |
| FFBFFBFLRR | 0010010011 | 147 |
| BFBFFFBLRL | 1010001010 | 650 |
| BFFBFBFRLL | 1001010100 | 596 |
| FBBBBFBLLL | 0111101000 | 488 |
| BBFBFFFRRL | 1101000110 | 838 |
| FFBBFFBLLL | 0011001000 | 200 |
| FFBFFBBRLR | 0010011101 | 157 |
| FFBBBFBRRL | 0011101110 | 238 |
| FFBBFFFLRR | 0011000011 | 195 |
| BBFFBFFLRR | 1100100011 | 803 |
| BFFFBFFRRL | 1000100110 | 550 |
| FBFBBFBRRR | 0101101111 | 367 |
| FBFFFBFLRL | 0100010010 | 274 |
| BBFBFFBLRR | 1101001011 | 843 |
| BFFBFBFRRR | 1001010111 | 599 |
| BFFFFFFLLL | 1000000000 | 512 |
| FBBBFFBLRL | 0111001010 | 458 |
| FBBBFBFRRL | 0111010110 | 470 |
| BFFBFFBRLR | 1001001101 | 589 |
| BFBBBFFRRR | 1011100111 | 743 |
| BFFBFFFRRR | 1001000111 | 583 |
| FFFBBBBLLL | 0001111000 | 120 |
| FFBBBFBRRR | 0011101111 | 239 |
| FFBBFBFLLR | 0011010001 | 209 |
| BFBBBFBLLL | 1011101000 | 744 |
| FBBFBBBLLL | 0110111000 | 440 |
| BBFBFBFLLL | 1101010000 | 848 |
| BFBBBFBRRR | 1011101111 | 751 |
| BFBFBBFRLR | 1010110101 | 693 |
| FBFFBFBRLR | 0100101101 | 301 |
| BFFBFFFRLL | 1001000100 | 580 |
| BFBBFFBRRL | 1011001110 | 718 |
| FFBBFBFLRR | 0011010011 | 211 |
| FFBBBFBLLR | 0011101001 | 233 |
| BBFBFFFRLR | 1101000101 | 837 |
| FFBBFBBLLR | 0011011001 | 217 |
| FBFFFBBLLR | 0100011001 | 281 |
| FBBFBFBLLR | 0110101001 | 425 |
| FFBBFBFRLL | 0011010100 | 212 |
| BFFFFFBLLR | 1000001001 | 521 |
| BFBFBFBLLR | 1010101001 | 681 |
| BFBBFFBLLL | 1011001000 | 712 |
| FBBBBFBLRR | 0111101011 | 491 |
| BFBBBBFLLL | 1011110000 | 752 |
| BFFBBFFLLR | 1001100001 | 609 |
| FBFBFFFRLL | 0101000100 | 324 |
| FBBBBBFLLR | 0111110001 | 497 |
| BBFBFFBLLR | 1101001001 | 841 |
| BFBFBFFLRR | 1010100011 | 675 |
| FBBBBFFRLR | 0111100101 | 485 |
| FFFBFBBRRL | 0001011110 | 94 |
| FFFBBFBLLL | 0001101000 | 104 |
| BFBBBBFLRR | 1011110011 | 755 |
| BFBBBBBLRR | 1011111011 | 763 |
| FBBFBBFLLL | 0110110000 | 432 |
| BFFFBFBRLR | 1000101101 | 557 |
| FBBFBFFLRR | 0110100011 | 419 |
| FBFFFBBRLL | 0100011100 | 284 |
| BFFFFFBRRR | 1000001111 | 527 |
| BFFBBBFRLL | 1001110100 | 628 |
| FFBFBFBLLL | 0010101000 | 168 |
| BFBBFBFLRL | 1011010010 | 722 |
| FBBBBFFLLL | 0111100000 | 480 |
| FBBFBFFRRR | 0110100111 | 423 |
| FFFBBBBRLR | 0001111101 | 125 |
| BFBFBFFLRL | 1010100010 | 674 |
| FFBBBFFRRL | 0011100110 | 230 |
| BBFFBFFLRL | 1100100010 | 802 |
| BFFFBBBRRL | 1000111110 | 574 |
| FBFFFFFLRL | 0100000010 | 258 |
| BBFFBFFRLL | 1100100100 | 804 |
| BFFFBBFRLR | 1000110101 | 565 |
| BFBFFBBRLR | 1010011101 | 669 |
| FBFBFBBLLR | 0101011001 | 345 |
| FBBFFBBRRL | 0110011110 | 414 |
| BBFFBFFRLR | 1100100101 | 805 |
| FFBFFBBRRR | 0010011111 | 159 |
| BBFFFBBRLL | 1100011100 | 796 |
| BFBFBFBRLL | 1010101100 | 684 |
| FBFBBBBLLR | 0101111001 | 377 |
| FBFBFBFLLL | 0101010000 | 336 |
| FFBFBBBLRL | 0010111010 | 186 |
| BFFBFBBLRR | 1001011011 | 603 |
| BBFFFFFRRR | 1100000111 | 775 |
| FFFBBFFLRL | 0001100010 | 98 |
| BBFFFBFLRR | 1100010011 | 787 |
| FFBFFBFRLL | 0010010100 | 148 |
| FBFFBBFLLR | 0100110001 | 305 |
| FBFFFFBLLR | 0100001001 | 265 |
| FFBBBBFRLL | 0011110100 | 244 |
| FFFBBFFLRR | 0001100011 | 99 |
| BBFFFFFLLL | 1100000000 | 768 |
| BBFBFBFLRR | 1101010011 | 851 |
| FFBBBBFRLR | 0011110101 | 245 |
| BBFFFBBLLL | 1100011000 | 792 |
| FFBFBBFRLL | 0010110100 | 180 |
| BFFFFFFLRR | 1000000011 | 515 |
| FFBFFFBRLL | 0010001100 | 140 |
| FBFFFFFRRL | 0100000110 | 262 |
| BBFFFBBLLR | 1100011001 | 793 |
| FFFBBFBRLR | 0001101101 | 109 |
| BFFBBFFRRL | 1001100110 | 614 |
| FBBBBFFRLL | 0111100100 | 484 |
| BFBBFFBRLR | 1011001101 | 717 |
| BFFFBFBLRR | 1000101011 | 555 |
| BFBFFBBLLR | 1010011001 | 665 |
| BFFBFBBRRR | 1001011111 | 607 |
| BBFFFBFRRR | 1100010111 | 791 |
| FFBBBFFRLL | 0011100100 | 228 |
| BFBBFBBRRR | 1011011111 | 735 |
| FFBBBBBRLR | 0011111101 | 253 |
| BFFFBBBRLR | 1000111101 | 573 |
| BFFFBBFLLL | 1000110000 | 560 |
| FFBFFBBLRL | 0010011010 | 154 |
| FFBBFBFLRL | 0011010010 | 210 |
| FBFBFBBLRL | 0101011010 | 346 |
| BFFBBFBRLR | 1001101101 | 621 |
| FBBBBFBRRL | 0111101110 | 494 |
| FBFBBBFRRR | 0101110111 | 375 |
| BBFBFFBRRR | 1101001111 | 847 |
| BBFBFBFRRL | 1101010110 | 854 |
| FBBBBFBRLL | 0111101100 | 492 |
| FBFFFBBLLL | 0100011000 | 280 |
| BFBFBBFLLL | 1010110000 | 688 |
| FBBBBFFRRR | 0111100111 | 487 |
| FBBFBBFLRR | 0110110011 | 435 |
| FFBFFFFRRL | 0010000110 | 134 |
| FFFBFBFRLL | 0001010100 | 84 |
| FBFBBFBRLR | 0101101101 | 365 |
| FFBBBFFLLR | 0011100001 | 225 |
| FBFFBBFLLL | 0100110000 | 304 |
| FFFBBBBRRR | 0001111111 | 127 |
| BFFFFBFRRR | 1000010111 | 535 |
| BFBFFFFLRL | 1010000010 | 642 |
| FBFBFFBLLL | 0101001000 | 328 |
| BFFBBBBRRR | 1001111111 | 639 |
| BFFBFBFLLL | 1001010000 | 592 |
| FBFBBFFLLL | 0101100000 | 352 |
| FBBFBBFLLR | 0110110001 | 433 |
| FBBFBFFLLR | 0110100001 | 417 |
| BBFFBFFRRR | 1100100111 | 807 |
| FBBBBBFLRR | 0111110011 | 499 |
| FFBFBBBRLL | 0010111100 | 188 |
| FBBBBBBLLL | 0111111000 | 504 |
| BFBBFBBLRR | 1011011011 | 731 |
| FBFBFFFRLR | 0101000101 | 325 |
| FFBBBBBRRL | 0011111110 | 254 |
| FBFFFFBRRR | 0100001111 | 271 |
| FBBFFBFRRR | 0110010111 | 407 |
| FFFBBBBRLL | 0001111100 | 124 |
| FBBFFFFRRR | 0110000111 | 391 |
| BFFBFFBLRL | 1001001010 | 586 |
| FFFBBBBLRR | 0001111011 | 123 |
| BFBBBBFRRL | 1011110110 | 758 |
| BFFFFBBLLR | 1000011001 | 537 |
| BFFFFFFRLR | 1000000101 | 517 |
| BFFBBFFRLR | 1001100101 | 613 |
| BFFBBFBLRL | 1001101010 | 618 |
| BBFFFFBLLL | 1100001000 | 776 |
| BFFFFBBRLL | 1000011100 | 540 |
| FBBFFBFRLL | 0110010100 | 404 |
| FFFBBFBLRR | 0001101011 | 107 |
| BBFBFFBRLR | 1101001101 | 845 |
| BFFFBBBLRL | 1000111010 | 570 |
| BFBBFFFRRL | 1011000110 | 710 |
| BFBFFBFRLL | 1010010100 | 660 |
| BFFBFBBRRL | 1001011110 | 606 |
| FBFFBFFLLL | 0100100000 | 288 |
| BFBBFFBRLL | 1011001100 | 716 |
| BFBBBFFLRL | 1011100010 | 738 |
| FFFBFBFRLR | 0001010101 | 85 |
| BFFBFFBLLR | 1001001001 | 585 |
| BBFFFFBLLR | 1100001001 | 777 |
| FFBBFBBRRR | 0011011111 | 223 |
| FBBFBBFRRR | 0110110111 | 439 |
| FFBBBFFLLL | 0011100000 | 224 |
| BFBBFFFLRR | 1011000011 | 707 |
| FFBFFBFRRR | 0010010111 | 151 |
| FBBFBBFRLR | 0110110101 | 437 |
| FBFBFFBLRL | 0101001010 | 330 |
| BBFFBFBLRL | 1100101010 | 810 |
| BFFFFBFLRR | 1000010011 | 531 |
| FBBBFFFRLL | 0111000100 | 452 |
| FFFBBFFRRL | 0001100110 | 102 |
| FFBFBFFRLR | 0010100101 | 165 |
| FFBBBBBLLR | 0011111001 | 249 |
| BFFBBFBRRL | 1001101110 | 622 |
| BFFBFBFLRR | 1001010011 | 595 |
| FFFBFBBRLL | 0001011100 | 92 |
| FBFBBBBLRR | 0101111011 | 379 |
| BFBFFFBRRL | 1010001110 | 654 |
| FFBFBBBRRL | 0010111110 | 190 |
| FFBFBFFLRR | 0010100011 | 163 |
| FFBFBFBLRR | 0010101011 | 171 |
| BFFBBFBLRR | 1001101011 | 619 |
| FFFBFBFLRL | 0001010010 | 82 |
| BFFBFBBRLL | 1001011100 | 604 |
| BFFBFFFRLR | 1001000101 | 581 |
| FFBBFFBLRR | 0011001011 | 203 |
| FBBBBBFRLL | 0111110100 | 500 |
| FBFBFBFRLL | 0101010100 | 340 |
| BFBBBBBRRR | 1011111111 | 767 |
| BBFBFFFLLR | 1101000001 | 833 |
| FFBFFFFRLL | 0010000100 | 132 |
| FFFBBFFLLR | 0001100001 | 97 |
| BFBBFFFRRR | 1011000111 | 711 |
| FBBBFBFLLR | 0111010001 | 465 |
| BFBBBBBRRL | 1011111110 | 766 |
| FBBBBBBLRL | 0111111010 | 506 |
| FBBBFBFLLL | 0111010000 | 464 |
| BFFBFFBLLL | 1001001000 | 584 |
| BFFBFFBRRL | 1001001110 | 590 |
| FBFFBFBRRR | 0100101111 | 303 |
| FBFBFBBLRR | 0101011011 | 347 |
| BFFFBFFRLR | 1000100101 | 549 |
| FBFBFBBRRL | 0101011110 | 350 |
| BFBBBBBLLL | 1011111000 | 760 |
| FBFFBBFLRR | 0100110011 | 307 |
| BBFFFBBRRR | 1100011111 | 799 |
| FFFBFBBLRR | 0001011011 | 91 |
| FBBFFBBLLL | 0110011000 | 408 |
| BFFFFFBRLL | 1000001100 | 524 |
| BBFBFBFRLR | 1101010101 | 853 |
| BFFFBFFLRR | 1000100011 | 547 |
| FBFBFFBLRR | 0101001011 | 331 |
| BFBBBFBRLR | 1011101101 | 749 |
| BBFFBFBLLL | 1100101000 | 808 |
| FFBBBBFLLR | 0011110001 | 241 |
| FBBBFBFRLR | 0111010101 | 469 |
| FBBBBBFRRL | 0111110110 | 502 |
| FBBBFFBRRR | 0111001111 | 463 |
| FFBBBBFLRR | 0011110011 | 243 |
| BBFFBBBRRR | 1100111111 | 831 |
| BFFFFBFLLR | 1000010001 | 529 |
| FBFFBBFRRR | 0100110111 | 311 |
| BBFFFFFRRL | 1100000110 | 774 |
| BBFFBBBRLL | 1100111100 | 828 |
| FBFFFFBRRL | 0100001110 | 270 |
| FBFFBBBLRL | 0100111010 | 314 |
| BFFFFFFRRR | 1000000111 | 519 |
| BFFFBBBLLR | 1000111001 | 569 |
| FBFBBFBLRL | 0101101010 | 362 |
| BFBFBBBLRL | 1010111010 | 698 |
| FFBBFBFRRL | 0011010110 | 214 |
| FBFFBBBRLR | 0100111101 | 317 |
| BFFBBBFRLR | 1001110101 | 629 |
| FFBFBBBLRR | 0010111011 | 187 |
| BFFBFFFLLL | 1001000000 | 576 |
| FBBBFFBLLR | 0111001001 | 457 |
| BFBFBBFRRL | 1010110110 | 694 |
| FFBFFBBLRR | 0010011011 | 155 |
| BBFFFBBRLR | 1100011101 | 797 |
| FFBFFBBRLL | 0010011100 | 156 |
| FBFFFFFRLR | 0100000101 | 261 |
| FBBBFBBLRL | 0111011010 | 474 |
| BBFFFBFLLR | 1100010001 | 785 |
| FBBFFFFRLL | 0110000100 | 388 |
| BFFFBBFLRL | 1000110010 | 562 |
| BFBBBBBRLR | 1011111101 | 765 |
| BFFBFBBLLR | 1001011001 | 601 |
| FFBBFFBLRL | 0011001010 | 202 |
| BFBBBFBRLL | 1011101100 | 748 |
| BFBBFBFRRR | 1011010111 | 727 |
| FFBBFFFLRL | 0011000010 | 194 |
| FFBFFFBLLL | 0010001000 | 136 |
| FFBFFBBLLR | 0010011001 | 153 |
| BBFFFBFRRL | 1100010110 | 790 |
| BFFBBFFLRL | 1001100010 | 610 |
| FBBFFBFLRL | 0110010010 | 402 |
| BFFFBBBRRR | 1000111111 | 575 |
| FFBBFFFRRL | 0011000110 | 198 |
| FFBFBFFRRL | 0010100110 | 166 |
| FBBBBFBLRL | 0111101010 | 490 |
| BBFFBBFLLR | 1100110001 | 817 |
| FBBBBFBRLR | 0111101101 | 493 |
| BFBFFBFRLR | 1010010101 | 661 |
| FFBFFBBLLL | 0010011000 | 152 |
| FFBBBBBLLL | 0011111000 | 248 |
| BFBFBBFRRR | 1010110111 | 695 |
| BBFFFFFRLL | 1100000100 | 772 |
| FBFFFBFRLR | 0100010101 | 277 |
| BFBBBBFRLR | 1011110101 | 757 |
| FBBFFFBRLR | 0110001101 | 397 |
| BFFFFFBLRR | 1000001011 | 523 |
| FBFFBBBRRL | 0100111110 | 318 |
| FBBBFBFLRL | 0111010010 | 466 |
| BFFFBFFLRL | 1000100010 | 546 |
| BFBFBBFLRR | 1010110011 | 691 |
| BFBBFBFRLR | 1011010101 | 725 |
| FFBFFBFRLR | 0010010101 | 149 |
| BBFFFBBLRL | 1100011010 | 794 |
| BFBFFBFLLL | 1010010000 | 656 |
| BBFFBBFRLL | 1100110100 | 820 |
| FBBBBBBRRL | 0111111110 | 510 |
| FFBBFFFLLR | 0011000001 | 193 |
| FFFBBBBLRL | 0001111010 | 122 |
| BBFFBFFLLL | 1100100000 | 800 |
| FBBBFFFLRR | 0111000011 | 451 |
| FBFBFBFLLR | 0101010001 | 337 |
| FFBFBFFLLL | 0010100000 | 160 |
| FFBFFFBLRL | 0010001010 | 138 |
| BFBFFBBLLL | 1010011000 | 664 |
| FBFBFFFLRR | 0101000011 | 323 |
| BBFFBBFLRL | 1100110010 | 818 |
| BFFFBFFRRR | 1000100111 | 551 |
| FBFFBBBRLL | 0100111100 | 316 |
| FFFBBBFRLL | 0001110100 | 116 |
| FBFFFBFLLL | 0100010000 | 272 |
| BBFFFBFRLR | 1100010101 | 789 |
| BBFFBBFLLL | 1100110000 | 816 |
| BBFBFFFRLL | 1101000100 | 836 |
| BBFFBBBLLL | 1100111000 | 824 |
| FBFBBFBLLL | 0101101000 | 360 |
| FBBFBBBLRL | 0110111010 | 442 |
| FBFFFFFLRR | 0100000011 | 259 |
| FBFBBFBRLL | 0101101100 | 364 |
| FFFBBFBRLL | 0001101100 | 108 |
| FBBBFBFLRR | 0111010011 | 467 |
| FBFBFFFLLR | 0101000001 | 321 |
| FFBFFFFRRR | 0010000111 | 135 |
| BFFBBFFRLL | 1001100100 | 612 |
| BBFFFFBRLL | 1100001100 | 780 |
| BFBBBFBLLR | 1011101001 | 745 |
| BFBBFBFLLL | 1011010000 | 720 |
| FBBBBBFRRR | 0111110111 | 503 |
| FFBFBBBRLR | 0010111101 | 189 |
| BFFFFBFLLL | 1000010000 | 528 |
| BFFFFFBRLR | 1000001101 | 525 |
| BFBFFFFLLL | 1010000000 | 640 |
| BFBFFBBRRL | 1010011110 | 670 |
| FFBFFBFRRL | 0010010110 | 150 |
| FBBBFBBLRR | 0111011011 | 475 |
| BFBFFBFLRL | 1010010010 | 658 |
| FBBBBBBRLL | 0111111100 | 508 |
| FFFBBFBLRL | 0001101010 | 106 |
| FFBFBBFLLR | 0010110001 | 177 |
| BFBFBBBLLR | 1010111001 | 697 |
| FBFBBFFRLR | 0101100101 | 357 |
| FBFBFFBLLR | 0101001001 | 329 |
| BBFFBBBLRL | 1100111010 | 826 |
| BFBFFBBLRR | 1010011011 | 667 |
| FFBBFFFRRR | 0011000111 | 199 |
| FBFBBBFRLR | 0101110101 | 373 |
| BFBBFBFLRR | 1011010011 | 723 |
| FBBFBFFRRL | 0110100110 | 422 |
| FBFBBFFLRR | 0101100011 | 355 |
| FBBFBFBRRR | 0110101111 | 431 |
| FBFBBBFLRR | 0101110011 | 371 |
| BFBBBBBLLR | 1011111001 | 761 |
| FBFFFBFLLR | 0100010001 | 273 |
| FBFBBFBLLR | 0101101001 | 361 |
| FFBFFFFLRR | 0010000011 | 131 |
| BFBFBBBRLR | 1010111101 | 701 |
| FBFFFFFRLL | 0100000100 | 260 |
| FFBBBBBLRL | 0011111010 | 250 |
| BFBBBFFLLL | 1011100000 | 736 |
| BBFFFFFLLR | 1100000001 | 769 |
| BFFFBBFRRR | 1000110111 | 567 |
| FBFBFFBRRL | 0101001110 | 334 |
| FFFBBFBRRR | 0001101111 | 111 |
| FBBBFBBLLR | 0111011001 | 473 |
| BFFFFBFRLL | 1000010100 | 532 |
| BFBFBFFRLL | 1010100100 | 676 |
| BFBFBBFLRL | 1010110010 | 690 |
| FFBBBFFRLR | 0011100101 | 229 |
| BFBFBBBLLL | 1010111000 | 696 |
| BFFFBBBLRR | 1000111011 | 571 |
| BFBBFFFLLL | 1011000000 | 704 |
| FBFBFBBRLL | 0101011100 | 348 |
| BFFFFFBLLL | 1000001000 | 520 |
| BBFBFFFLRR | 1101000011 | 835 |
| BFBFFBBRLL | 1010011100 | 668 |
| FFBFBBFRRL | 0010110110 | 182 |
| FBFBBBFLLL | 0101110000 | 368 |
| FBFFFFBLLL | 0100001000 | 264 |
| FBFFBFFLLR | 0100100001 | 289 |
| FBBFBBFRRL | 0110110110 | 438 |
| BBFFBBFRRR | 1100110111 | 823 |
| BFFFBFBRRL | 1000101110 | 558 |
| BFBFFFBRLR | 1010001101 | 653 |
| FBBFFBFLLR | 0110010001 | 401 |
| BFBFFFFRLL | 1010000100 | 644 |
| BFBFBBBRRR | 1010111111 | 703 |
| BFBFFFFRLR | 1010000101 | 645 |
| FFBFBFBLLR | 0010101001 | 169 |
| FBFFFBFLRR | 0100010011 | 275 |
| FFBBBBBRRR | 0011111111 | 255 |
| FBBFFFBLRR | 0110001011 | 395 |
| FFBFFFBRLR | 0010001101 | 141 |
| BFFFBFBRRR | 1000101111 | 559 |
| FBBFBBBLLR | 0110111001 | 441 |
| BFBBBBBLRL | 1011111010 | 762 |
| FBBBFFFLRL | 0111000010 | 450 |
| BFFBBFFRRR | 1001100111 | 615 |
| BFBBBFFRLL | 1011100100 | 740 |
| BFBFFFFLLR | 1010000001 | 641 |
| BFFBFFFLRL | 1001000010 | 578 |
| BFBFFFFRRR | 1010000111 | 647 |
| BBFFFFFRLR | 1100000101 | 773 |
| FBFFFBFRLL | 0100010100 | 276 |
| FFFBBBFRRR | 0001110111 | 119 |
| BFFFBFBLLR | 1000101001 | 553 |
| FBBFBFFRLL | 0110100100 | 420 |
| FBBBFBBLLL | 0111011000 | 472 |
| BFBBBBBRLL | 1011111100 | 764 |
| BFFBBBFRRR | 1001110111 | 631 |
| FFFBFBFRRR | 0001010111 | 87 |
| BFBBBFBRRL | 1011101110 | 750 |
| FBFFBFBLLL | 0100101000 | 296 |
| FBBBFFFRLR | 0111000101 | 453 |
| FBFBBFFRRL | 0101100110 | 358 |
| FBBFFBFRRL | 0110010110 | 406 |
| FBBFBFBLRR | 0110101011 | 427 |
| BFFFFFBLRL | 1000001010 | 522 |
| FBBBFBFRRR | 0111010111 | 471 |
| BFFFBBBLLL | 1000111000 | 568 |
| FFBBBFBRLL | 0011101100 | 236 |
| | | 0 |
| | | 855 |
#+TBLFM: @>$3=vmax(@1$3..@>>$3)
AWESOME it worked :) Now for part 2.
** Part 2
*** Problem
--- Part Two ---
Ding! The "fasten seat belt" signs have turned on. Time to find your seat.
It's a completely full flight, so your seat should be the only missing boarding pass in your list. However, there's a catch: some of the seats at the very front and back of the plane don't exist on this aircraft, so they'll be missing from your list as well.
Your seat wasn't at the very front or back, though; the seats with IDs +1 and -1 from yours will be in your list.
Of /course/ we can't just see the one number that's missing; that'd be too easy, lol. I do need to slurp up the list from earlier though. Of course ... I don't think that's super easy, lol. Or rather, I don't know how to do it. Let's just do that here.
Well, there's a lot of garbage here but there's also 552 -- which I think is probably our answer. /Oh/ I must've had an off-by-one answer /because/ I only tested for the non-existence of /s+1/ earlier -- meaning once I got to the seat /before/ mine, it returned true. Ha.
As your flight approaches the regional airport where you'll switch to a much larger plane, customs declaration forms are distributed to the passengers.
The form asks a series of 26 yes-or-no questions marked a through z. All you need to do is identify the questions for which anyone in your group answers "yes". Since your group is just you, this doesn't take very long.
However, the person sitting next to you seems to be experiencing a language barrier and asks if you can help. For each of the people in their group, you write down the questions for which they answer "yes", one per line. For example:
#+begin_example
abcx
abcy
abcz
#+end_example
In this group, there are 6 questions to which anyone answered "yes": a, b, c, x, y, and z. (Duplicate answers to the same question don't count extra; each question counts at most once.)
Another group asks for your help, then another, and eventually you've collected answers from every group on the plane (your puzzle input). Each group's answers are separated by a blank line, and within each group, each person's answers are on a single line. For example:
#+begin_example
abc
a
b
c
ab
ac
a
a
a
a
b
#+end_example
This list represents answers from five groups:
The first group contains one person who answered "yes" to 3 questions: a, b, and c.
The second group contains three people; combined, they answered "yes" to 3 questions: a, b, and c.
The third group contains two people; combined, they answered "yes" to 3 questions: a, b, and c.
The fourth group contains four people; combined, they answered "yes" to only 1 question, a.
The last group contains one person who answered "yes" to only 1 question, b.
In this example, the sum of these counts is 3 + 3 + 3 + 1 + 1 = 11.
For each group, count the number of questions to which anyone answered "yes". What is the sum of those counts?
*** Solution
I think this is basic set manipulation. Basically, for each group of people, build a set out of the letters they answered /yes/ to, then find the length of that set. Then add the lengths. Okay, this shouldn’t be too hard.
#+NAME: day6-part1
#+begin_src emacs-lisp :noweb yes
<<aoc>>
(defun set-from-group (group)
"Build a set from a group.
The group will be a newline-separated string."
;; basically, i just need to build a list from the string
;; then remove duplicates.
(let ((lst (seq-filter (lambda (c)
(not (char-equal c ?\n)))
(string-to-list group))))
(delete-dups lst)))
(aoc
input "\n\n"
(seq-reduce
(lambda (result group)
(+ result
(length (set-from-group group))))
lines 0))
#+end_src
#+RESULTS: day6-part1
: 6532
Awesome, 6532 is right!
** Part 2
*** Problem
--- Part Two ---
As you finish the last group's customs declaration, you notice that you misread one word in the instructions:
You don't need to identify the questions to which anyone answered "yes"; you need to identify the questions to which everyone answered "yes"!
Using the same example as above:
#+begin_example
abc
a
b
c
ab
ac
a
a
a
a
b
#+end_example
This list represents answers from five groups:
In the first group, everyone (all 1 person) answered "yes" to 3 questions: a, b, and c.
In the second group, there is no question to which everyone answered "yes".
In the third group, everyone answered yes to only 1 question, a. Since some people did not answer "yes" to b or c, they don't count.
In the fourth group, everyone answered yes to only 1 question, a.
In the fifth group, everyone (all 1 person) answered "yes" to 1 question, b.
In this example, the sum of these counts is 3 + 0 + 1 + 1 + 1 = 6.
For each group, count the number of questions to which everyone answered "yes". What is the sum of those counts?
*** Solution
Hm… well, it would’ve been easy if I’d set up the previous part to use =or=: this one would just use =and=. Of /course/ I didn’t make it easy on myself though!
Okay, I’ve had a think and this is what I’m going to do. The number of answers /everyone/ said yes to is just the total number of answers – 26 ✕ /n/ (where /n/ is the number of people in the group) –/minus/ the number of answers where /anyone/ said yes. So I have to figure out how many people are in each group, use =set-from-group= (from part 1) to find the number of /any yeses/, then subtract that from the total possible answers.
#+NAME: day6-part2-attempt1
#+begin_src emacs-lisp
(aoc
input "\n\n"
(seq-reduce
(lambda (result group)
(let* ((members (split-string group))
(total-questions (length members))
(anyone-yeses-count
(length (set-from-group group))))
(+ result (- total-questions
anyone-yeses-count))))
lines 0))
#+end_src
#+RESULTS: day6-part2-attempt1
: -4383
Damn, *36680* is too high. Hm. Let’s try breaking the lambda out into a function. (By the way, I tried adding a =-1= to the calculation too –*36193* is /still/ too high.
#+NAME: day6-part2-attempt2
#+begin_src emacs-lisp
(defun unanimous-yes-count (group)
"Count how many answers were answered yes by everyone in GROUP.
No… that’s higher than the previous answer!!! hmmmmm. Let’s try this a totally different way.
/Wait a minute!/ The first answer was *3680*– it makes /no sense/ that the answre to part 2 would be 10 times /higher/ than that. I’m doing something wrong.
Okay, 4870 is too high too. /Now/ we’re getting somewhere.
I’VE GOT IT!! It’s the /set difference/, not /arithmetic difference!/
#+NAME: day6-part2-attempt4
#+begin_src emacs-lisp
(aoc
input "\n\n"
(seq-reduce
(lambda (result group)
(let* ((members (split-string group))
(total-qs 26)
(anyone-yeses-count
(length (set-from-group group))))
(+ result (- total-qs
anyone-yeses-count))))
lines 0))
#+end_src
#+RESULTS: day6-part2-attempt4
: 6130
*NOPE*. Ugggghhhh
Okay, I really need to try another tack. I’ve played this one out.
[fn:1]By the way, inserting this [[https://emojipedia.org/person-shrugging/][shrug emoji]] was absolutely maddening to do on Emacs on Windows. I've got to fix my clipboard character set.