Initial commit
This commit is contained in:
commit
f242d2b0df
420 changed files with 62521 additions and 0 deletions
7
2022/day01/day01.bqn
Normal file
7
2022/day01/day01.bqn
Normal file
|
@ -0,0 +1,7 @@
|
|||
P←(10⊸×⊸+˜´∘⌽0∾-⟜'0') # string->number, 0 for empty string
|
||||
i←P¨¨(+`0=≠¨)⊸⊔•FLines"input" # parse input as list of lists
|
||||
# Alternative version, with bqn-libs
|
||||
#str ← •Import"../bqn-libs/strings.bqn"
|
||||
#i ← str.ToNats¨ (2⥊@+10) str.Split •FChars"input"
|
||||
•Show ⌈´+´¨i # part 1
|
||||
•Show +´3↑∨+´¨i # part 2
|
3
2022/day01/day01.jl
Normal file
3
2022/day01/day01.jl
Normal file
|
@ -0,0 +1,3 @@
|
|||
ll = [[parse(Int, x) for x in split(s)] for s in split(read("input", String), "\n\n")]
|
||||
println(maximum(sum(l) for l in ll))
|
||||
println(sum(sort([sum(l) for l in ll])[end-2:end]))
|
3
2022/day01/day01.py
Normal file
3
2022/day01/day01.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
l = [sum(map(int, x.splitlines())) for x in open("input").read().split("\n\n")]
|
||||
print(max(l))
|
||||
print(sum(sorted(l)[-3:]))
|
25
2022/day01/day01.rkt
Normal file
25
2022/day01/day01.rkt
Normal file
|
@ -0,0 +1,25 @@
|
|||
#lang racket
|
||||
|
||||
(require threading)
|
||||
|
||||
(define (read-input filename)
|
||||
(for/list ([s (string-split (file->string filename) "\n\n")])
|
||||
(for/list ([n (string-split s "\n")])
|
||||
(string->number n))))
|
||||
|
||||
(define (sum l)
|
||||
(apply + l))
|
||||
|
||||
(define part1
|
||||
(lambda~>> (map sum)
|
||||
(apply max)))
|
||||
|
||||
(define part2
|
||||
(lambda~> (map sum _)
|
||||
(sort _ >)
|
||||
(take _ 3)
|
||||
(apply + _)))
|
||||
|
||||
(define input (read-input "input"))
|
||||
(displayln (part1 input))
|
||||
(displayln (part2 input))
|
2254
2022/day01/input
Normal file
2254
2022/day01/input
Normal file
File diff suppressed because it is too large
Load diff
14
2022/day01/test
Normal file
14
2022/day01/test
Normal file
|
@ -0,0 +1,14 @@
|
|||
1000
|
||||
2000
|
||||
3000
|
||||
|
||||
4000
|
||||
|
||||
5000
|
||||
6000
|
||||
|
||||
7000
|
||||
8000
|
||||
9000
|
||||
|
||||
10000
|
Loading…
Add table
Add a link
Reference in a new issue