/* Simultaneous_pleasure in Picat. From https://enigmaticcode.wordpress.com/2021/12/04/puzzle-142-simultaneous-pleasure/ """ Puzzle #142: Simultaneous pleasure From New Scientist #3363, 4th December 2021 :-) :-) :-) + :-( :-( = 22 (3 happy faces + 2 sad faces = 22) :-) :-) + :-( :-( :-( = 23 (2 happy faces + 3 sad faces = 23) During lockdowns, I researched viral internet maths sensations. Several of them are what a teenager might recognise as simultaneous equations. In the emoji example above, smiley faces = 4 and blown minds = 5. Simultaneous equations without emojis are less likely to go viral, but can be more fun. Here are two of my favourites. 1. A pen and a pencil cost £1 together. The pen costs 90p more than the pencil. How much do they each cost? 2. There are some cows and some chickens in a field. I can see 40 eyes and 64 legs. How many are there of each animal? """ This model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. % 1. A pen and a pencil cost £1 together. The pen costs 90p more than the pencil. % How much do they each cost? % go ?=> Pen :: 0..100, Pencil :: 0..100, Pen + Pencil #= 100, Pen #= Pencil + 90, solve([Pen,Pencil]), println([pen=Pen,pencil=Pencil]), fail, nl. go => true. % % 2. There are some cows and some chickens in a field. I can see 40 eyes and 64 legs. % How many are there of each animal? % go2 ?=> Cows :: 0..100, Chickens :: 0..100, Cows * 2 + Chickens * 2 #= 40, % 40 eyes Cows * 4 + Chickens * 2 #= 64, % 64 legs % solve([Cows,Chickens]), println([cows=Cows,chickens=Chickens]), nl, fail, nl. go2 => true. % % :-) :-) :-) + :-( :-( = 22 (3 happy faces + 2 sad faces = 22) % :-) :-) + :-( :-( :-( = 23 (2 happy faces + 3 sad faces = 23) % go3 ?=> Happy :: 0..23, Sad :: 0..23, 3 * Happy + 2 * Sad #= 22, 2 * Happy + 3 * Sad #= 23, % solve([Happy,Sad]), println([happy=Happy,sad=Sad]), nl, fail, nl. go3 => true.