-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path05-intern.jl
More file actions
28 lines (22 loc) · 854 Bytes
/
Copy path05-intern.jl
File metadata and controls
28 lines (22 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
input_filename = "input.txt"
function is_nice(string::String)
has_enough_vowels = count(r"[aeiou]", string) >= 3
has_double = occursin(r"([a-z])\1", string)
has_forbidden = occursin(r"(ab|cd|pq|xy)", string)
return has_enough_vowels && has_double && !has_forbidden
end
function is_nice_bis(string::String)
has_pair = occursin(r"([a-z]{2}).*\1", string)
has_repeat = occursin(r"([a-z])[a-z]\1", string)
return has_pair && has_repeat
end
for s in ["ugknbfddgicrmopn", "aaa", "jchzalrnumimnmhp", "haegwjzuvuyypxyu", "dvszwmarrgswjxmb"]
println(s, " : ", is_nice(s))
end
println()
for s in ["qjhvhtzxzqqjkmpb", "xxyxx", "uurcxstgmygtbstg", "ieodomkazucvgmuy"]
println(s, " : ", is_nice_bis(s))
end
for (i, f) in enumerate([is_nice, is_nice_bis])
println("Part ", i, ": ", count(f, readlines(input_filename)))
end