Skip to content
This repository has been archived by the owner on Apr 9, 2020. It is now read-only.

Commit

Permalink
day 1 - frequency lists
Browse files Browse the repository at this point in the history
  • Loading branch information
mackuba committed Dec 1, 2018
0 parents commit 90a3639
Show file tree
Hide file tree
Showing 3 changed files with 1,070 additions and 0 deletions.
10 changes: 10 additions & 0 deletions day1/1frequency.cr
@@ -0,0 +1,10 @@
#!/usr/bin/env crystal run

sum = 0

STDIN.each_line do |line|
value = line.strip.to_i
sum += value
end

puts sum
23 changes: 23 additions & 0 deletions day1/2repeating.cr
@@ -0,0 +1,23 @@
#!/usr/bin/env crystal run

list = [] of Int32

STDIN.each_line do |line|
value = line.strip.to_i
list << value
end

found = {0 => true}
sum = 0

loop do
list.each do |value|
sum += value
if found[sum]?
puts sum
exit
else
found[sum] = true
end
end
end

0 comments on commit 90a3639

Please sign in to comment.