Skip to content

Instantly share code, notes, and snippets.

@pocket7878
Created September 24, 2013 05:36
Show Gist options
  • Save pocket7878/6680752 to your computer and use it in GitHub Desktop.
Save pocket7878/6680752 to your computer and use it in GitHub Desktop.
ナムドット問題僕の回答 出力の行数を減らすためにSetを使ってる。
require 'set'
k = [0]*5; m = [0]*5
begin
puts Set.new([*1..5]).divide{|i| k[i-1]}.map{|i| i.to_a*""}*"."
end while
(if i = [4,3,2,1].index{|i| k[i] <= m[i-1]}; then i=4-i
k[i]+=1; m[i] = m[i]>k[i] ? m[i] : k[i]
((i+1)..4).each{|j| k[j] = k[0]; m[j] = m[i]; }
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment