-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
day02
1 parent
1038039
commit e33f7d4
Showing
4 changed files
with
62 additions
and
10 deletions.
There are no files selected for viewing
Submodule inputs
updated
from 45b7a4 to 2c9945
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
module Day02 | ||
using ..AdventOfCode24 | ||
|
||
""" | ||
day02() | ||
Solves the two puzzles of day 02. | ||
""" | ||
|
||
function day02(input::String = readInput(02)) | ||
r = r"(\d+)" | ||
|
||
s0 = 0 | ||
s1 = 0 | ||
|
||
for l in split(input, "\n") | ||
|
||
n = [parse(Int, m.match) for m in eachmatch(r, l)] | ||
|
||
if is_safe(n) | ||
s0 += 1 | ||
s1 += 1 | ||
else | ||
|
||
for k in eachindex(n) | ||
# n0 = deleteat!(copy(n), k) | ||
if is_safe(n[begin:end .!= k]) | ||
s1 += 1 | ||
break | ||
end | ||
end | ||
|
||
end | ||
|
||
end | ||
|
||
return [s0, s1] | ||
end | ||
|
||
|
||
function is_safe(n::Vector{Int}) | ||
diffs = diff(n) | ||
|
||
if all(@. 0 < diffs <= 3 ) || all(@. 0 > diffs >= -3) | ||
return true | ||
else | ||
return false | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters