Skip to content

Instantly share code, notes, and snippets.

@mark
Created December 7, 2013 04:44
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 mark/7837397 to your computer and use it in GitHub Desktop.
Save mark/7837397 to your computer and use it in GitHub Desktop.
Priority/n generator
def priority(n)
WireMind::Circuits::Circuit.new.tap do |priority|
# I/O
inputs = (1..n).map { |idx| priority.input("input#{idx}") }
outputs = (1..n).map { |idx| priority.output("output#{idx}") }
# Nodes
nones = (1...n).map { |idx| priority.node("none") }
alls = (2..n ).map { |idx| priority.node("all") }
# Connections
outputs[0] << inputs[0]
nones.each_with_index { |none, idx| none << inputs[idx] }
alls.each_with_index do |all, idx|
all << nones[0,idx+1] + inputs[idx+1,1]
outputs[idx+1] << all
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment