mirror of
https://github.com/onyx-and-iris/aoc2025.git
synced 2026-04-08 19:13:37 +00:00
first commit
This commit is contained in:
27
day_01/1.rb
Executable file
27
day_01/1.rb
Executable file
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
class Main
|
||||
def run
|
||||
current = 50
|
||||
count = 0
|
||||
|
||||
$stdin.each_line do |line|
|
||||
direction, magnitude = line[0], line[1..].to_i
|
||||
|
||||
case direction
|
||||
when "R"
|
||||
current = (current + magnitude) % 100
|
||||
when "L"
|
||||
current = (current -= magnitude) % 100
|
||||
end
|
||||
|
||||
if current == 0
|
||||
count += 1
|
||||
end
|
||||
end
|
||||
|
||||
puts count
|
||||
end
|
||||
end
|
||||
|
||||
Main.new.run
|
||||
32
day_01/2.rb
Executable file
32
day_01/2.rb
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
class Main
|
||||
def run
|
||||
current = 50
|
||||
count = 0
|
||||
|
||||
$stdin.each_line do |line|
|
||||
direction, magnitude = line[0], line[1..].to_i
|
||||
|
||||
loop do
|
||||
case direction
|
||||
when "R"
|
||||
current = (current + 1) % 100
|
||||
when "L"
|
||||
current = (current - 1) % 100
|
||||
end
|
||||
|
||||
if current == 0
|
||||
count += 1
|
||||
end
|
||||
|
||||
magnitude -= 1
|
||||
break if magnitude == 0
|
||||
end
|
||||
end
|
||||
|
||||
puts count
|
||||
end
|
||||
end
|
||||
|
||||
Main.new.run
|
||||
Reference in New Issue
Block a user