Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1,3 +1,8 @@
|
|||
{{omit from|Brlcad}}
|
||||
{{omit from|GUISS}}
|
||||
{{omit from|Openscad}}
|
||||
{{omit from|TPP}}
|
||||
|
||||
This puzzle is borrowed from [http://math-frolic.blogspot.co.uk/2012/08/mind-wrenching.html here].
|
||||
|
||||
Given the following twelve statements, which of them are true?
|
||||
|
|
@ -15,6 +20,8 @@ Given the following twelve statements, which of them are true?
|
|||
11. Exactly 1 of statements 7, 8 and 9 are true.
|
||||
12. Exactly 4 of the preceding statements are true.</pre>
|
||||
|
||||
When you get tired of trying to figure it out in your head, write a program to solve it, and print the correct answer or answers.
|
||||
When you get tired of trying to figure it out in your head,
|
||||
write a program to solve it, and print the correct answer or answers.
|
||||
|
||||
Extra credit: also print out a table of near misses, that is, solutions that are contradicted by only a single statement.
|
||||
Extra credit: also print out a table of near misses, that is,
|
||||
solutions that are contradicted by only a single statement.
|
||||
|
|
|
|||
4
Task/Twelve-statements/00META.yaml
Normal file
4
Task/Twelve-statements/00META.yaml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
category:
|
||||
- Constraint Handling Rules
|
||||
note: Puzzles
|
||||
44
Task/Twelve-statements/Common-Lisp/twelve-statements.lisp
Normal file
44
Task/Twelve-statements/Common-Lisp/twelve-statements.lisp
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
(defparameter *state* (make-list 12))
|
||||
|
||||
(defparameter *statements* '(t ; 1
|
||||
(= (count-true '(7 8 9 10 11 12)) 3) ; 2
|
||||
(= (count-true '(2 4 6 8 10 12)) 2) ; 3
|
||||
(or (not (p 5)) (and (p 6) (p 7))) ; 4
|
||||
(and (not (p 2)) (not (p 3)) (not (p 4))) ; 5
|
||||
(= (count-true '(1 3 5 7 9 11)) 4) ; 6
|
||||
(or (and (p 2) (not (p 3))) (and (not (p 2)) (p 3))) ; 7
|
||||
(or (not (p 7)) (and (p 5) (p 6))) ; 8
|
||||
(= (count-true '(1 2 3 4 5 6)) 3) ; 9
|
||||
(and (p 11) (p 12)) ;10
|
||||
(= (count-true '(7 8 9)) 1) ;11
|
||||
(= (count-true '(1 2 3 4 5 6 7 8 9 10 11)) 4))) ;12
|
||||
|
||||
(defun start ()
|
||||
(loop while (not (equal *state* '(t t t t t t t t t t t t)))
|
||||
do (progn (let ((true-stats (check)))
|
||||
(cond ((= true-stats 11) (result nil))
|
||||
((= true-stats 12) (result t))))
|
||||
(new-state))))
|
||||
|
||||
(defun check ()
|
||||
(loop for el in *state*
|
||||
for stat in *statements*
|
||||
counting (eq el (eval stat)) into true-stats
|
||||
finally (return true-stats)))
|
||||
|
||||
(defun count-true (lst)
|
||||
(loop for i in lst
|
||||
counting (nth (- i 1) *state*) into total
|
||||
finally (return total)))
|
||||
|
||||
(defun p (n)
|
||||
(nth (- n 1) *state*))
|
||||
|
||||
(defun new-state ()
|
||||
(let ((contr t))
|
||||
(loop for i from 0 to 11
|
||||
do (progn (setf (nth i *state*) (not (eq (nth i *state*) contr)))
|
||||
(setq contr (and contr (not (nth i *state*))))))))
|
||||
|
||||
(defun result (?)
|
||||
(format t "~:[Missed by one~;Solution:~] ~%~{~:[F~;T~] ~}~%" ? *state*))
|
||||
|
|
@ -14,7 +14,7 @@ immutable texts = [
|
|||
"exactly 1 of statements 7, 8 and 9 are true",
|
||||
"exactly 4 of the preceding statements are true"];
|
||||
|
||||
immutable pure bool function(in bool[])[12] predicates = [
|
||||
immutable pure @safe /*@nogc*/ bool function(in bool[])[12] predicates = [
|
||||
s => s.length == 12,
|
||||
s => s[$ - 6 .. $].sum == 3,
|
||||
s => s.dropOne.stride(2).sum == 2,
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
constraints = [
|
||||
->(st) { st.size == 12 },
|
||||
->(st) { st[-6,6].count(true) == 3 },
|
||||
->(st) { st.last(6).count(true) == 3 },
|
||||
->(st) { st.each_slice(2).map(&:last).count(true) == 2 },
|
||||
->(st) { st[4] ? (st[5] & st[6]) : true },
|
||||
->(st) { st[1..3].map(&:!).all? },
|
||||
->(st) { st[1..3].none? },
|
||||
->(st) { st.each_slice(2).map(&:first).count(true) == 4 },
|
||||
->(st) { st[1] ^ st[2] },
|
||||
->(st) { st[6] ? (st[4] & st[5]) : true },
|
||||
->(st) { st[0,6].count(true) == 3 },
|
||||
->(st) { st.first(6).count(true) == 3 },
|
||||
->(st) { st[10] & st[11] },
|
||||
->(st) { st[6..8].count(true) == 1 },
|
||||
->(st) { st[6..8].one? },
|
||||
->(st) { st[0,11].count(true) == 4 },
|
||||
]
|
||||
|
||||
|
|
@ -20,11 +20,10 @@ results = [true, false].repeated_permutation(12).map do |truths|
|
|||
end
|
||||
|
||||
puts "solution:",
|
||||
results.find {|r| r.consistency.all? }.truths.inspect
|
||||
results.find {|r| r.consistency.all? }.truths.to_s
|
||||
|
||||
puts "near misses: "
|
||||
puts "\nnear misses: "
|
||||
near_misses = results.select {|r| r.consistency.count(false) == 1 }
|
||||
near_misses.each do |r|
|
||||
puts "missed by statement #{r.consistency.index(false) + 1}"
|
||||
puts r.truths.inspect
|
||||
puts "missed by statement #{r.consistency.index(false) + 1}", r.truths.to_s
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue