Twelve statements: Difference between revisions
Content deleted Content added
Added Forth version |
No edit summary |
||
Line 1,208: | Line 1,208: | ||
{0,0,0,0,1,0,0,1,0,1,1,1} |
{0,0,0,0,1,0,0,1,0,1,1,1} |
||
{0,0,0,0,1,0,0,1,0,0,1,0}</pre> |
{0,0,0,0,1,0,0,1,0,0,1,0}</pre> |
||
=={{header|Perl}} |
|||
<lang perl>use List::Util 'sum'; |
|||
my @condition = ( |
|||
sub { 0 }, # dummy sub for index 0 |
|||
sub { (13==@_) ? 1 : 0 }, |
|||
sub { (3==sum @_[7..12]) ? 1 : 0 }, |
|||
sub { (2==sum @_[2,4,6,8,10,12]) ? 1 : 0 }, |
|||
sub { ($_[5]) ? (($_[6] and $_[7])?1:0) : 1 }, |
|||
sub { (!$_[2] and !$_[3] and !$_[4]) ? 1 : 0 }, |
|||
sub { (4==sum @_[1,3,5,7,9,11]) ? 1 : 0 }, |
|||
sub { ($_[2]==1-$_[3]) ? 1 : 0 }, |
|||
sub { ($_[7]) ? (($_[5] and $_[6])?1:0) : 1 }, |
|||
sub { (3==sum @_[1..6]) ? 1 : 0 }, |
|||
sub { (2==sum @_[11..12]) ? 1 : 0 }, |
|||
sub { (1==sum @_[7,8,9]) ? 1 : 0 }, |
|||
sub { (4==sum @_[1..11]) ? 1 : 0 }, |
|||
); |
|||
sub miss { |
|||
return grep { $condition[$_]->(@_) != $_[$_] ? 1 : 0 } 1..12; |
|||
} |
|||
for (0..2**12-1) { |
|||
my @truth = split //, sprintf "0%012b", $_; |
|||
my @no = miss @truth; |
|||
print "Solution: true statements are ", join( " ", grep { $truth[$_] } 1..12), "\n" if 0 == @no; |
|||
print "1 miss (",$no[0],"): true statements are ", join( " ", grep { $truth[$_] } 1..12), "\n" if 1 == @no; |
|||
} |
|||
</lang> |
|||
{{out}} |
|||
<pre>1 miss (1): true statements are 5 8 11 |
|||
1 miss (1): true statements are 5 8 10 11 12 |
|||
1 miss (1): true statements are 4 8 10 11 12 |
|||
1 miss (8): true statements are 1 5 |
|||
1 miss (11): true statements are 1 5 8 |
|||
1 miss (12): true statements are 1 5 8 11 |
|||
1 miss (12): true statements are 1 5 8 10 11 12 |
|||
1 miss (8): true statements are 1 5 6 9 11 |
|||
1 miss (8): true statements are 1 4 |
|||
1 miss (12): true statements are 1 4 8 10 11 12 |
|||
1 miss (6): true statements are 1 4 6 8 9 |
|||
1 miss (7): true statements are 1 3 4 8 9 |
|||
Solution: true statements are 1 3 4 6 7 11 |
|||
1 miss (9): true statements are 1 3 4 6 7 9 |
|||
1 miss (12): true statements are 1 2 4 7 9 12 |
|||
1 miss (10): true statements are 1 2 4 7 9 10 |
|||
1 miss (8): true statements are 1 2 4 7 8 9 |
|||
</pre> |
|||
=={{header|Perl 6}}== |
=={{header|Perl 6}}== |