Last active
July 19, 2016 00:42
-
-
Save takano32/1fe8860377a7b6592244c2b3acceb10c to your computer and use it in GitHub Desktop.
階乗フィーバー数問題
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# http://riverplus.net/39/ | |
# https://twitter.com/riverplus/status/754322322220158977 | |
# | |
class Factorial | |
@@f = 1 | |
@@now = 0 | |
def self.next | |
@@now += 1 | |
@@f *= @@now | |
end | |
def self.index | |
@@now + 1 | |
end | |
end | |
1.upto(12) do |i| | |
puts "#{Factorial.index}: #{Factorial.next}" | |
end | |
def solve?(f) | |
ns = f.to_s[0...6].split '' | |
return false if ns.size < 6 | |
(ns - [ns.first]).empty? | |
end | |
i = 0 | |
loop do | |
i += 1 | |
f = Factorial.next | |
if solve? f | |
puts i | |
end | |
end | |
Author
takano32
commented
Jul 19, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment