Created
January 13, 2011 00:29
-
-
Save msakai/777169 to your computer and use it in GitHub Desktop.
贋金パズルのAlloyモデル
This file contains hidden or 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
// 失敗版 | |
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 |
This file contains hidden or 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
sig Coin {} | |
pred test[s, left, right, eq, lt, gt : set Coin] { | |
no left & right | |
#left = #right | |
eq = s - (left + right) | |
lt = s & left | |
gt = s & right | |
} | |
pred final[s : set Coin] { lone s } | |
pred solve { | |
some l, r, eq, lt, gt, | |
eq_l, eq_r, eq_eq, eq_lt, eq_gt, | |
lt_l, lt_r, lt_eq, lt_lt, lt_gt, | |
gt_l, gt_r, gt_eq, gt_lt, gt_gt | |
: set Coin { | |
test[Coin, l, r, eq, lt, gt] | |
test[eq, eq_l, eq_r, eq_eq, eq_lt, eq_gt] | |
test[lt, lt_l, lt_r, lt_eq, lt_lt, lt_gt] | |
test[gt, gt_l, gt_r, gt_eq, gt_lt, gt_gt] | |
final[eq_eq] | |
final[eq_lt] | |
final[eq_gt] | |
final[lt_eq] | |
final[lt_lt] | |
final[lt_gt] | |
final[gt_eq] | |
final[gt_lt] | |
final[gt_gt] | |
} | |
} | |
run solve for 5 int, exactly 8 Coin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment