Ruby/2024/03: add solution

This commit is contained in:
Felix Bargfeldt 2024-12-03 07:46:36 +01:00
parent 0aba27c744
commit 8c83e5ecd5
Signed by: Defelo
GPG key ID: 2A05272471204DD3
2 changed files with 22 additions and 2 deletions

View file

@ -9,11 +9,11 @@
|[2021](https://adventofcode.com/2021/leaderboard)|**136**|438|13.41% (of 1014)|0.0532% (of ≥255548)|
|[2020](https://adventofcode.com/2020/leaderboard)|**621**|46|65.23% (of 952)|0.3146% (of ≥197402)|
## [2024](https://adventofcode.com/2024) ([<img height=18 src=".assets/rs.svg"> Rust](Rust/2024): 3/25 | [<img height=18 src=".assets/hs.svg"> Haskell](Haskell/2024): 3/25 | [<img height=18 src=".assets/ua.png"> Uiua](Uiua/2024): 3/25 | [<img height=18 src=".assets/rb.svg"> Ruby](Ruby/2024): 2/25 | [<img height=18 src=".assets/nix.svg"> Nix](Nix/2024): 1/25)
## [2024](https://adventofcode.com/2024) ([<img height=18 src=".assets/rs.svg"> Rust](Rust/2024): 3/25 | [<img height=18 src=".assets/hs.svg"> Haskell](Haskell/2024): 3/25 | [<img height=18 src=".assets/ua.png"> Uiua](Uiua/2024): 3/25 | [<img height=18 src=".assets/rb.svg"> Ruby](Ruby/2024): 3/25 | [<img height=18 src=".assets/nix.svg"> Nix](Nix/2024): 1/25)
|Mo|Tu|We|Th|Fr|Sa|Su|
|-|-|-|-|-|-|-|
|||||||[**1**](https://adventofcode.com/2024/day/1) [<img height=12 src=".assets/rs.svg">](Rust/2024/01.rs "Rust solution for 2024/01") [<img height=12 src=".assets/hs.svg">](Haskell/2024/01.hs "Haskell solution for 2024/01") [<img height=12 src=".assets/ua.png">](https://uiua.org/pad?src=JnNjCgrCsOKKn-KNieKKnOKKnOKLleKIqeKJoEBcbixAIC4K4oipLyviioMo4pmtw5fiip7iirg9fOKMtS3iiKnijYYpCg== "Uiua solution for 2024/01") [<img height=12 src=".assets/nix.svg">](Nix/2024/01.nix "Nix solution for 2024/01") [<img height=12 src=".assets/rb.svg">](Ruby/2024/01.rb "Ruby solution for 2024/01")|
|[**2**](https://adventofcode.com/2024/day/2) [<img height=12 src=".assets/rs.svg">](Rust/2024/02.rs "Rust solution for 2024/02") [<img height=12 src=".assets/hs.svg">](Haskell/2024/02.hs "Haskell solution for 2024/02") [<img height=12 src=".assets/ua.png">](https://uiua.org/pad?src=JnNjCgriipwo4pah4oqc4ouVKeKIqeKJoEBcbixAIC4KCkNoZWNrIOKGkCDDl-KKgygvw5fiiaQz4oy1fOKJjcKkMeKMteKXtMKxKSDiiaEvLeKXqzIK4oipLyviiaHil4fiioMoL-KGpeKJoShDaGVja-KWvSniip7iiaAu4oeh4qe74p-cwqR8Q2hlY2spCg== "Uiua solution for 2024/02") [<img height=12 src=".assets/rb.svg">](Ruby/2024/02.rb "Ruby solution for 2024/02")|[**3**](https://adventofcode.com/2024/day/3) [<img height=12 src=".assets/rs.svg">](Rust/2024/03.rs "Rust solution for 2024/03") [<img height=12 src=".assets/hs.svg">](Haskell/2024/03.hs "Haskell solution for 2024/03") [<img height=12 src=".assets/ua.png">](https://uiua.org/pad?src=JnNjCgrilr3irJoxXCjihqXihqfiipnCsOKKnynijYniip_CrOKIqeKMlSJkb24ndCgpIiwiZG8oKSIuLgriiKkoLysvw5fii5Xihpgx4o2JcmVnZXgibXVsXFwoKFxcZCspLChcXGQrKVxcKSIpCg== "Uiua solution for 2024/03")|[**4**](https://adventofcode.com/2024/day/4)|[**5**](https://adventofcode.com/2024/day/5)|[**6**](https://adventofcode.com/2024/day/6)|[**7**](https://adventofcode.com/2024/day/7)|[**8**](https://adventofcode.com/2024/day/8)|
|[**2**](https://adventofcode.com/2024/day/2) [<img height=12 src=".assets/rs.svg">](Rust/2024/02.rs "Rust solution for 2024/02") [<img height=12 src=".assets/hs.svg">](Haskell/2024/02.hs "Haskell solution for 2024/02") [<img height=12 src=".assets/ua.png">](https://uiua.org/pad?src=JnNjCgriipwo4pah4oqc4ouVKeKIqeKJoEBcbixAIC4KCkNoZWNrIOKGkCDDl-KKgygvw5fiiaQz4oy1fOKJjcKkMeKMteKXtMKxKSDiiaEvLeKXqzIK4oipLyviiaHil4fiioMoL-KGpeKJoShDaGVja-KWvSniip7iiaAu4oeh4qe74p-cwqR8Q2hlY2spCg== "Uiua solution for 2024/02") [<img height=12 src=".assets/rb.svg">](Ruby/2024/02.rb "Ruby solution for 2024/02")|[**3**](https://adventofcode.com/2024/day/3) [<img height=12 src=".assets/rs.svg">](Rust/2024/03.rs "Rust solution for 2024/03") [<img height=12 src=".assets/hs.svg">](Haskell/2024/03.hs "Haskell solution for 2024/03") [<img height=12 src=".assets/ua.png">](https://uiua.org/pad?src=JnNjCgrilr3irJoxXCjihqXihqfiipnCsOKKnynijYniip_CrOKIqeKMlSJkb24ndCgpIiwiZG8oKSIuLgriiKkoLysvw5fii5Xihpgx4o2JcmVnZXgibXVsXFwoKFxcZCspLChcXGQrKVxcKSIpCg== "Uiua solution for 2024/03") [<img height=12 src=".assets/rb.svg">](Ruby/2024/03.rb "Ruby solution for 2024/03")|[**4**](https://adventofcode.com/2024/day/4)|[**5**](https://adventofcode.com/2024/day/5)|[**6**](https://adventofcode.com/2024/day/6)|[**7**](https://adventofcode.com/2024/day/7)|[**8**](https://adventofcode.com/2024/day/8)|
|[**9**](https://adventofcode.com/2024/day/9)|[**10**](https://adventofcode.com/2024/day/10)|[**11**](https://adventofcode.com/2024/day/11)|[**12**](https://adventofcode.com/2024/day/12)|[**13**](https://adventofcode.com/2024/day/13)|[**14**](https://adventofcode.com/2024/day/14)|[**15**](https://adventofcode.com/2024/day/15)|
|[**16**](https://adventofcode.com/2024/day/16)|[**17**](https://adventofcode.com/2024/day/17)|[**18**](https://adventofcode.com/2024/day/18)|[**19**](https://adventofcode.com/2024/day/19)|[**20**](https://adventofcode.com/2024/day/20)|[**21**](https://adventofcode.com/2024/day/21)|[**22**](https://adventofcode.com/2024/day/22)|
|[**23**](https://adventofcode.com/2024/day/23)|[**24**](https://adventofcode.com/2024/day/24)|[**25**](https://adventofcode.com/2024/day/25)|26|27|28|29|

20
Ruby/2024/03.rb Normal file
View file

@ -0,0 +1,20 @@
input = File.read(ARGV[0])
a = 0
b = 0
enabled = true
input.scan(/(mul\((\d+),(\d+)\)|do\(\)|don't\(\))/).each {
if _1[0] == "do()"
enabled = true
elsif _1[0] == "don't()"
enabled = false
else
x = _1[1].to_i * _1[2].to_i
a += x
b += x if enabled
end
}
puts a
puts b