Mian-Chowla sequence: Difference between revisions
Content added Content deleted
Line 1,099: | Line 1,099: | ||
Mian-Chowla terms 91-100: |
Mian-Chowla terms 91-100: |
||
22526,23291,23564,23881,24596,24768,25631,26037,26255,27219</pre> |
22526,23291,23564,23881,24596,24768,25631,26037,26255,27219</pre> |
||
=={{header|jq}}== |
|||
{{works with|jq}} |
|||
'''Works with gojq, the Go implementation of jq''' |
|||
<lang jq> |
|||
# Input: a bag-of-words (bow) |
|||
# Output: either an augmented bow, or nothing if a duplicate is found |
|||
def augment_while_unique(stream): |
|||
label $out |
|||
| foreach ((stream|tostring), null) as $word (.; |
|||
if $word == null then . |
|||
elif has($word) then break $out |
|||
else .[$word] = 1 |
|||
end; |
|||
select($word == null) ); |
|||
# For speedup, store "sums" as a hash |
|||
def mian_chowlas: |
|||
{m:[1], sums: {"1":1}} |
|||
| recurse( |
|||
.m as $m |
|||
| .sums as $sums |
|||
| first(range(1+$m[-1]; infinite) as $i |
|||
| $sums |
|||
| augment_while_unique( ($m[] | (.+$i)), (2*$i)) |
|||
| [$i, .] ) as [$i, $sums] |
|||
| {m: ($m + [$i]), $sums} ) |
|||
| .m[-1] ;</lang> |
|||
'''The Tasks''' |
|||
<lang jq>[limit(100; mian_chowlas)] |
|||
| "First thirty: \(.[:30]);", |
|||
"91st through 100th: \(.[90:])."</lang> |
|||
{{out}} |
|||
<pre> |
|||
First thirty: [1,2,4,8,13,21,31,45,66,81,97,123,148,182,204,252,290,361,401,475,565,593,662,775,822,916,970,1016,1159,1312]; |
|||
91st through 100th: [22526,23291,23564,23881,24596,24768,25631,26037,26255,27219]. |
|||
</pre> |
|||
=={{header|Julia}}== |
=={{header|Julia}}== |