Add solution for 2021 day 01
This commit is contained in:
parent
c2121387a1
commit
b429390ac2
@ -1,29 +1,29 @@
|
||||
# [Advent of Code 2021](https://adventofcode.com/2021)
|
||||
|
||||
## Progress
|
||||
|
||||
- [ ] Day 01
|
||||
- [ ] Day 02
|
||||
- [ ] Day 03
|
||||
- [ ] Day 04
|
||||
- [ ] Day 05
|
||||
- [ ] Day 06
|
||||
- [ ] Day 07
|
||||
- [ ] Day 08
|
||||
- [ ] Day 09
|
||||
- [ ] Day 10
|
||||
- [ ] Day 11
|
||||
- [ ] Day 12
|
||||
- [ ] Day 13
|
||||
- [ ] Day 14
|
||||
- [ ] Day 15
|
||||
- [ ] Day 16
|
||||
- [ ] Day 17
|
||||
- [ ] Day 18
|
||||
- [ ] Day 19
|
||||
- [ ] Day 20
|
||||
- [ ] Day 21
|
||||
- [ ] Day 22
|
||||
- [ ] Day 23
|
||||
- [ ] Day 24
|
||||
- [ ] Day 25
|
||||
| Solved | Day | Language |
|
||||
| :----: | :-: | :------- |
|
||||
| ✓ | 01 | Ruby |
|
||||
| | 02 | |
|
||||
| | 03 | |
|
||||
| | 04 | |
|
||||
| | 05 | |
|
||||
| | 06 | |
|
||||
| | 07 | |
|
||||
| | 08 | |
|
||||
| | 09 | |
|
||||
| | 10 | |
|
||||
| | 11 | |
|
||||
| | 12 | |
|
||||
| | 13 | |
|
||||
| | 14 | |
|
||||
| | 15 | |
|
||||
| | 16 | |
|
||||
| | 17 | |
|
||||
| | 18 | |
|
||||
| | 19 | |
|
||||
| | 20 | |
|
||||
| | 21 | |
|
||||
| | 22 | |
|
||||
| | 23 | |
|
||||
| | 24 | |
|
||||
| | 25 | |
|
||||
|
2000
2021/day-01/inputs/puzzle.txt
Normal file
2000
2021/day-01/inputs/puzzle.txt
Normal file
File diff suppressed because it is too large
Load Diff
10
2021/day-01/inputs/sample.txt
Normal file
10
2021/day-01/inputs/sample.txt
Normal file
@ -0,0 +1,10 @@
|
||||
199
|
||||
200
|
||||
208
|
||||
210
|
||||
200
|
||||
207
|
||||
240
|
||||
269
|
||||
260
|
||||
263
|
13
2021/day-01/part_one.rb
Executable file
13
2021/day-01/part_one.rb
Executable file
@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
def part_one(measurements)
|
||||
measurements
|
||||
.each_cons(2)
|
||||
.reduce(0) do |acc, (a, b)|
|
||||
a < b ? acc + 1 : acc
|
||||
end
|
||||
end
|
||||
|
||||
content = File.readlines(ARGV.first, chomp: true).map(&:to_i)
|
||||
result = part_one(content)
|
||||
puts(result)
|
15
2021/day-01/part_two.rb
Executable file
15
2021/day-01/part_two.rb
Executable file
@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
def part_two(measurements)
|
||||
measurements
|
||||
.each_cons(3)
|
||||
.map { |(x, y, z)| x + y + z }
|
||||
.each_cons(2)
|
||||
.reduce(0) do |acc, (a, b)|
|
||||
a < b ? acc + 1 : acc
|
||||
end
|
||||
end
|
||||
|
||||
content = File.readlines(ARGV.first, chomp: true).map(&:to_i)
|
||||
result = part_two(content)
|
||||
puts(result)
|
Loading…
Reference in New Issue
Block a user