Created
December 23, 2015 11:08
-
-
Save stansidel/a1cd566c280afd5a0e0e to your computer and use it in GitHub Desktop.
A sequence for FlatStack
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
#!/usr/bin/env ruby | |
element = '1' | |
elements_count = ARGV[0].to_i | |
max_count = 20 | |
if elements_count == 0 | |
print "Write a number of sequence elements to print as an argument for the script. It should be between 1 and #{max_count}.\n" | |
exit | |
end | |
if elements_count > max_count | |
puts "You've asked to print #{elements_count} elements. I won't do that many, just printing #{max_count}." | |
elements_count = max_count | |
end | |
puts element | |
for i in 2..elements_count | |
element = element.chars.slice_when{|a,b| a != b}.map{|a| "#{a.count}#{a.first}"}.join | |
puts element | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment