Non-continuous subsequences: Difference between revisions
Content added Content deleted
(Added Quackery.) |
|||
Line 2,117: | Line 2,117: | ||
n = 10 if len(argv) < 2 else int(argv[1]) |
n = 10 if len(argv) < 2 else int(argv[1]) |
||
print len( ncsub(range(1, n)) )</lang> |
print len( ncsub(range(1, n)) )</lang> |
||
=={{header|Quackery}}== |
|||
A sequence of n items has 2^n possible subsequences, including the empty sequence. These correspond to the numbers 0 to 2^n-1, where a one in the binary expansion of the number indicates inclusion in the subsequence of the corresponding item in the sequence. Non-continuous subsequences correspond to numbers where the binary expansion of the number has a one, followed by one or more zeroes, followed by a one. |
|||
<lang Quackery> [ dup 1 & dip [ 1 >> ] ] is 2/mod ( n --> n n ) |
|||
[ 0 swap |
|||
[ dup 0 != while |
|||
2/mod iff |
|||
[ dip 1+ ] done |
|||
again ] |
|||
[ dup 0 != while |
|||
2/mod not iff |
|||
[ dip 1+ ] done |
|||
again ] |
|||
[ dup 0 != while |
|||
2/mod iff |
|||
[ dip 1+ ] done |
|||
again ] |
|||
drop 3 = ] is noncontinuous ( n --> b ) |
|||
[ [] unrot |
|||
[ dup 0 != while |
|||
dip behead tuck |
|||
1 & iff |
|||
[ nested dip rot |
|||
join unrot ] |
|||
else drop |
|||
1 >> again ] |
|||
2drop ] is bitems ( [ n --> [ ) |
|||
[ [] swap |
|||
dup size bit times |
|||
[ i^ noncontinuous if |
|||
[ dup i^ bitems |
|||
nested rot |
|||
join swap ] ] |
|||
drop ] is ncsubs ( [ --> [ ) |
|||
' [ 1 2 3 4 ] ncsubs echo cr |
|||
$ "quackery" ncsubs 72 wrap$</lang> |
|||
{{out}} |
|||
<pre>[ [ 1 3 4 ] [ 1 2 4 ] [ 2 4 ] [ 1 4 ] [ 1 3 ] ] |
|||
qackery quckery uckery qckery quakery uakery qakery akery qukery ukery |
|||
qkery quacery uacery qacery acery qucery ucery qcery cery quaery uaery |
|||
qaery aery query uery qery quackry uackry qackry ackry quckry uckry |
|||
qckry ckry quakry uakry qakry akry qukry ukry qkry kry quacry uacry |
|||
qacry acry qucry ucry qcry cry quary uary qary ary qury ury qry quackey |
|||
uackey qackey ackey quckey uckey qckey ckey quakey uakey qakey akey |
|||
qukey ukey qkey key quacey uacey qacey acey qucey ucey qcey cey quaey |
|||
uaey qaey aey quey uey qey ey quacky uacky qacky acky qucky ucky qcky |
|||
cky quaky uaky qaky aky quky uky qky ky quacy uacy qacy acy qucy ucy qcy |
|||
cy quay uay qay ay quy uy qy qacker qucker ucker qcker quaker uaker |
|||
qaker aker quker uker qker quacer uacer qacer acer qucer ucer qcer cer |
|||
quaer uaer qaer aer quer uer qer quackr uackr qackr ackr quckr uckr qckr |
|||
ckr quakr uakr qakr akr qukr ukr qkr kr quacr uacr qacr acr qucr ucr qcr |
|||
cr quar uar qar ar qur ur qr qacke qucke ucke qcke quake uake qake ake |
|||
quke uke qke quace uace qace ace quce uce qce ce quae uae qae ae que ue |
|||
qe qack quck uck qck quak uak qak ak quk uk qk qac quc uc qc qa |
|||
</pre> |
|||
=={{header|R}}== |
=={{header|R}}== |