[ prog / sol / mona ]

prog


LISP Puzzles

17 2020-04-06 03:38

hofseq-old code for reference:

/* hofseq.c v1.03 by FrozenVoid  */
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
//version without array: hofseq-old
uint64_t hofseq_ff(uint64_t N) {
    uint64_t R = 1, S = 2, P = 1, t = 0,Plast=0;
    for (uint64_t i = 1; i < N; i++) {
         R += S++; 
        if(Plast!=P){t = P > 1 ? hofseq_ff(P) : 3;

         }
         S += (S == t);Plast=P; P += (t < S);
     }
     return R;
}
uint64_t hofseq(uint64_t N){
    uint64_t R = 1, S = 2, P = 1, t = 0,Plast=0;
    for (uint64_t i = 1; i < N; i++) {
       printf("%lu,",R);
         R += S++; 
        if(Plast!=P){ t = P > 1 ? hofseq_ff(P) : 3;
          }
         S += (S == t);Plast=P; P += (t < S);
     }
     return R;


}

int main(int argc, char**argv) {
// Syntax: hofseq Num1 [Num2]
//if second argument, print sequence up to Num2
if(argc==3){ hofseq( strtoull(argv[2], NULL, 10));}
//print hofseq Nth number(num1)
if(argc>=2){  printf("%lu", hofseq_ff(strtoull(argv[1], NULL, 10)));}


return 0;}
157


VIP:

do not edit these