Skip to content

Instantly share code, notes, and snippets.

@zunda
Last active January 25, 2023 19:13
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 zunda/ed6fb48973e8f02e8c636d3c173b6a3a to your computer and use it in GitHub Desktop.
Save zunda/ed6fb48973e8f02e8c636d3c173b6a3a to your computer and use it in GitHub Desktop.
拡張素数日
#!/usr/bin/ruby
#
# Copyright 2023 zunda <zundan at gmail.com>
#
# Permission is granted for use, copying, modification, distribution,
# and distribution of modified versions of this work as long as the
# above copyright notice is included.
#
require 'prime'
today = Time.now.localtime.strftime('%Y%m%d')
a = today.scan(/\d/).map{|i| i.to_i}.reverse
b = a.max + 1
r = nil
while b < 100
if a.map.with_index{|n,i| n*b**i}.sum.prime?
r = "今日#{today}は基数#{b}で素数だからがんばろう"
break
end
b += 1
end
r ||= "今日#{today}は素数日じゃないかもしれない"
puts r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment