Skip to content

Instantly share code, notes, and snippets.

@ggPeti

ggPeti/rule.rb

Created Oct 16, 2016
Embed
What would you like to do?
#!/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
You can’t perform that action at this time.