Ruby (I get paid to write this)
This commit is contained in:
parent
ec12f162e4
commit
f6eba9c423
15
ruby/2015/1/problem.rb
Normal file
15
ruby/2015/1/problem.rb
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
input = File.read("../data/2015/1/input.txt").split("")
|
||||||
|
counts = input.tally
|
||||||
|
final_floor = counts["("] - counts[")"]
|
||||||
|
puts "Part 1: #{final_floor}"
|
||||||
|
|
||||||
|
floor = 0
|
||||||
|
steps = 0
|
||||||
|
input.each do |char|
|
||||||
|
floor += 1 if char == "("
|
||||||
|
floor -= 1 if char == ")"
|
||||||
|
steps += 1
|
||||||
|
break if floor < 0
|
||||||
|
end
|
||||||
|
|
||||||
|
puts "Part 2: #{steps}"
|
6
ruby/bin/run
Executable file
6
ruby/bin/run
Executable file
@ -0,0 +1,6 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
year=$1
|
||||||
|
day=$2
|
||||||
|
|
||||||
|
time ruby $year/$day/problem.rb
|
Loading…
Reference in New Issue
Block a user