From 316a48b6a87bffce372ef2186ace9f0565c3eceb Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Thu, 9 Mar 2023 21:55:36 +0100 Subject: Renamed folder --- 2020/01-Report-Repair/example | 6 ++ 2020/01-Report-Repair/first.hs | 29 ++++++ 2020/01-Report-Repair/input | 200 ++++++++++++++++++++++++++++++++++++++++ 2020/01-Report-Repair/second.hs | 32 +++++++ 2020/01/example | 6 -- 2020/01/first.hs | 29 ------ 2020/01/input | 200 ---------------------------------------- 2020/01/second.hs | 32 ------- 8 files changed, 267 insertions(+), 267 deletions(-) create mode 100644 2020/01-Report-Repair/example create mode 100644 2020/01-Report-Repair/first.hs create mode 100644 2020/01-Report-Repair/input create mode 100644 2020/01-Report-Repair/second.hs delete mode 100644 2020/01/example delete mode 100644 2020/01/first.hs delete mode 100644 2020/01/input delete mode 100644 2020/01/second.hs (limited to '2020') diff --git a/2020/01-Report-Repair/example b/2020/01-Report-Repair/example new file mode 100644 index 0000000..e3fb011 --- /dev/null +++ b/2020/01-Report-Repair/example @@ -0,0 +1,6 @@ +1721 +979 +366 +299 +675 +1456 diff --git a/2020/01-Report-Repair/first.hs b/2020/01-Report-Repair/first.hs new file mode 100644 index 0000000..5a615a9 --- /dev/null +++ b/2020/01-Report-Repair/first.hs @@ -0,0 +1,29 @@ +module Main where + +import Control.Monad (when) +import Data.Maybe (catMaybes, fromJust) +import System.Exit (die) + +exampleExpectedOutput = 514579 + +compute2020 :: Int -> Int -> Maybe Int +compute2020 a b + | a + b == 2020 = Just (a * b) + | otherwise = Nothing + +compute :: String -> Int +compute input = head . catMaybes $ processInput inputList + where + inputList :: [Int] + inputList = map read $ lines input + processInput :: [Int] -> [Maybe Int] + processInput (_:[]) = [Nothing] + processInput (x:xs) = map (compute2020 x) xs ++ processInput xs + +main :: IO () +main = do + example <- readFile "example" + let exampleOutput = compute example + when (exampleOutput /= exampleExpectedOutput) (die $ "example failed: got " ++ show exampleOutput ++ " instead of " ++ show exampleExpectedOutput) + input <- readFile "input" + print $ compute input diff --git a/2020/01-Report-Repair/input b/2020/01-Report-Repair/input new file mode 100644 index 0000000..8f18073 --- /dev/null +++ b/2020/01-Report-Repair/input @@ -0,0 +1,200 @@ +1962 +1577 +1750 +1836 +1762 +1691 +1726 +1588 +1370 +1043 +1307 +1552 +1813 +1804 +1765 +1893 +1610 +764 +1512 +1404 +1711 +1000 +1694 +1546 +1880 +1721 +2006 +1787 +1510 +1850 +1420 +1712 +1926 +1707 +1983 +1680 +1436 +389 +1448 +1875 +1333 +1733 +1935 +1794 +1337 +1863 +1769 +1635 +1499 +1807 +1326 +1989 +1705 +1673 +1829 +1684 +1716 +456 +1696 +1398 +1942 +1851 +1690 +1328 +1356 +1775 +1564 +1466 +1273 +1896 +766 +1814 +1810 +1537 +1463 +1755 +1341 +1665 +1520 +1366 +1387 +1976 +1717 +1737 +1551 +1760 +1496 +1664 +1450 +1319 +1674 +1630 +1301 +1330 +1658 +1637 +1655 +1439 +1832 +1948 +1339 +1656 +1449 +1296 +1489 +1758 +1939 +1857 +1402 +1394 +1882 +1446 +1412 +1430 +1212 +1377 +1501 +1873 +1812 +1667 +1560 +1654 +1575 +1999 +1581 +1792 +1299 +1843 +1383 +1351 +1297 +1822 +1801 +1977 +1316 +1477 +1980 +1693 +1220 +1554 +1607 +1903 +1669 +1593 +1955 +1286 +1909 +1280 +1854 +2005 +1820 +1803 +1763 +1660 +1410 +1974 +1808 +1816 +1723 +1936 +1423 +1818 +1800 +1294 +857 +496 +1248 +1670 +1993 +1929 +1966 +1381 +1259 +1285 +1797 +1644 +1919 +1267 +1509 +399 +1300 +1662 +1556 +1747 +1517 +1972 +1729 +1506 +1544 +1957 +1930 +1956 +1753 +1284 +1389 +1689 +1709 +1627 +1770 +847 diff --git a/2020/01-Report-Repair/second.hs b/2020/01-Report-Repair/second.hs new file mode 100644 index 0000000..9c7f3b3 --- /dev/null +++ b/2020/01-Report-Repair/second.hs @@ -0,0 +1,32 @@ +module Main where + +import Control.Monad (when) +import Data.Maybe (catMaybes, fromJust) +import System.Exit (die) + +exampleExpectedOutput = 241861950 + +compute2020 :: Int -> Int -> Int -> Maybe Int +compute2020 a b c + | a + b + c == 2020 = Just (a * b * c) + | otherwise = Nothing + +compute :: String -> Int +compute input = head . catMaybes $ processInput inputList + where + inputList :: [Int] + inputList = map read $ lines input + processInput :: [Int] -> [Maybe Int] + processInput (_:[]) = [Nothing] + processInput (x:xs) = (processA $ compute2020 x) xs ++ processInput xs + processA :: (Int -> Int -> Maybe Int) -> [Int] -> [Maybe Int] + processA f (_:[]) = [Nothing] + processA f (x:xs) = map (f x) xs ++ processA f xs + +main :: IO () +main = do + example <- readFile "example" + let exampleOutput = compute example + when (exampleOutput /= exampleExpectedOutput) (die $ "example failed: got " ++ show exampleOutput ++ " instead of " ++ show exampleExpectedOutput) + input <- readFile "input" + print $ compute input diff --git a/2020/01/example b/2020/01/example deleted file mode 100644 index e3fb011..0000000 --- a/2020/01/example +++ /dev/null @@ -1,6 +0,0 @@ -1721 -979 -366 -299 -675 -1456 diff --git a/2020/01/first.hs b/2020/01/first.hs deleted file mode 100644 index 5a615a9..0000000 --- a/2020/01/first.hs +++ /dev/null @@ -1,29 +0,0 @@ -module Main where - -import Control.Monad (when) -import Data.Maybe (catMaybes, fromJust) -import System.Exit (die) - -exampleExpectedOutput = 514579 - -compute2020 :: Int -> Int -> Maybe Int -compute2020 a b - | a + b == 2020 = Just (a * b) - | otherwise = Nothing - -compute :: String -> Int -compute input = head . catMaybes $ processInput inputList - where - inputList :: [Int] - inputList = map read $ lines input - processInput :: [Int] -> [Maybe Int] - processInput (_:[]) = [Nothing] - processInput (x:xs) = map (compute2020 x) xs ++ processInput xs - -main :: IO () -main = do - example <- readFile "example" - let exampleOutput = compute example - when (exampleOutput /= exampleExpectedOutput) (die $ "example failed: got " ++ show exampleOutput ++ " instead of " ++ show exampleExpectedOutput) - input <- readFile "input" - print $ compute input diff --git a/2020/01/input b/2020/01/input deleted file mode 100644 index 8f18073..0000000 --- a/2020/01/input +++ /dev/null @@ -1,200 +0,0 @@ -1962 -1577 -1750 -1836 -1762 -1691 -1726 -1588 -1370 -1043 -1307 -1552 -1813 -1804 -1765 -1893 -1610 -764 -1512 -1404 -1711 -1000 -1694 -1546 -1880 -1721 -2006 -1787 -1510 -1850 -1420 -1712 -1926 -1707 -1983 -1680 -1436 -389 -1448 -1875 -1333 -1733 -1935 -1794 -1337 -1863 -1769 -1635 -1499 -1807 -1326 -1989 -1705 -1673 -1829 -1684 -1716 -456 -1696 -1398 -1942 -1851 -1690 -1328 -1356 -1775 -1564 -1466 -1273 -1896 -766 -1814 -1810 -1537 -1463 -1755 -1341 -1665 -1520 -1366 -1387 -1976 -1717 -1737 -1551 -1760 -1496 -1664 -1450 -1319 -1674 -1630 -1301 -1330 -1658 -1637 -1655 -1439 -1832 -1948 -1339 -1656 -1449 -1296 -1489 -1758 -1939 -1857 -1402 -1394 -1882 -1446 -1412 -1430 -1212 -1377 -1501 -1873 -1812 -1667 -1560 -1654 -1575 -1999 -1581 -1792 -1299 -1843 -1383 -1351 -1297 -1822 -1801 -1977 -1316 -1477 -1980 -1693 -1220 -1554 -1607 -1903 -1669 -1593 -1955 -1286 -1909 -1280 -1854 -2005 -1820 -1803 -1763 -1660 -1410 -1974 -1808 -1816 -1723 -1936 -1423 -1818 -1800 -1294 -857 -496 -1248 -1670 -1993 -1929 -1966 -1381 -1259 -1285 -1797 -1644 -1919 -1267 -1509 -399 -1300 -1662 -1556 -1747 -1517 -1972 -1729 -1506 -1544 -1957 -1930 -1956 -1753 -1284 -1389 -1689 -1709 -1627 -1770 -847 diff --git a/2020/01/second.hs b/2020/01/second.hs deleted file mode 100644 index 9c7f3b3..0000000 --- a/2020/01/second.hs +++ /dev/null @@ -1,32 +0,0 @@ -module Main where - -import Control.Monad (when) -import Data.Maybe (catMaybes, fromJust) -import System.Exit (die) - -exampleExpectedOutput = 241861950 - -compute2020 :: Int -> Int -> Int -> Maybe Int -compute2020 a b c - | a + b + c == 2020 = Just (a * b * c) - | otherwise = Nothing - -compute :: String -> Int -compute input = head . catMaybes $ processInput inputList - where - inputList :: [Int] - inputList = map read $ lines input - processInput :: [Int] -> [Maybe Int] - processInput (_:[]) = [Nothing] - processInput (x:xs) = (processA $ compute2020 x) xs ++ processInput xs - processA :: (Int -> Int -> Maybe Int) -> [Int] -> [Maybe Int] - processA f (_:[]) = [Nothing] - processA f (x:xs) = map (f x) xs ++ processA f xs - -main :: IO () -main = do - example <- readFile "example" - let exampleOutput = compute example - when (exampleOutput /= exampleExpectedOutput) (die $ "example failed: got " ++ show exampleOutput ++ " instead of " ++ show exampleExpectedOutput) - input <- readFile "input" - print $ compute input -- cgit v1.2.3