new(haskell): Day 1 first puzzle in haskell.
authorsgf <sgf.dma@gmail.com>
Fri, 10 Dec 2021 20:05:02 +0000 (23:05 +0300)
committersgf <sgf.dma@gmail.com>
Fri, 10 Dec 2021 20:05:02 +0000 (23:05 +0300)
day1/Main.hs [new file with mode: 0644]
day1/main.go

diff --git a/day1/Main.hs b/day1/Main.hs
new file mode 100644 (file)
index 0000000..d571ad2
--- /dev/null
@@ -0,0 +1,10 @@
+
+f1 :: [Int] -> Int
+f1 [] = 0
+f1 (k : ks) = foldr (\x g y -> let n = g x in if y < x then n + 1 else n) (const 0) ks k
+
+main :: IO ()
+main = do
+    c <- readFile "day1/input.txt"
+    let xs = map read (lines c)
+    print (f1 xs)
index 920df87..a47463b 100644 (file)
@@ -89,7 +89,7 @@ func RunF1(input string) {
         fmt.Printf("Error: %v\n", err)
         return
     }
-    fmt.Printf("Answer: %d\n", i)
+    fmt.Printf("Answer1: %d\n", i)
 }
 
 func RunF2(input string) {
@@ -102,6 +102,6 @@ func RunF2(input string) {
         fmt.Printf("Error: %v\n", err)
         return
     }
-    fmt.Printf("Answer: %d\n", n)
+    fmt.Printf("Answer2: %d\n", n)
 }