Skip to content

Commit

Permalink
[Day 7] Read input only once
Browse files Browse the repository at this point in the history
  • Loading branch information
goggle committed Jan 2, 2024
1 parent 8d80b24 commit 4be75cc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This Julia package contains my solutions for [Advent of Code 2023](https://adven
| 4 | [:white_check_mark:](https://adventofcode.com/2023/day/4) | 2.745 ms | 1.40 MiB | [:white_check_mark:](https://github.com/goggle/AdventOfCode2023.jl/blob/master/src/day04.jl) |
| 5 | [:white_check_mark:](https://adventofcode.com/2023/day/5) | 71.969 ms | 198.09 KiB | [:white_check_mark:](https://github.com/goggle/AdventOfCode2023.jl/blob/master/src/day05.jl) |
| 6 | [:white_check_mark:](https://adventofcode.com/2023/day/6) | 7.953 μs | 7.44 KiB | [:white_check_mark:](https://github.com/goggle/AdventOfCode2023.jl/blob/master/src/day06.jl) |
| 7 | [:white_check_mark:](https://adventofcode.com/2023/day/7) | 13.584 ms | 18.21 MiB | [:white_check_mark:](https://github.com/goggle/AdventOfCode2023.jl/blob/master/src/day07.jl) |
| 7 | [:white_check_mark:](https://adventofcode.com/2023/day/7) | 11.831 ms | 15.28 MiB | [:white_check_mark:](https://github.com/goggle/AdventOfCode2023.jl/blob/master/src/day07.jl) |
| 8 | [:white_check_mark:](https://adventofcode.com/2023/day/8) | 11.879 ms | 556.42 KiB | [:white_check_mark:](https://github.com/goggle/AdventOfCode2023.jl/blob/master/src/day08.jl) |
| 9 | [:white_check_mark:](https://adventofcode.com/2023/day/9) | 1.408 ms | 1.72 MiB | [:white_check_mark:](https://github.com/goggle/AdventOfCode2023.jl/blob/master/src/day09.jl) |
| 10 | [:white_check_mark:](https://adventofcode.com/2023/day/10) | 43.997 ms | 8.82 MiB | [:white_check_mark:](https://github.com/goggle/AdventOfCode2023.jl/blob/master/src/day10.jl) |
Expand Down
5 changes: 2 additions & 3 deletions src/day07.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ end
function day07(input::String = readInput(joinpath(@__DIR__, "..", "data", "day07.txt")))
hands = [Hand([_to_value(c) for c x[1]], parse(Int, x[2])) for x split.(eachsplit(rstrip(input), "\n"), " ")]
p1 = solve(hands)
handsp2 = [Handp2([_to_value(c; p2=true) for c x[1]], parse(Int, x[2])) for x split.(eachsplit(rstrip(input), "\n"), " ")]
handsp2 = map(y -> Handp2(map(x -> x == 11 ? 1 : x, y.cards), y.bid), hands)
p2 = solve(handsp2)
return [p1, p2]
end

function _to_value(c::Char; p2 = false)
p2 && c == 'J' && return Int8(1)
function _to_value(c::Char)
isdigit(c) && return Int8(c - '0')
c == 'T' && return Int8(10)
c == 'J' && return Int8(11)
Expand Down

0 comments on commit 4be75cc

Please sign in to comment.