How to resolve the algorithm Klarner-Rado sequence step by step in the 11l programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Klarner-Rado sequence step by step in the 11l programming language

Table of Contents

Problem Statement

Klarner-Rado sequences are a class of similar sequences that were studied by the mathematicians David Klarner and Richard Rado. The most well known is defined as the thinnest strictly ascending sequence K which starts 1, then, for each element n, it will also contain somewhere in the sequence, 2 × n + 1 and 3 × n + 1.

So, the sequence K starts with 1. Set n equal to the first element 1; the sequence will also contain 2 × n + 1 and 3 × n + 1, or 3 and 4. Set n equal to the next element: 3, somewhere in the sequence it will contain 2 × n + 1 and 3 × n + 1, or 7 and 10. Continue setting n equal to each element in turn to add to the sequence.

Preferably without needing to find an over abundance and sorting.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Klarner-Rado sequence step by step in the 11l programming language

Source code in the 11l programming language

F klarner_rado(n)
   V K = [1]
   L(i) 0 .< n
      V j = K[i]
      V (firstadd, secondadd) = (2 * j + 1, 3 * j + 1)
      I firstadd < K.last
         L(pos) (K.len - 1 .< 1).step(-1)
            I K[pos] < firstadd & firstadd < K[pos + 1]
               K.insert(pos + 1, firstadd)
               L.break
      E I firstadd > K.last
         K.append(firstadd)
      I secondadd < K.last
         L(pos) (K.len - 1 .< 1).step(-1)
            I K[pos] < secondadd & secondadd < K[pos + 1]
               K.insert(pos + 1, secondadd)
               L.break
      E I secondadd > K.last
         K.append(secondadd)

   R K

V kr1m = klarner_rado(100'000)

print(‘First 100 Klarner-Rado sequence numbers:’)
L(v) kr1m[0.<100]
   print(f:‘ {v:3}’, end' I (L.index + 1) % 20 == 0 {"\n"} E ‘’)
L(n) [1000, 10'000, 100'000]
   print(f:‘The {commatize(n)}th Klarner-Rado number is {commatize(kr1m[n - 1])}’)

  

You may also check:How to resolve the algorithm A+B step by step in the FBSL programming language
You may also check:How to resolve the algorithm Erdös-Selfridge categorization of primes step by step in the Factor programming language
You may also check:How to resolve the algorithm Largest int from concatenated ints step by step in the Rust programming language
You may also check:How to resolve the algorithm Shortest common supersequence step by step in the Mathematica/Wolfram Language programming language
You may also check:How to resolve the algorithm Catalan numbers step by step in the Mathematica / Wolfram Language programming language