Skip to content

Instantly share code, notes, and snippets.

@ggPeti
Created October 16, 2016 17:12
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 ggPeti/069cf8325bcba321d7d991cca9933e29 to your computer and use it in GitHub Desktop.
Save ggPeti/069cf8325bcba321d7d991cca9933e29 to your computer and use it in GitHub Desktop.
#!/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