107
\$\begingroup\$

As of 13/03/2018 16:45 UTC, the winner is answer #345, by Khuldraeseth na'Barya. This means the contest is officially over, but feel free to continue posting answers, just so long as they follow the rules.

As well, just a quick shout out to the top three answerers in terms of numbers of answers:

1. NieDzejkob - 41 answers

2. KSmarts - 30 answers

3. Hyper Neutrino - 26 answers


This is an answer chaining question that uses sequences from OEIS, and the length of the previous submission.

This answer chaining question will work in the following way:

  • I will post the first answer. All other solutions must stem from that.
  • The next user (let's call them userA) will find the OEIS sequence in which its index number (see below) is the same as the length of my code.
  • Using the sequence, they must then code, in an unused language, a program that takes an integer as input, n, and outputs the nth number in that sequence.
  • Next, they post their solution after mine, and a new user (userB) must repeat the same thing.

The nth term of a sequence is the term n times after the first, working with the first value being the first value given on its OEIS page. In this question, we will use 0-indexing for these sequences. For example, with A000242 and n = 3, the correct result would be 25.

However!

This is not a , so shortest code doesn't matter. But the length of your code does still have an impact. To prevent the duplication of sequences, your bytecount must be unique. This means that no other program submitted here can be the same length in bytes as yours.

If there isn't a sequence for then length of the last post, then the sequence for your post is the lowest unused sequence. This means that the sequences used also have to be unique, and that the sequence cannot be the same as your bytecount.

After an answer has been posted and no new answers have been posted for more than a week, the answer before the last posted (the one who didn't break the chain) will win.

Input and Output

Generic input and output rules apply. Input must be an integer or a string representation of an integer and output must be the correct value in the sequence.

Formatting

As with most questions, please format your answer like this

# N. language, length, [sequence](link)

`code`

[next sequence](link)

*anything else*

Rules

  • You must wait for at least 1 hour before posting an answer, after having posted.
  • You may not post twice (or more) in a row.
  • The index number of a sequence is the number after the A part, and with leading zeros removed (e.g. for A000040 the index number is 40)
  • You can assume that neither the input nor the required output will be outside your languages numerical range, but please don't abuse this by choosing a language that can only use the number 1, for example.
  • If the length of your submission is greater than 65536 characters long, please provide a link to a way to access the code (pastebin for example).
  • n will never be larger than 1000, or be out of bounds for the sequence, simply to prevent accuracy discrepancies from stopping a language from competing.
  • Every 150 (valid) answers, the number of times a language may be used increases. So after 150 solutions have been posted, every language may be used twice (with all previous answers counting towards this). For instance, when 150 answers have been posted, Python 3 may be used twice, but due to the fact that it has already been used once, this means it can only be used once more until 300 answers have been posted.
  • Please be helpful and post a link to the next sequence to be used. This isn't required, but is a recommendation.
  • Different versions of languages, e.g. Python 2 and Python 3 are different languages. As a general rule, if the different versions are both available on Try It Online, they are different languages, but keep in mind that this is a general rule and not a rigid answer.
  • It is not banned, but please try not to copy the code from the OEIS page, and actually try to solve it.
  • Hardcoding is only allowed if the sequence is finite. Please note that the answer that prompted this (#40) is the exception to the rule. A few answers early in the chain hardcode, but these can be ignored, as there is no good in deleting the chain up to, say, #100.

Answer chain snippet

var QUESTION_ID=133754,OVERRIDE_USER=66833;function shareUrl(i){return"https://codegolf.stackexchange.com/a/"+i}function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getTemplate(s){return jQuery(jQuery("#answer-template").html().replace("{{PLACE}}",s.index+".").replace("{{NAME}}",s.user).replace("{{LANGUAGE}}",s.language).replace("{{SEQUENCE}}",s.sequence).replace("{{SIZE}}",s.size).replace("{{LINK}}",s.link))}function search(l,q){m=jQuery("<tbody id='answers'></tbody>");e.forEach(function(s){if(!q||(l==0&&RegExp('^'+q,'i').exec(s.lang_name))||(l==1&&q===''+s.size)){m.append(jQuery(getTemplate(s)))}});jQuery("#answers").remove();jQuery(".answer-list").append(m)}function sortby(ix){t=document.querySelector('#answers');_els=t.querySelectorAll('tr');els=[];for(var i=0;i<_els.length;i++){els.push(_els[i]);}els.sortBy(function(a){a=a.cells[ix].innerText;return ix==0||ix==4?Number(a):a.toLowerCase()});for(var i=0;i<els.length;i++)t.appendChild(els[i]);}function checkSize(x){if(!x)return jQuery("#size-used").text("");var i=b.indexOf(+x);if(i<0)return jQuery("#size-used").text("Available!");var low=+x,high=+x;while(~b.indexOf(low))low--;while(~b.indexOf(high))high++;jQuery("#size-used").text(("Not available. The nearest are "+low+" and "+high).replace("are 0 and","is"))}function checkLang(x){}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.answer_id;answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return (e.owner.user_id==OVERRIDE_USER?"<span id='question-author'>"+e.owner.display_name+"</span>":e.owner.display_name)}function process(){b=[];c=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);if(a){e.push({user:getAuthorName(s),size:+a[4],language:a[2],lang_name:a[3],index:+a[1],sequence:a[5],link:shareUrl(s.answer_id)});if(b.indexOf(+a[4])>=0&&c.indexOf(+a[4])<0){c.push(+a[4])};b.push(+a[4])}else{jQuery('#weird-answers').append('<a href="'+shareUrl(s.answer_id)+'">This answer</a> is not formatted correctly. <b>Do not trust the information provided by this snippet until this message disappears.</b><br />')}}),e.sortBy(function(e){return e.index});e.forEach(function(e){jQuery("#answers").append(getTemplate(e))});var q="A"+("000000"+e.slice(-1)[0].size).slice(-6);jQuery("#next").html("<a href='http://oeis.org/"+q+"'>"+q+"</a>");c.forEach(function(n){jQuery('#weird-answers').append('The bytecount '+n+' was used more than once!<br />')})}Array.prototype.sortBy=function(f){return this.sort(function(a,b){if(f)a=f(a),b=f(b);return(a>b)-(a<b)})};var ANSWER_FILTER="!*RB.h_b*K(IAWbmRBLe",COMMENT_FILTER="!owfmI7e3fd9oB",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page,e=[];getAnswers();var SCORE_REG=/<h\d>\s*(\d+)\.\s*((?:<a [^>]+>\s*)?((?:[^\n,](?!<\/a>))*[^\s,])(?:<\/a>)?),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*, ((?:<a[^>]+>\s*)?A\d+(?:\s*<\/a>)?)\s*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important;font-family:Roboto,sans-serif}#answer-list,#language-list{padding:10px;/*width:290px*/;float:left;display:flex;flex-wrap:wrap;list-style:none;}table thead{font-weight:700}table td{padding:5px}ul{margin:0px}#board{display:flex;flex-direction:column;}#language-list li{padding:2px 5px;}#langs-tit{margin-bottom:5px}#byte-counts{display:block;margin-left:15px;}#question-author{color:purple;text-shadow: 0 0 15px rgba(128,0,128,0.1);}#label-info{font-weight: normal;font-size: 14px;font-style: italic;color: dimgray;padding-left: 10px;vertical-align: middle; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"><p id="weird-answers"></p><p>Currently waiting on <span id="next"></span></p><span>Search by Byte Count: <input id="search" type="number" min=1 oninput="checkSize(this.value);search(1,this.value)" onclick="document.getElementById('search2').value='';!this.value&&search(0,'')"/> <span id="size-used"></span></span><br><span>Search by Language: <input id="search2" oninput="checkLang(this.value);search(0,this.value)" onclick="document.getElementById('search').value='';!this.value&&search(0,'')"/> <span id="language-used"></span></span><h2>Answer chain <span id="label-info">click a label to sort by column</span></h2><table class="answer-list"><thead><tr><td  onclick="sortby(0)">#</td><td onclick="sortby(1)">Author</td><td onclick="sortby(2)">Language</td><td onclick="sortby(3)">Sequence</td><td onclick="sortby(4)">Size</td></tr></thead><tbody id="answers"></tbody></table><table style="display: none"><tbody id="answer-template"><tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SEQUENCE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody></table><table style="display: none"><tbody id="language-template"><tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SEQUENCE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody></table>

