Skip to content

Instantly share code, notes, and snippets.

@msakai
Created January 13, 2011 00:29
Show Gist options
  • Save msakai/777169 to your computer and use it in GitHub Desktop.
Save msakai/777169 to your computer and use it in GitHub Desktop.
贋金パズルのAlloyモデル
sig Coin {}
abstract sig State {
  candidates : set Coin,
}
sig Branch extends State {
  left, right : set Coin, 
  eq, lt, gt : State
}
fact {
  all b : Branch {
    not b in b.^(eq+lt+gt)
    no b.left & b.right
    #b.left = #b.right
    b.eq.candidates = b.candidates - (b.left + b.right)
    b.lt.candidates = b.candidates & b.left
    b.gt.candidates = b.candidates & b.right
  }
}
sig Leaf extends State { }
{ lone candidates }
pred solve {
  one root : State {
    root.candidates = Coin
    State in root.*(eq+lt+gt)
  } 
}
run solve for 5 int, 4 Branch, 9 Leaf,  exactly 8 Coin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment