How to resolve the algorithm Twelve statements step by step in the Clojure programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Twelve statements step by step in the Clojure programming language

Table of Contents

Problem Statement

This puzzle is borrowed from   math-frolic.blogspot.

Given the following twelve statements, which of them are true?

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.

Print out a table of near misses, that is, solutions that are contradicted by only a single statement.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Twelve statements step by step in the Clojure programming language

Source code in the clojure programming language

(use '[clojure.math.combinatorics]

(defn xor? [& args]
  (odd? (count (filter identity args))))

(defn twelve-statements []
  (for [[a b c d e f g h i j k l] (selections [true false] 12)
    :when (true? a)
    :when (if (= 3 (count (filter true? [g h i j k l]))) (true? b) (false? b))
    :when (if (= 2 (count (filter true? [b d f h j l]))) (true? c) (false? c))
    :when (if (or (false? e) (every? true? [e f g])) (true? d) (false? d))
    :when (if (every? false? [b c d]) (true? e) (false? e))
    :when (if (= 4 (count (filter true? [a c e g i k]))) (true? f) (false? f))
    :when (if (xor? (true? b) (true? c)) (true? g) (false? g))
    :when (if (or (false? g) (every? true? [e f g])) (true? h) (false? h))
    :when (if (= 3 (count (filter true? [a b c d e f]))) (true? i) (false? i))
    :when (if (every? true? [k l]) (true? j) (false? j))
    :when (if (= 1 (count (filter true? [g h i]))) (true? k) (false? k))
    :when (if (= 4 (count (filter true? [a b c d e f g h i j k]))) (true? l) (false? l))]
  [a b c d e f g h i j k l]))


  

You may also check:How to resolve the algorithm MAC vendor lookup step by step in the Rust programming language
You may also check:How to resolve the algorithm The Twelve Days of Christmas step by step in the Prolog programming language
You may also check:How to resolve the algorithm Factorial step by step in the Acornsoft Lisp programming language
You may also check:How to resolve the algorithm Play recorded sounds step by step in the Julia programming language
You may also check:How to resolve the algorithm Hash from two arrays step by step in the NetRexx programming language