\$\endgroup\$
13
  • \$\begingroup\$ Comments are not for extended discussion; this conversation has been moved to chat. \$\endgroup\$
    – Dennis
    Oct 31, 2017 at 2:49
  • \$\begingroup\$ Is it OK if a program would need a better floating-point accuracy for the builtin float/double type in order to produce values for larger n? \$\endgroup\$
    – Maya
    Nov 21, 2017 at 15:15
  • 1
    \$\begingroup\$ @Giuseppe No, as you're generating the numbers by doing the maths, rather than just placing them into an array/string \$\endgroup\$ Dec 15, 2017 at 22:14
  • 2
    \$\begingroup\$ @cairdcoinheringaahing In my opinion that's hardcoding the gamma constant. It doesn't work "in theory" for larger numbers. \$\endgroup\$
    – DELETE_ME
    Dec 22, 2017 at 12:44
  • 6
    \$\begingroup\$ Chat room \$\endgroup\$
    – DELETE_ME
    Dec 22, 2017 at 12:45

387 Answers 387

1
3 4
5
6 7
13
4
\$\begingroup\$

124. ArnoldC, 796 bytes, A000278

IT'S SHOWTIME

HEY CHRISTMAS TREE input
YOU SET US UP @I LIED
HEY CHRISTMAS TREE result
YOU SET US UP @I LIED
HEY CHRISTMAS TREE x
YOU SET US UP @I LIED
HEY CHRISTMAS TREE y
YOU SET US UP @NO PROBLEMO
HEY CHRISTMAS TREE temp1
YOU SET US UP @I LIED

GET YOUR ASS TO MARS input
DO IT NOW
I WANT TO ASK YOU A BUNCH OF QUESTIONS AND I WANT TO HAVE THEM ANSWERED IMMEDIATELY

STICK AROUND input

GET TO THE CHOPPER temp1
HERE IS MY INVITATION x
ENOUGH TALK

GET TO THE CHOPPER x
HERE IS MY INVITATION x
GET UP y
ENOUGH TALK

GET TO THE CHOPPER y
HERE IS MY INVITATION temp1
YOU'RE FIRED temp1
ENOUGH TALK

GET TO THE CHOPPER input
HERE IS MY INVITATION input
GET DOWN 1
ENOUGH TALK

CHILL

GET TO THE CHOPPER result
HERE IS MY INVITATION x
ENOUGH TALK

TALK TO THE HAND result
YOU HAVE BEEN TERMINATED

Try it Online!

Next Sequence

\$\endgroup\$
6
  • 1
    \$\begingroup\$ useful for the next person, perhaps? \$\endgroup\$
    – Giuseppe
    Sep 1, 2017 at 15:16
  • \$\begingroup\$ I WANT TO ASK YOU A BUNCH OF QUESTIONS AND I WANT TO HAVE THEM ANSWERED IMMEDIATELY: How does this work? \$\endgroup\$
    – Maya
    Sep 1, 2017 at 15:16
  • \$\begingroup\$ @NieDzejkob GET YOUR ASS TO MARS assigns a variable from a method call, DO IT NOW calls the method, and I WANT TO ASK YOU A BUNCH OF QUESTIONS AND I WANT TO HAVE THEM ANSWERED IMMEDIATELY reads an integer input. \$\endgroup\$
    – KSmarts
    Sep 1, 2017 at 15:33
  • \$\begingroup\$ @Giuseppe Of course, lots of math software have built-ins for arbitrary precision pi, too. \$\endgroup\$
    – KSmarts
    Sep 1, 2017 at 15:35
  • \$\begingroup\$ @KSmarts sure, but I'm having trouble picking one that hasn't been used yet, so I provided that link as at least one example of a "roll your own" algorithm \$\endgroup\$
    – Giuseppe
    Sep 1, 2017 at 15:36
4
\$\begingroup\$

309. Haskell, 699 bytes, A003025

import Control.Monad
import Data.List

-- (n, es) has n nodes; es is a list of (i,j) where 1 <= i < j <= n.
type Dag = (Int, [(Int, Int)])

both f (a,b) = (f a, f b)
powerset = filterM (const [True, False])

-- All dags with n nodes.
dags :: Int -> [Dag]
dags n = map ((,) n) $ powerset [(i,j) | i <- [1..n], j <- [i+1..n]]

-- Is there only one node with no exits?
ok :: Dag -> Bool
ok (n, es) = not $ any (\i -> not $ any ((==i) . fst) es) [1..n-1]

-- All ways to relabel the given dag.
rewrites :: Dag -> [Dag]
rewrites (n, es) = [(n, sort $ map (both ((p!!) . pred)) es) | p <- permutations [1..n]]

-- A003025
f :: Int -> Integer
f = genericLength . nub . concatMap rewrites . filter ok . dags

Try it online!

Enumerates the n-node labeled acyclic digraphs with 1 out-point.

print (f 5) produces the correct output (16885) after 20 seconds when compiled with -O3.

Next sequence

\$\endgroup\$
4
\$\begingroup\$

311. ALGOL 68 (Genie), 334 bytes, A000148

BEGIN
  LONG LONG INT n   := read int + 2;
  LONG LONG INT r   := 0;
  LONG LONG REAL ma := ( n / 2.0 ) ** 1.5;
  LONG LONG REAL x  := 2.0 / 3;
  INT a             := 1;
  WHILE a <= ma DO
    INT b := a;
    WHILE a ** x + b ** x <= n DO
      r := r + 1;
      b := b + 1
    OD;
    a := a + 1
  OD;
  print ( whole ( r , 0 ) )
END

Next Sequence

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ C (gcc) is allowed right now (2018-01-09), right? \$\endgroup\$ Jan 9, 2018 at 18:46
  • \$\begingroup\$ @Blacksilver looks like it, it's only been used twice so far. \$\endgroup\$
    – Giuseppe
    Jan 9, 2018 at 18:55
4
\$\begingroup\$

314. M, 4166 bytes, A000146

I hope I didn’t accidentally add any bytes outside of the M code page in the code.

The actual source code is the markdown source of this post. To prevent infinite recursion, the source can be found here.

Try it online! (with anti-infinite-recursion)

Next sequence!

Explanation

® ÆD ‘ ÆPÐf İ           ḷ“   First link. Calculate Sum_{(p-1)|2n} 1/p, with
                             the value of 2n stored in the register.
® ÆD                         All divisors of 2n (possible values of (p-1).
     ‘                  ḷ“   Increment. Get all possible values of (p).
       ÆPÐf                  Filter, keep only prime values.
            İ                Inverse.       ”
-* ×c@ × *®¥            ḷ“   Second (dyadic) link. Given v and k, calculate
                             (-1)^v * (k choose v) * v^m / (k+1). (m = 2*n),
                             a term from the closed-form formula.
-                            Literal -1.
 *                           Power. Current value = (-1)^v.
   ×c@                       Multiply (×) by the combination (c) with swapped (@)
                             arguments applied on k and v.
       × *®¥                 Multiply by the value of dyad applied on v...
         *                     Raise to power...
          ®                    register value (currently have value m = 2n)   ”
‘ Ḥ© 0r µ0r ç€ ÷‘µ€ ;-£ FS ḷ“ Main link.
‘                          ḷ“ Increment.
  Ḥ©                          Unhalve (double) the value, and store to register.
     0r                       Generate range from 0.
        µ........µ€           For each value (k),
         0r                     generate range from 0 (values (v)),
            ç€                  apply previous range for each element,
               ÷‘          ḷ“   and divide by (k+1).
                    ;-£       Concatenate the resulting list with the value of
                                the first link. x£ is "call link index x as a
                                nilad, excluding the main link, and wrap around".
                       FS     Flatten, and sum.         ”
\$\endgroup\$
8
  • \$\begingroup\$ Another bignum sequence... this one is easy enough, please don't use Hy. (or another-Python-variant) \$\endgroup\$
    – DELETE_ME
    Jan 17, 2018 at 8:13
  • 1
    \$\begingroup\$ I think you should edit in an explanation of how the polyglot works ;) \$\endgroup\$
    – Maya
    Jan 17, 2018 at 14:06
  • \$\begingroup\$ This answer broke the snippet, but I will nudge the regex used to make it work. \$\endgroup\$
    – Maya
    Jan 17, 2018 at 14:30
  • \$\begingroup\$ Is M just an early version/precursor of Jelly? \$\endgroup\$
    – dylnan
    Jan 17, 2018 at 21:34
  • 1
    \$\begingroup\$ @dylnan Numerical inaccuracy. This also works (adding ceiling will make the difference more explicit). \$\endgroup\$
    – DELETE_ME
    Jan 18, 2018 at 4:13
4
\$\begingroup\$

315. Befunge-98 (PyFunge), 147 bytes, A004166

