Skip to content

Instantly share code, notes, and snippets.

@cielavenir
Created October 24, 2015 06:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cielavenir/496a8cd01ebf83ee9ed1 to your computer and use it in GitHub Desktop.
Save cielavenir/496a8cd01ebf83ee9ed1 to your computer and use it in GitHub Desktop.
行列のできるラーメン屋 ref: http://qiita.com/cielavenir/items/fa6e7b4e79e1673bbe05
#!/usr/bin/env ruby
#https://gist.github.com/mtsmfm/4b8ffb53ffac055f5843
N=8
def fill_table(a,n)
idx=N.times.find{|st|n.times.all?{|i|a[(st+i)%N]==0}}
if idx
n.times{|i|a[(idx+i)%N]=1}
true
else
false
end
end
def clear_table(a)
N.times{|i|
a[i]=0 if a[i]==4
}
end
def take_turn(a)
N.times{|i|
a[i]+=1 if a[i]>0
}
end
if __FILE__==$0
while gets
a=[0]*N
$_.chomp.chars{|c|
clear_table(a)
f=fill_table(a,c.to_i)
take_turn(a)
redo if !f
}
puts a.map{|e|e==0 ? 0 : 1}*''
STDOUT.flush
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment