Skip to content

Instantly share code, notes, and snippets.

@aruponse
Created April 11, 2016 15:45
Show Gist options
  • Save aruponse/c9afa590c8f42e491259449570504685 to your computer and use it in GitHub Desktop.
Save aruponse/c9afa590c8f42e491259449570504685 to your computer and use it in GitHub Desktop.
Codejam
input = ARGV[0]
index = 0
numbers = ""
File.open(input, 'r') do |f|
while line = f.gets
if index==0
limit=line.to_i
index+=1
next
end
if line.to_i==0
puts "Case \#" + index.to_s + ": INSOMNIA"
index+=1
next
end
multiplier_counter = 1
while numbers.length < 10
product=line.to_i*multiplier_counter
product.to_s.split(//).each do |d|
unless numbers.index(d)
numbers << d
end
end
multiplier_counter+=1
end
puts "Case \#" + index.to_s + ": " + product.to_s
index+=1
numbers=""
end
end
class Pancake
def set_string(str)
@str = str
end
def countFlips
flips = 1 + @str.scan(/\+-/).count + @str.scan(/\-+/).count
if @str.end_with? "-"
return flips
else
return flips - 1
end
end
end
pancake = Pancake.new
input = ARGV[0]
index = 0
numbers = ""
File.open(input, 'r') do |f|
while line = f.gets
if index==0
limit=line.to_i
index+=1
next
end
pancake.set_string(line)
puts "Case #" + index.to_s + ": " + pancake.countFlips().to_s
index+=1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment