Last active
October 3, 2017 21:32
-
-
Save jonelf/3030a7d343f691348c68 to your computer and use it in GitHub Desktop.
A "random" FizzBuzz in Ruby. This is just for fun.
This file contains hidden or 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
c = ('a'..'z').to_a | |
srand(1792579 * 1800) | |
f = (0..3).map { c[rand(26)] } | |
b = (0..3).map { c[rand(26)] } | |
a = [f, b].map {|s| s.join.capitalize } | |
srand(s = 93113 * 19243) | |
puts (0..99).map{|i| [a[0], a[0] + a[(srand(s) if i%15 < 1) || 1].to_s, a[1], i+1][rand(4)] } |
FizzBuzz repeats itself every 15th step and this is how to find such a sequence.
require 'pp'
(0..999999999999999).each do |n|
srand(n)
a = (0..14).map { rand(4) }
b = [a[1], a[3], a[6], a[7], a[10], a[12], a[13]]
c = [a[5], a[8], a[11]]
if a[4] == a[9] && b.all? {|n| n == a[0]} && c.all? {|n| n == a[2]} && [a[0], a[2], a[4]].uniq.length == 3
puts n.to_s
pp a
break
end
end
The array we are searching for looks like this
[A, A, B, A, C, B, A, A, B, C, A, B, A, A, D]
a=%w[Fizz ☹ Buzz]
a[1]=a[0]+a[2]
srand(1791773459)
((0..14).map{rand(4)}*7)[0..99].each_with_index{|v,i|puts a[v]||i+1}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is one way to find the seed for an arbitrary string.