very simple :)
>"HTRF"4(1&>:!#v_1v <-- this loop here
  @.$<--out^\*3 \-< <-- calculates 3^n
 >;#_^#:/a\+%aO<\;#z<-- and here the digits are summed

Try it online!

Next sequence!

\$\endgroup\$
4
  • \$\begingroup\$ dagnabbit, I had a snobol solution all ready, I was just testing it :( here it is, looks like it's correct. \$\endgroup\$
    – Giuseppe
    Jan 17, 2018 at 15:45
  • \$\begingroup\$ @Giuseppe well, I got ninjad on the previous sequence - I was working on a Trefunge solution and I had the Bernoulli numbers working, I just had to add the reciprocals of prime divisors. \$\endgroup\$
    – Maya
    Jan 17, 2018 at 16:13
  • \$\begingroup\$ Again, a trailing newline is necessary. So v = ... \$\endgroup\$
    – DELETE_ME
    Jan 18, 2018 at 4:17
  • \$\begingroup\$ Looks like I have to post the next answer. 38 hours left. \$\endgroup\$
    – DELETE_ME
    Jan 23, 2018 at 1:38
4
\$\begingroup\$

332. tinylisp, 852 bytes, A000766

(d in (q ((x xs) (i (e x (h xs)) 1 (i xs (in x (t xs)) 0

(d vec (q ((x y z) (c x (c y (c z (
(d + (q ((x y) (i x (c (a (h x) (h y)) (+ (t x) (t y))) (

(d map (q ((f xs) (i xs (c (f (h xs)) (map f (t xs))) (

(d sub (q ((exp pat rep) (i (e exp pat) rep (i (e (type exp) (q List)) (i exp (c (sub (h exp) pat rep) (sub (t exp) pat rep)) ()) exp
(d qt (q ((x) (c (q q) (c x (

(d - (s 0 1
(d adj (c (vec 1 1 0) (c (vec - 1 0) (c (vec 1 - 0) (c (vec - - 0) (c (vec 1 0 1) (c (vec - 0 1) (c (vec 1 0 -) (c (vec - 0 -) (c (vec 0 1 1) (c (vec 0 - 1) (c (vec 0 1 -) (c (vec 0 - -) (

(d sum (q ((ls) (i ls (a (h ls) (sum (t ls))) 0

(d sol (q ((ve pre n) (i (in ve pre) 0 (i n (sum (map (sub (sub (sub (q ((aj) (sol (+ VEC aj) PRE N))) (q VEC) (qt ve)) (q PRE) (qt (c ve pre))) (q N) (qt (s n 1))) adj)) (e (h ve) 1

(d main (q ((x) (sol (vec 0 0 0) () (a 1 x

Try it online!

Next sequence! Intentionally chosen to be easy. (somewhat weird, too)

... It was (not) fun learning this language.

Defines a function main which calculates the required function. tinylisp doesn't support reading from standard input.

Brute force approach. That's why it's terribly slow.


... There is library to load? In an esoteric language? Surprise!

\$\endgroup\$
2
  • \$\begingroup\$ No line has a trailing ). \$\endgroup\$
    – DELETE_ME
    Feb 10, 2018 at 15:25
  • \$\begingroup\$ Hey, thanks for using my language. :) Sorry your learning experience was painful... If you have suggestions on how I can make tinylisp more approachable, I'd love to hear them! (Chat room here) \$\endgroup\$
    – DLosc
    Feb 10, 2018 at 19:03
4
\$\begingroup\$

364. Wenyan (文言), 2534 bytes, A001669

吾有一術。名之曰「開方本源圖」。欲行是術。必先得一數。曰「甲」。乃行是術曰。
 批曰。「「西人謂之曰「巴斯噶三角」者是也。」」
 吾有一列。名之曰「層」。充「層」以一。
 為是「甲」遍。
  吾有一列。名之曰「下層」。
  吾有一數。曰零。名之曰「上廉」。
  凡「層」中之「廉」。
   加「廉」以「上廉」。名之曰「下廉」。充「下層」以「下廉」。
   昔之「上廉」者。今「廉」是矣。
  云云。
  充「下層」以一。
  昔之「層」者。今「下層」是矣。
 云云。
 乃得「層」。
是謂「開方本源圖」之術也。

吾有一術。名之曰「指數」。欲行是術。必先得一列。曰「天」。乃行是術曰。
 批曰。「「形式冪級數之指數者也。不計其常數項。」」
 夫「天」之長。名之曰「階」。
 吾有一列。名之曰「地」。
 吾有一數。曰零。名之曰「甲」。
 為是「階」遍。
  若「甲」等於零者。
   充「地」以一。
  若非。
   減「甲」以一。施「開方本源圖」於其。名之曰「開方本源」。
   吾有一數。曰零。名之曰「乙」。
   吾有一數。曰零。名之曰「和」。
   凡「開方本源」中之「廉」。
    減「甲」以「乙」。加其以一。名之曰「丙」。
    加一於「乙」。昔之「乙」者。今其是矣。
    夫「地」之「乙」。名之曰「項」。
    夫「天」之「丙」。乘其以「項」。乘其以「廉」。
    加其於「和」。昔之「和」者。今其是矣。
   云云。
   充「地」以「和」。
  云云。
  加一於「甲」。昔之「甲」者。今其是矣。
 云云。
 乃得「地」。
是謂「指數」之術也。

吾有一術。名之曰「序列零零壹陸陸玖」。欲行是術。必先得一數。曰「甲」。乃行是術曰。
 批曰。「「OEIS之序列A001669者是也。」」
 加一於「甲」。昔之「甲」者。今其是矣。
 吾有一列。名之曰「天」。為是「甲」遍。充「天」以一也。
 為是六遍。
  施「指數」於「天」。昔之「天」者。今其是矣。
 云云。
 夫「天」之「甲」。名之曰「乙」。
 乃得「乙」。
是謂「序列零零壹陸陸玖」之術也。

Next sequence!

Time to write some Classical Chinese.

You can try it on this Online IDE. Add the following snippets to the end to print the first 20 terms. Uncheck "Print Hanzi" in the settings to show the results in Arabic numerals.

吾有一數。曰零。名之曰「甲」。
為是二十遍。
 施「序列零零壹陸陸玖」於「甲」。書之。
 加一於「甲」。昔之「甲」者。今其是矣。
云云。
\$\endgroup\$
3
\$\begingroup\$

48. SOGL, 3 bytes, A000194

.√Ρ

Next sequence

\$\endgroup\$
2
  • \$\begingroup\$ @cairdcoinheringaahing There's no way I can't solve it in 2 days \$\endgroup\$
    – Leaky Nun
    Jul 22, 2017 at 14:20
  • \$\begingroup\$ @cairdcoinheringaahing you don't need to worry about not solving it until a couple days have passed :P \$\endgroup\$
    – Stephen
    Jul 22, 2017 at 14:37
3
\$\begingroup\$

53. Coffeescript, 34 bytes, A000484

alert Math.round Math.cos prompt()

Try it online!

Next sequence

\$\endgroup\$
3
  • \$\begingroup\$ @StepHen The next one is super easy too \$\endgroup\$
    – BlackCap
    Jul 22, 2017 at 16:26
  • \$\begingroup\$ Man, the next one is so easy, too bad I can't post yet... This would be ....I2%:)O@ in Cubix (could be shorter but 9 and 10 are already taken) \$\endgroup\$ Jul 22, 2017 at 16:26
  • \$\begingroup\$ @BlackCap yup I got it in :P \$\endgroup\$
    – Stephen
    Jul 22, 2017 at 16:28
3
\$\begingroup\$

54. C# (.NET Core), 196 bytes, A000034

using System;
namespace A000008
{
    class Program
    {
        static void Main(string[] args)
        {
           Console.WriteLine(1 + Int32.Parse(Console.ReadLine()) % 2);
        }
    }
}

Try it online!

Next Sequence

\$\endgroup\$
1
  • \$\begingroup\$ lol the next one literally has a builtin in Jelly xD \$\endgroup\$
    – hyper-neutrino
    Jul 22, 2017 at 16:32
3
\$\begingroup\$

60. Oasis, 5 + 2 = 7 bytes, A000059

+2 bytes for the N and o flags.

Code:

x4m>p

Try it online!

Explanation:

x      # Double the number
 4m    # Raise to the power of 4
   >   # Add one
    p  # Check for primality

Used with the following flags:

  • N: Find the Nth number that satisfies each line of code
  • o: Shift the sequence by 1 (N = N + 1).

Next sequence

\$\endgroup\$
1
  • \$\begingroup\$ Can't believe that we haven't had A7 \$\endgroup\$
    – Leaky Nun
    Jul 22, 2017 at 20:00
3
\$\begingroup\$

61. √ å ı ¥ ® Ï Ø ¿, 5 bytes, A000007

I0^o 

Next sequence

\$\endgroup\$
0
3
\$\begingroup\$

64. LiveScript, 152 bytes, A000108

f = (n) ->
  ns = [1]
  for i from 0 to n-1
    ns.push 0
    s = 0
    for k from 0 to ns.length-1
      s += ns[k]
      ns[k] =  s
  ns[ns.length-1]

Try it online!

Next sequence

\$\endgroup\$
7
  • \$\begingroup\$ Great, I don't even understand how 2 becomes 32 in this one \$\endgroup\$ Jul 22, 2017 at 23:21
  • \$\begingroup\$ @ETHproductions Would you rather have had A151? \$\endgroup\$
    – BlackCap
    Jul 22, 2017 at 23:22
  • \$\begingroup\$ ...no, sorry to complain :P You could have golfed it though \$\endgroup\$ Jul 22, 2017 at 23:29
  • \$\begingroup\$ Oh, it's 0-indexed. That makes more sense I suppose \$\endgroup\$ Jul 22, 2017 at 23:33
  • 1
    \$\begingroup\$ @WheatWizard You have to account for -1s as well though, hence why 1 is 32 as opposed to 16. \$\endgroup\$ Jul 22, 2017 at 23:57
3
\$\begingroup\$

65. Fortran (GFortran), 371 bytes, A000152

function A000152(n)
	integer :: n, i, a, sum, index, A000152
	integer, dimension(n+1) :: gf
	gf(1) = 1
	do i=2,n+1
		gf(i) = 0
	end do
	do a=1,16
		do i=n+1,2,-1
			sum = 0
			index = 1
			do while (index * index < i)
				sum = sum + 2 * gf(i - index * index)
				index = index + 1
			end do
			gf(i) = gf(i) + sum
		end do
	end do
	A000152 = gf(n+1)
end function A000152

Try it online!

Next sequence

How it works

It uses the following gf:

(sum(m=[-infty,infty], x^(m^2)))^16
\$\endgroup\$
3
\$\begingroup\$

66. Yacas, 43 bytes, A000371

f(n):=Sum(k,0,n,(-1)^(n-k)*Bin(n,k)*2^2^k);

Try it online!

Next sequence

\$\endgroup\$
3
\$\begingroup\$

56. Pony, 138 bytes, A000041

fun f(n: U64, q: U64 = 1): U64 =>
  if n>0 then
    if n>=q then
      f(n-q, q)+f(n,q+1)
    else
      0
    end
  else
    1
  end //a

Try it online! (Thank you for adding Pony Dennis!)

Next sequence

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Try this: playground.ponylang.org \$\endgroup\$
    – Stephen
    Jul 22, 2017 at 17:58
  • 1
    \$\begingroup\$ I add most languages by request. Assuming this is one, I'll look into Pony. \$\endgroup\$
    – Dennis
    Jul 22, 2017 at 18:05
  • \$\begingroup\$ @StepHen Thanks, that worked. \$\endgroup\$
    – BlackCap
    Jul 22, 2017 at 18:11
  • \$\begingroup\$ @Dennis Thank you, I appreciate that \$\endgroup\$
    – BlackCap
    Jul 22, 2017 at 18:59
  • 3
    \$\begingroup\$ One Pony, as requested. In the future, if you find a language you'd like to see added to TIO, please don't hesitate to leave me a message in talk.tryitonline.net. \$\endgroup\$
    – Dennis
    Jul 23, 2017 at 5:44
3
\$\begingroup\$

70. Elm, 1134 bytes, A000333

import Html exposing (text)

f n s = let l = takeWhile (\x -> (s + sqrt (toFloat x)) <= n) (List.range 1 (floor (n*n)))
        in List.map (\x -> [x]) l 
        ++ (List.concatMap (\x -> List.map (\y -> x::y) ( f n (s+sqrt (toFloat x)) )) l)

t n = List.length(List.map List.head(group(List.sort(List.map List.sort(f(n+1)0)))))

main = text (toString (List.length (t 5)))


takeWhile : (a -> Bool) -> List a -> List a
takeWhile predicate list =
  case list of
    []      -> []
    x::xs   -> if (predicate x) then x :: takeWhile predicate xs
              else []

dropWhile : (a -> Bool) -> List a -> List a
dropWhile predicate list =
  case list of
    []      -> []
    x::xs   -> if (predicate x) then dropWhile predicate xs
              else list

span : (a -> Bool) -> List a -> (List a, List a)
span p xs = (takeWhile p xs, dropWhile p xs)

groupBy : (a -> a -> Bool) -> List a -> List (List a)
groupBy eq zs =
  case zs of
    [] -> []
    (x::xs) -> let (ys,zs) = span (eq x) xs
              in (x::ys)::groupBy eq zs

group : List a -> List (List a)
group = groupBy (==)

This is much prettier in Haskell, but it has been used.


Try it online!

Next sequence

\$\endgroup\$
1
  • \$\begingroup\$ but it has been used. by you :P \$\endgroup\$
    – Stephen
    Jul 23, 2017 at 20:35
3
\$\begingroup\$

71. F# (Mono), 401 bytes, A001134

That was quite an experience, using a language I've never tried before which is based on a bunch of programming paradigms I've never experienced before...

let isprime p =
  let mutable q = 2
  while q * q < p && p % q > 0 do
    q <- q + 1
  p >= 2 && q * q > p

let isA001134 p =
  let mutable i = 1
  let mutable g = 2
  while g <> 1 do
    g <- g * 2 % p
    i <- i + 1
  i * 4 = p - 1 && isprime p

let A001134 n =
  let mutable q = n
  let mutable result = 113
  while q > 0 do
    result <- result + 4
    if isA001134 result then q <- q - 1
  result

Try it online!

Next sequence

\$\endgroup\$
3
\$\begingroup\$

77. Braingolf, 51 bytes, A004147

m32&gM9784&gM7571840&gM11140566368&gMvvcv1+[R<v]v_;

Try it online!

Next sequence

\$\endgroup\$
2
  • \$\begingroup\$ According to this answer, the number of 5-state Turing machines which halt is 32. :p And then it just keeps cycling through the same four numbers \$\endgroup\$ Jul 24, 2017 at 16:49
  • \$\begingroup\$ @PeterOlson actually according to this answer the number of 4-state halting machines is 32, but it's irrelevant because the numbers are incomputable, and unknown beyond n=3 \$\endgroup\$
    – Mayube
    Jul 24, 2017 at 18:11
3
\$\begingroup\$

78. anyfix, 12 bytes, A000051

        2«*‘

Try it online!

Next Sequence

Note: TIO says 15 bytes but that's because I haven't asked Dennis to configure Anyfix to use the Jelly codepage yet.

\$\endgroup\$
3
\$\begingroup\$

79. Commentator, 13 bytes, A000012

 */          

Try it online!

Next Sequence

A space increments the accumulator and */ outputs it as a number. As the program has outputted, the spaces at the end are essentially no-ops.

\$\endgroup\$
3
\$\begingroup\$

87. Neim, 16 bytes, A000040

>𝐋1𝕗><><><><><><

Output is wrapped in braces []. Yes, those are random filler bytes (that increment and decrement continuously), but I like to think of them as fish having fun with code.

Try it online!

Next sequence.

\$\endgroup\$
3
  • 2
    \$\begingroup\$ i don't know, I think it looks like a fish double date ><><>< ><><>< \$\endgroup\$
    – BlackCap
    Jul 25, 2017 at 14:49
  • \$\begingroup\$ You can replace 1𝕗 (get last 1 elements) with 𝐠 (get greatest element) if you want output without braces. Also, you can use Q as a filler (terminate program) or a space character. \$\endgroup\$
    – Okx
    Jul 26, 2017 at 11:41
  • \$\begingroup\$ @Okx Why do you want no fish dates? \$\endgroup\$
    – Maya
    Sep 5, 2017 at 5:24
3
\$\begingroup\$

90. Open Shading Language (OSL), 66 bytes, A000201

shader abc(int i=1, output float o=1){o=floor(i*((1+sqrt(5))/2));}

Next Sequence

\$\endgroup\$
0
3
\$\begingroup\$

40. Rust, 3416 bytes, A000001

The rules seem to imply hardcoding the first 1001 cases is fine.

EDIT: I’m editing this post to give some commenters the chance to adjust their vote on it.

static COUNT: [i32; 1001] =
[0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2,
1, 15, 2, 2, 5, 4, 1, 4, 1, 51, 1, 2, 1, 14, 1, 2, 2, 14, 1, 6, 1, 4,
2, 2, 1, 52, 2, 5, 1, 5, 1, 15, 2, 13, 2, 2, 1, 13, 1, 2, 4, 267, 1,
4, 1, 5, 1, 4, 1, 50, 1, 2, 3, 4, 1, 6, 1, 52, 15, 2, 1, 15, 1, 2, 1,
12, 1, 10, 1, 4, 2, 2, 1, 231, 1, 5, 2, 16, 1, 4, 1, 14, 2, 2, 1, 45,
1, 6, 2, 43, 1, 6, 1, 5, 4, 2, 1, 47, 2, 2, 1, 4, 5, 16, 1, 2328, 2,
4, 1, 10, 1, 2, 5, 15, 1, 4, 1, 11, 1, 2, 1, 197, 1, 2, 6, 5, 1, 13,
1, 12, 2, 4, 2, 18, 1, 2, 1, 238, 1, 55, 1, 5, 2, 2, 1, 57, 2, 4, 5,
4, 1, 4, 2, 42, 1, 2, 1, 37, 1, 4, 2, 12, 1, 6, 1, 4, 13, 4, 1, 1543,
1, 2, 2, 12, 1, 10, 1, 52, 2, 2, 2, 12, 2, 2, 2, 51, 1, 12, 1, 5, 1,
2, 1, 177, 1, 2, 2, 15, 1, 6, 1, 197, 6, 2, 1, 15, 1, 4, 2, 14, 1,
16, 1, 4, 2, 4, 1, 208, 1, 5, 67, 5, 2, 4, 1, 12, 1, 15, 1, 46, 2, 2,
1, 56092, 1, 6, 1, 15, 2, 2, 1, 39, 1, 4, 1, 4, 1, 30, 1, 54, 5, 2,
4, 10, 1, 2, 4, 40, 1, 4, 1, 4, 2, 4, 1, 1045, 2, 4, 2, 5, 1, 23, 1,
14, 5, 2, 1, 49, 2, 2, 1, 42, 2, 10, 1, 9, 2, 6, 1, 61, 1, 2, 4, 4,
1, 4, 1, 1640, 1, 4, 1, 176, 2, 2, 2, 15, 1, 12, 1, 4, 5, 2, 1, 228,
1, 5, 1, 15, 1, 18, 5, 12, 1, 2, 1, 12, 1, 10, 14, 195, 1, 4, 2, 5,
2, 2, 1, 162, 2, 2, 3, 11, 1, 6, 1, 42, 2, 4, 1, 15, 1, 4, 7, 12, 1,
60, 1, 11, 2, 2, 1, 20169, 2, 2, 4, 5, 1, 12, 1, 44, 1, 2, 1, 30, 1,
2, 5, 221, 1, 6, 1, 5, 16, 6, 1, 46, 1, 6, 1, 4, 1, 10, 1, 235, 2, 4,
1, 41, 1, 2, 2, 14, 2, 4, 1, 4, 2, 4, 1, 775, 1, 4, 1, 5, 1, 6, 1,
51, 13, 4, 1, 18, 1, 2, 1, 1396, 1, 34, 1, 5, 2, 2, 1, 54, 1, 2, 5,
11, 1, 12, 1, 51, 4, 2, 1, 55, 1, 4, 2, 12, 1, 6, 2, 11, 2, 2, 1,
1213, 1, 2, 2, 12, 1, 261, 1, 14, 2, 10, 1, 12, 1, 4, 4, 42, 2, 4, 1,
56, 1, 2, 1, 202, 2, 6, 6, 4, 1, 8, 1, 10494213, 15, 2, 1, 15, 1, 4,
1, 49, 1, 10, 1, 4, 6, 2, 1, 170, 2, 4, 2, 9, 1, 4, 1, 12, 1, 2, 2,
119, 1, 2, 2, 246, 1, 24, 1, 5, 4, 16, 1, 39, 1, 2, 2, 4, 1, 16, 1,
180, 1, 2, 1, 10, 1, 2, 49, 12, 1, 12, 1, 11, 1, 4, 2, 8681, 1, 5, 2,
15, 1, 6, 1, 15, 4, 2, 1, 66, 1, 4, 1, 51, 1, 30, 1, 5, 2, 4, 1, 205,
1, 6, 4, 4, 7, 4, 1, 195, 3, 6, 1, 36, 1, 2, 2, 35, 1, 6, 1, 15, 5,
2, 1, 260, 15, 2, 2, 5, 1, 32, 1, 12, 2, 2, 1, 12, 2, 4, 2, 21541, 1,
4, 1, 9, 2, 4, 1, 757, 1, 10, 5, 4, 1, 6, 2, 53, 5, 4, 1, 40, 1, 2,
2, 12, 1, 18, 1, 4, 2, 4, 1, 1280, 1, 2, 17, 16, 1, 4, 1, 53, 1, 4,
1, 51, 1, 15, 2, 42, 2, 8, 1, 5, 4, 2, 1, 44, 1, 2, 1, 36, 1, 62, 1,
1387, 1, 2, 1, 10, 1, 6, 4, 15, 1, 12, 2, 4, 1, 2, 1, 840, 1, 5, 2,
5, 2, 13, 1, 40, 504, 4, 1, 18, 1, 2, 6, 195, 2, 10, 1, 15, 5, 4, 1,
54, 1, 2, 2, 11, 1, 39, 1, 42, 1, 4, 2, 189, 1, 2, 2, 39, 1, 6, 1, 4,
2, 2, 1, 1090235, 1, 12, 1, 5, 1, 16, 4, 15, 5, 2, 1, 53, 1, 4, 5,
172, 1, 4, 1, 5, 1, 4, 2, 137, 1, 2, 1, 4, 1, 24, 1, 1211, 2, 2, 1,
15, 1, 4, 1, 14, 1, 113, 1, 16, 2, 4, 1, 205, 1, 2, 11, 20, 1, 4, 1,
12, 5, 4, 1, 30, 1, 4, 2, 1630, 2, 6, 1, 9, 13, 2, 1, 186, 2, 2, 1,
4, 2, 10, 2, 51, 2, 10, 1, 10, 1, 4, 5, 12, 1, 12, 1, 11, 2, 2, 1,
4725, 1, 2, 3, 9, 1, 8, 1, 14, 4, 4, 5, 18, 1, 2, 1, 221, 1, 68, 1,
15, 1, 2, 1, 61, 2, 4, 15, 4, 1, 4, 1, 19349, 2, 2, 1, 150, 1, 4, 7,
15, 2, 6, 1, 4, 2, 8, 1, 222, 1, 2, 4, 5, 1, 30, 1, 39, 2, 2, 1, 34,
2, 2, 4, 235, 1, 18, 2, 5, 1, 2, 2, 222, 1, 4, 2, 11, 1, 6, 1, 42,
13, 4, 1, 15, 1, 10, 1, 42, 1, 10, 2, 4, 1, 2, 1, 11394, 2, 4, 2, 5,
1, 12, 1, 42, 2, 4, 1, 900, 1, 2, 6, 51, 1, 6, 2, 34, 5, 2, 1, 46, 1,
4, 2, 11, 1, 30, 1, 196, 2, 6, 1,10,1,2,15,199];

fn count(i: usize) -> i32 { COUNT[i] }

Try it online!

Next sequence.

\$\endgroup\$
6
  • 16
    \$\begingroup\$ Hardcoding in a language as dedicated to computation as rust... you earned my downvote. \$\endgroup\$
    – Leaky Nun
    Jul 22, 2017 at 11:22
  • 2
    \$\begingroup\$ "Voting up a question or answer signals to the rest of the community that a post is interesting, well-researched, and useful, while voting down a post signals the opposite: that the post contains wrong information, is poorly researched, or fails to communicate information." I wouldn't necessarily upvote this because hardcoding isn't interesting but I don't think it deserves downvotes just because it isn't a creative solution \$\endgroup\$
    – Poke
    Jul 28, 2017 at 18:32
  • 6
    \$\begingroup\$ Note that counting finite groups of order n is a highly non-trivial problem, and any serious attempt to write an answer here that isn’t O(silly(n)) would take hours/days of coding, and get beaten to it by some bullshit Mathematica-oid that has a built-in for it, which, surprise, absolutely would cache the first 1001 cases too. \$\endgroup\$
    – Lynn
    Jul 28, 2017 at 18:55
  • \$\begingroup\$ Well then, seeing your point I will reverse my downvote, but apparently I can't un-downvote until this post is edited again. \$\endgroup\$
    – user41805
    Jul 28, 2017 at 19:35
  • \$\begingroup\$ I see your point with that, and though I don't like having languages being "wasted" to downvotes, I do see your point with the built-ins. If you edit the post I'll revert my downvote. \$\endgroup\$
    – hyper-neutrino
    Jul 30, 2017 at 0:10
3
\$\begingroup\$

93. Clojure, 35 bytes, A000093

#(Math/floor (Math/sqrt (* % % %)))

Try it online!

Next Sequence

\$\endgroup\$
3
\$\begingroup\$

98. Befunge-98 (PyFunge), 153 bytes, A001772

&v >1 >1+:00g\%kvv>1\>1-\2*\:kvv
 #   vw\-1g00: < >$v ^       < $
>0p^ >$01g1-:01v> #> > 1+vv-1*b<
^>1+01p         ^ ^:     <>0
               >p  k^.@zz

Try it online! The two zs after the @ are nop's that never get executed but I added in the make the bytecount correspond to an easier sequence. Becuase of what I think is a quirk of the interpreter and the fact that TIO doesn't provide a trailing newline, input needs to be given with a trailing space.

Next sequence

\$\endgroup\$
0
3
\$\begingroup\$

100. Pyke, 20 bytes, A000030

Yaay, the 100th answer! 0-indexed.

                  `h

Try it online!

Next Sequence.

\$\endgroup\$
3
  • \$\begingroup\$ @StepHen EDIT Sorry, fixing \$\endgroup\$
    – Mr. Xcoder
    Aug 11, 2017 at 19:27
  • \$\begingroup\$ @StepHen How is this 1-indexed? Inputting 0 gives 0 as it should \$\endgroup\$ Aug 11, 2017 at 19:27
  • \$\begingroup\$ @StepHen Fixed, haha \$\endgroup\$
    – Mr. Xcoder
    Aug 11, 2017 at 19:28
3
\$\begingroup\$

110. Nim, 442 bytes, A000081

from strutils import parseint
import math

proc A000081(index: int): int =
 if index <= 0: return 0
 elif index <= 2: return 1
 elif index == 3: return 2
 elif index == 4: return 4
 else:
  var n: int = index - 1
  result = 0
  for k in 1..n:
   var t: int = 0
   for d in 1..k:
    if gcd(d,k)==d:
     t = t + (d * A000081(d))
   result = result + t*A000081(n-k+1)
  result = int(result / n)
 return

echo A000081(parseint(readline(stdin)))

Try it online!

Next sequence

\$\endgroup\$
3
\$\begingroup\$

113. Arcyóu, 228 bytes, A000049

(: grp (F(d) d))
(: q (# (q)))
(: t (? q (] 
 (r * (* (_ 2 3) q))) 2))
(: a 0)
(f x (_ 1 t) (grp
 (: b 0)
 (f y (_ t) (grp
  (f z (_ t) (grp
   (? (= (+ (* 3 (* y y)) (* 4 (* z z))) x) (: b 1) 1)
  ))
 ))
 (: a (+ a b))
))
(p a)

This is slow for terms past about the fifth, but Arcyóu is implemented in Python, which does support arbitrary precision numbers. Try it online!

Next sequence (let's try some geometry ...)

\$\endgroup\$
9
  • 3
    \$\begingroup\$ The next one ought to be done in Hexagony. \$\endgroup\$
    – KSmarts
    Aug 16, 2017 at 15:41
  • 2
    \$\begingroup\$ why do you keep doing hard next-sequences ;_; xD \$\endgroup\$
    – hyper-neutrino
    Aug 16, 2017 at 20:09
  • 1
    \$\begingroup\$ Because I think this challenge is progressing too fast. Actually, this is only my second hard sequence, and the first one was accidental; I didn't realize it was going to be hard. \$\endgroup\$ Aug 16, 2017 at 21:18
  • 3
    \$\begingroup\$ I managed to decypher the name, I believe. It's about thr number of different "tetrominoes" with n pieces, but on a hexagonal grid. Read Polyhex on Wikipedia. \$\endgroup\$
    – Maya
    Aug 17, 2017 at 1:58
  • 2
    \$\begingroup\$ @NieDzejkob Your link was 404 \$\endgroup\$
    – hyper-neutrino
    Aug 17, 2017 at 15:26
3
\$\begingroup\$

122. MIT/GNU Scheme, 2057 bytes, A000525

So I'm implementing A000081 again...

(define (add f g)
  (stream-map + f g) )

(define (scale c f)
  (stream-map (lambda (v) (* c v)) f) )

(define (adddiag sf)
  (let ((f0 (stream-first sf)))
    (cons-stream (stream-first f0)
         (add (stream-rest f0) (adddiag (stream-rest sf))) ) ) )

(define (mult f g)
  (adddiag (stream-map (lambda (v) (scale v g)) f)) )

(define (prependzeros n f)
  (if (= 0 n) f (cons-stream 0 (prependzeros (-1+ n) f))) )

(define (intersperse f n)
  (cons-stream (stream-first f)
           (prependzeros n (intersperse (stream-rest f) n)) ) )

(define (iterate fun init)
  (cons-stream init (iterate fun (fun init))) )

(define (from n)
  (cons-stream n (from (1+ n))) )

(define (scanl fun init s)
  (cons-stream init (scanl fun (fun init (stream-first s)) (stream-rest s))) )

(define (expx f)
  (cons-stream 1
           (adddiag (stream-map (lambda (s g) (scale (/ 1 s) g))
                    (scanl * 1 (from 2))
                    (iterate (lambda (g) (mult f g)) f) )) ) )

(define (eu f)
  (expx (adddiag (stream-map (lambda (n) (scale (/ 1 n)
                                                (intersperse f (-1+ n)) ))
                             (from 1) ))) )

(define gf000081s (cons-stream 1 (stream-rest (eu gf000081s))))

(define gf000081 (cons-stream 0 gf000081s))

(define (recip1 f)
  (let ((msf (scale -1 (stream-rest f))))
    (cons-stream 1 (adddiag (iterate (lambda (g) (mult msf g)) msf))) ) )

(define (div1 f g)
  (mult f (recip1 g)) )

(define (pow7 f)
  (let* ((p2 (mult f f))
         (p4 (mult p2 p2))
         (p6 (mult p4 p2)) )
    (mult p6 f) ) )

(define (addconst c f)
  (cons-stream (+ c (stream-first f))
               (stream-rest f) ) )

(define gf
  (let* ((p2 (mult gf000081 gf000081))
         (p3 (mult p2 gf000081))
         (p4 (mult p3 gf000081)) )
    (div1 (mult p4 (addconst 64
                             (add (add (scale -79 gf000081)
                                       (scale  36 p2) )
                                  (scale -6 p3) ) ))
          (pow7 (addconst 1 (scale -1 gf000081))) ) ) )

(define (f n) (stream-ref gf (+ 4 n)))

In debian, MIT/GNU Scheme is in the package mit-scheme.

Here's how to use it when the program is in a file ps.scm:

$ scheme --load ps.scm
MIT/GNU Scheme running under GNU/Linux
[...]
1 ]=> (f 20)

;Value: 90039381031273

Next sequence

\$\endgroup\$
2
  • \$\begingroup\$ Man, I wanted to do this one. I mean, I implemented A000081 first... \$\endgroup\$
    – KSmarts
    Sep 1, 2017 at 15:38
  • \$\begingroup\$ Sorry, I thought I had waited long enough... \$\endgroup\$ Sep 1, 2017 at 16:46
1
3 4
5
6 7
13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.