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)
|
# [Advent of Code 2021](https://adventofcode.com/2021)
|
||||||
|
|
||||||
## Progress
|
| Solved | Day | Language |
|
||||||
|
| :----: | :-: | :------- |
|
||||||
- [ ] Day 01
|
| ✓ | 01 | Ruby |
|
||||||
- [ ] Day 02
|
| | 02 | |
|
||||||
- [ ] Day 03
|
| | 03 | |
|
||||||
- [ ] Day 04
|
| | 04 | |
|
||||||
- [ ] Day 05
|
| | 05 | |
|
||||||
- [ ] Day 06
|
| | 06 | |
|
||||||
- [ ] Day 07
|
| | 07 | |
|
||||||
- [ ] Day 08
|
| | 08 | |
|
||||||
- [ ] Day 09
|
| | 09 | |
|
||||||
- [ ] Day 10
|
| | 10 | |
|
||||||
- [ ] Day 11
|
| | 11 | |
|
||||||
- [ ] Day 12
|
| | 12 | |
|
||||||
- [ ] Day 13
|
| | 13 | |
|
||||||
- [ ] Day 14
|
| | 14 | |
|
||||||
- [ ] Day 15
|
| | 15 | |
|
||||||
- [ ] Day 16
|
| | 16 | |
|
||||||
- [ ] Day 17
|
| | 17 | |
|
||||||
- [ ] Day 18
|
| | 18 | |
|
||||||
- [ ] Day 19
|
| | 19 | |
|
||||||
- [ ] Day 20
|
| | 20 | |
|
||||||
- [ ] Day 21
|
| | 21 | |
|
||||||
- [ ] Day 22
|
| | 22 | |
|
||||||
- [ ] Day 23
|
| | 23 | |
|
||||||
- [ ] Day 24
|
| | 24 | |
|
||||||
- [ ] Day 25
|
| | 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