aoc-1.scm 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  1. (define input '(1788 1627 1883 1828 1924 1993 972 1840 1866 1762 1781
  2. 1782 1520 1971 1660 1857 1867 1564 1983 1391 2002 494 1500 1967 1702 1958
  3. 1886 1910 1838 1985 1836 2009 2005 1602 1939 1945 1609 1582 1647 1737
  4. 1982 1931 790 745 1598 1586 1547 1951 1264 1382 1776 1499 1977 1766 1360
  5. 1807 1991 1981 1693 634 1847 1774 1990 1409 1410 1974 1862 1744 1827 1978
  6. 1980 2003 1491 1595 1640 1576 1887 1746 1617 1923 1706 1964 60 1620 1959
  7. 257 1395 1854 1843 1682 1667 1639 279 1911 1986 1575 1232 1919 1852 1509
  8. 1976 1465 2008 1953 1518 1795 1912 1269 1835 1984 1538 2001 1954 1365
  9. 1569 1418 1844 1580 1875 1551 1861 1946 1810 1655 1987 1549 1301 1859
  10. 1929 1254 1604 1933 1998 1661 1899 1411 1975 1707 1966 1601 1936 1440
  11. 1942 1937 1851 1731 1257 1533 1405 1890 1600 1970 1626 1824 1442 2006
  12. 1796 1658 1930 646 1904 1489 2004 1922 1424 1802 1623 1870 1242 1591 1338
  13. 754 1826 1305 1825 1793 1872 1741 1979 107 1833 1856 1952 1791 1728 2010
  14. 1965 1646 1522 1671 1624 1876 1537 1759 1962 1773 1907 1573 1908 1903))
  15. (define (intersection a b)
  16. (if (null? a)
  17. '()
  18. (if (member (car a) b)
  19. (cons (car a) (intersection (cdr a) b))
  20. (intersection (cdr a) b))))
  21. (define (subtract-twenty-twenty x)
  22. (- 2020 x))
  23. (define a1
  24. (let* ((h1 (map subtract-twenty-twenty input))
  25. (h2 (intersection input h1))
  26. (h3 (car h2))
  27. (h4 (car (cdr h2))))
  28. (if (and (memq h3 input) (memq h4 input))
  29. (* h3 h4))))