1
0
Fork 0

Change line endings

This commit is contained in:
Case Duckworth 2020-12-01 20:30:50 -06:00
parent f1a0a32e48
commit 3e28ff70ab
1 changed files with 298 additions and 296 deletions

594
aoc.org
View File

@ -1,296 +1,298 @@
#+TITLE:Advent of Code 2020
#+AUTHOR:Case Duckworth
Let's do this -- Advent of Code, literate-style.
* Day 1
** A
*** Problem
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.
#+TITLE:Advent of Code 2020
#+AUTHOR:Case Duckworth
Let's do this -- Advent of Code, literate-style.
* Day 1
** A
*** Problem
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.
* Day 2