Skip to content

Commit 3b5b552

Browse files
committed
[Day 7] Mainly coding style
1 parent 46c8d2b commit 3b5b552

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ This Julia package contains my solutions for [Advent of Code 2024](https://adven
1616
| 4 | [:white_check_mark:](https://adventofcode.com/2024/day/4) | 1.798 ms | 3.06 MiB | [:white_check_mark:](https://github.com/goggle/AdventOfCode2024.jl/blob/main/src/day04.jl) |
1717
| 5 | [:white_check_mark:](https://adventofcode.com/2024/day/5) | 2.104 ms | 1.26 MiB | [:white_check_mark:](https://github.com/goggle/AdventOfCode2024.jl/blob/main/src/day05.jl) |
1818
| 6 | [:white_check_mark:](https://adventofcode.com/2024/day/6) | 549.253 ms | 50.91 MiB | [:white_check_mark:](https://github.com/goggle/AdventOfCode2024.jl/blob/main/src/day06.jl) |
19-
| 7 | [:white_check_mark:](https://adventofcode.com/2024/day/7) | 33.994 ms | 1.53 MiB | [:white_check_mark:](https://github.com/goggle/AdventOfCode2024.jl/blob/main/src/day07.jl) |
19+
| 7 | [:white_check_mark:](https://adventofcode.com/2024/day/7) | 30.710 ms | 1.53 MiB | [:white_check_mark:](https://github.com/goggle/AdventOfCode2024.jl/blob/main/src/day07.jl) |
2020
| 8 | [:white_check_mark:](https://adventofcode.com/2024/day/8) | 316.122 μs | 671.41 KiB | [:white_check_mark:](https://github.com/goggle/AdventOfCode2024.jl/blob/main/src/day08.jl) |
2121
| 9 | [:white_check_mark:](https://adventofcode.com/2024/day/9) | 28.732 ms | 9.58 MiB | [:white_check_mark:](https://github.com/goggle/AdventOfCode2024.jl/blob/main/src/day09.jl) |
2222
| 10 | [:white_check_mark:](https://adventofcode.com/2024/day/10) | 578.868 μs | 633.67 KiB | [:white_check_mark:](https://github.com/goggle/AdventOfCode2024.jl/blob/main/src/day10.jl) |

src/day07.jl

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function parse_input(input)
1313
numbers = Vector{Int}[]
1414
concat_factors = Vector{Int}[]
1515

16-
for line in lines
16+
for line lines
1717
left, right = split(line, ':')
1818
nums = parse.(Int, split(right))
1919
factors = [10^ndigits(n) for n in nums]
@@ -27,17 +27,12 @@ end
2727

2828
function solve(test_values::Vector{Int}, numbers::Vector{Vector{Int}}, concat_factors::Vector{Vector{Int}})
2929
p1 = p2 = 0
30-
for i in eachindex(test_values)
30+
for i eachindex(test_values)
3131
nums = numbers[i]
32-
isempty(nums) && continue
33-
tv = test_values[i]
34-
cf = concat_factors[i]
35-
36-
valid1 = _valid_p1(tv, nums[1], 2, nums)
37-
valid2 = valid1 ? true : _valid_p2(tv, nums[1], 2, nums, cf)
38-
39-
p1 += valid1 * tv
40-
p2 += (valid1 || valid2) * tv
32+
valid1 = _valid_p1(test_values[i], nums[1], 2, nums)
33+
valid2 = valid1 ? true : _valid_p2(test_values[i], nums[1], 2, nums, concat_factors[i])
34+
p1 += valid1 * test_values[i]
35+
p2 += (valid1 || valid2) * test_values[i]
4136
end
4237
return [p1, p2]
4338
end

0 commit comments

Comments
 (0)