projects
/
aoc-2021.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
0c4a4bf
)
new(haskell): Day 1 first puzzle in haskell.
author
sgf
<sgf.dma@gmail.com>
Fri, 10 Dec 2021 20:05:02 +0000
(23:05 +0300)
committer
sgf
<sgf.dma@gmail.com>
Fri, 10 Dec 2021 20:05:02 +0000
(23:05 +0300)
day1/Main.hs
[new file with mode: 0644]
patch
|
blob
day1/main.go
patch
|
blob
|
history
diff --git a/day1/Main.hs
b/day1/Main.hs
new file mode 100644
(file)
index 0000000..
d571ad2
--- /dev/null
+++ b/
day1/Main.hs
@@ -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)
diff --git
a/day1/main.go
b/day1/main.go
index
920df87
..
a47463b
100644
(file)
--- a/
day1/main.go
+++ b/
day1/main.go
@@
-89,7
+89,7
@@
func RunF1(input string) {
fmt.Printf("Error: %v\n", err)
return
}
- fmt.Printf("Answer: %d\n", i)
+ fmt.Printf("Answer
1
: %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("Answer
2
: %d\n", n)
}