Created
October 16, 2016 17:12
-
-
Save ggPeti/069cf8325bcba321d7d991cca9933e29 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 | |
# Wolfram cellular automaton simulator | |
# Usage: ./rule.rb <rulenr> [<generations>|100] | |
rule = 7.downto(0).map { |x| x.to_s(2).rjust(3, ?0).chars.map(&:to_i) }.zip(ARGV.shift.to_i.to_s(2).rjust(8, ?0).chars.map(&:to_i)).to_h | |
steps = ARGV.shift&.to_i || 100 | |
row = [0] * steps + [1] + [0] * steps | |
steps.times { | |
puts(row.map { |c| c == 0 ? ' ' : "\u2588" }.join) | |
row = ([row.first] + row + [row.last]).each_cons(3).map(&rule.method(:[])) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment