Twelve statements: Difference between revisions

Content deleted Content added
added J
Line 75: Line 75:
([0,0,0,0,1,0,0,1,0,0,1,0],[0])
([0,0,0,0,1,0,0,1,0,0,1,0],[0])
</pre>
</pre>

=={{header|J}}==
Follows the Haskell solution.

In the following 'apply' is a foreign conjunction:
<lang j> apply
128!:2

NB. example
'*:' apply 1 2 3
1 4 9</lang>
This enables us to apply strings (left argument) being verbs to the right argument, mostly a noun.
<lang j>S=: <;._2 (0 :0)
12&=@#
3=+/@:{.~&_6
2= +/@:{~&1 3 5 7 9 11
4&{=*./@:{~&4 5 6
0=+/@:{~&1 2 3
4=+/@:{~&0 2 4 6 8 10
1=+/@:{~&1 2
6&{=*./@:{~&4 5 6
3=+/@:{.~&6
2=+/@:{~&10 11
1=+/@:{~&6 7 8
4=+/@:{.~&11
)

testall=: (];"1 0<@I.@:(]~:(apply&><))"1) #:@i.@(2&^)@#</lang>

'''All true'''
<lang j> (#~0=#@{::~&_1"1) testall S
┌───────────────────────┬┐
│1 0 1 1 0 1 1 0 0 0 1 0││
└───────────────────────┴┘</lang>
'''Near misses'''
<lang j> (#~1=#@{::~&_1"1) testall S
┌───────────────────────┬──┐
│0 0 0 0 1 0 0 1 0 0 1 0│0 │
├───────────────────────┼──┤
│0 0 0 0 1 0 0 1 0 1 1 1│0 │
├───────────────────────┼──┤
│0 0 0 1 0 0 0 1 0 1 1 1│0 │
├───────────────────────┼──┤
│1 0 0 0 1 0 0 0 0 0 0 0│7 │
├───────────────────────┼──┤
│1 0 0 0 1 0 0 1 0 0 0 0│10│
├───────────────────────┼──┤
│1 0 0 0 1 0 0 1 0 0 1 0│11│
├───────────────────────┼──┤
│1 0 0 0 1 0 0 1 0 1 1 1│11│
├───────────────────────┼──┤
│1 0 0 0 1 1 0 0 1 0 1 0│7 │
├───────────────────────┼──┤
│1 0 0 1 0 0 0 0 0 0 0 0│7 │
├───────────────────────┼──┤
│1 0 0 1 0 0 0 1 0 1 1 1│11│
├───────────────────────┼──┤
│1 0 0 1 0 1 0 1 1 0 0 0│5 │
├───────────────────────┼──┤
│1 0 1 1 0 0 0 1 1 0 0 0│6 │
├───────────────────────┼──┤
│1 0 1 1 0 1 1 0 1 0 0 0│8 │
├───────────────────────┼──┤
│1 1 0 1 0 0 1 0 1 0 0 1│11│
├───────────────────────┼──┤
│1 1 0 1 0 0 1 0 1 1 0 0│9 │
├───────────────────────┼──┤
│1 1 0 1 0 0 1 1 1 0 0 0│7 │
└───────────────────────┴──┘</lang>

'''Iterative for all true'''
<lang j> (-N)&{. #: S <:@]^:((]-.@-:(apply&><)"1) (-N)&{.@#:@])^:(_) 2^N=.#S
1 0 1 1 0 1 1 0 0 0 1 0</lang>


=={{header|Perl 6}}==
=={{header|Perl 6}}==