29
\$\begingroup\$

The sequence A109648 starts with the following numbers

53, 51, 44, 32, 53, 49, 44, 32, 52, 52, 44, 32,
51, 50, 44, 32, 53, 51, 44, 32, 52, 57, 44, 32,
52, 52, 44, 32, 51, 50, 44, 32, 53, 50, 44, 32,
53, 50, 44, 32, 52, 52, 44, 32, 51, 50, 44, 32,
53, 49, 44, 32, 53, 48, 44, 32, 52, 52, 44, 32,
51, 50, 44, 32, 53, 51, 44, 32, 53, ...

and has the description of

Sequence is its own ASCII representation (including commas and spaces).

This is the unique sequence with the property. Your task is compute this sequence.

Standard rules and I/O methods apply. The shortest code in bytes wins.

\$\endgroup\$
4
  • \$\begingroup\$ so this works maybe? a[0] = 53; a[1] = 51; a[n_] := Switch[Mod[n, 4], 0, 48 + Floor[a[n/4]/10], 1, 48 + Mod[a[(n - 1)/4], 10], 2, 44, 3, 32]; Table[a[n], {n, 0, 68}] \$\endgroup\$
    – DialFrost
    Dec 29, 2021 at 0:04
  • 8
    \$\begingroup\$ @DialFrost is that just copied from the Mathematica entry on OEIS? \$\endgroup\$
    – pxeger
    Dec 29, 2021 at 0:05
  • 1
    \$\begingroup\$ yes it is im not posting it as an answer im asking \$\endgroup\$
    – DialFrost
    Dec 29, 2021 at 0:11
  • \$\begingroup\$ Related \$\endgroup\$
    – emanresu A
    Jan 5 at 21:56

20 Answers 20

12
+50
\$\begingroup\$

Python 2, 41 bytes

f=lambda n:ord(`map(f,n*[n/4])+[5]`[1+n])

Attempt This Online!

Thanks to @loopywalt

Uses Python's string representation of tuples to get the , parts of the sequence (44, 32).

Python 2, 42 bytes

f=lambda n:ord("5"[n:]or`f(n/4),1`[1+n%4])

Attempt This Online!

Here are some variations, but I've not been able to get any of them shorter:

f=lambda n:ord(`5*(n<1)or f(n/4),1`[1+n%4])
f=lambda n:ord(`0**n*5or f(n/4),1`[1+n%4])
f=lambda n:ord(`[5][n:]or[f(n/4)]*n`[1+n])
f=lambda n:ord(`[5]+[n and f(n/4)]*n`[1+n])
f=lambda n:ord(`0**n*-5or[f(n/4)]*n`[1+n])
f=lambda n:ord(`-~-n*"5"or[f(n/4)]*n`[1+n])
\$\endgroup\$
2
  • 4
    \$\begingroup\$ 41! Very slow, though. Times out around term 200 or so. ato.pxeger.com/… \$\endgroup\$
    – loopy walt
    Dec 30, 2021 at 1:31
  • 3
    \$\begingroup\$ @loopywalt 41 factorial is way too many bytes! \$\endgroup\$
    – pxeger
    Dec 30, 2021 at 3:55
7
\$\begingroup\$

JavaScript (Node.js), 39 bytes

f=n=>n?[...f(n>>2)+'',28,16][n%4]^48:53

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ What does the ^48 do? \$\endgroup\$
    – Jonah
    Dec 29, 2021 at 2:19
  • 3
    \$\begingroup\$ @Jonah ^ is xor operator. xor 48 so convert number to its ASCII. \$\endgroup\$
    – tsh
    Dec 29, 2021 at 2:31
  • 1
    \$\begingroup\$ More specifically, ^48 is the same as +48 which gets a number's ASCII code (since 0 is 48 and the digits increase from there), but 28^48 also gives 44 (ASCII for ,) and 16^48 gives 32 (ASCII for space) \$\endgroup\$
    – pxeger
    Dec 29, 2021 at 8:35
7
\$\begingroup\$

Wolfram Language (Mathematica), 58 57 55 48 bytes

-1 (-2) thanks to alephalpha

Nest[Rest@*ToCharacterCode@*ToString,!5,#][[#]]&

Try it online!

Returns the \$n\$th element, 1-indexed.


Wolfram Language (Mathematica), 68 bytes

If[#<1,53,Join[48+IntegerDigits@#0@⌊#/4⌋,{44,32}][[#~Mod~4+1]]]&

Try it online!

Implements the formula given on the OEIS page.

\$\endgroup\$
4
  • \$\begingroup\$ I guess we approached this in the same way... Can you make a version using the formula? \$\endgroup\$
    – ZaMoC
    Dec 29, 2021 at 0:47
  • \$\begingroup\$ what does #0 do? \$\endgroup\$
    – Jonah
    Dec 29, 2021 at 0:48
  • 1
    \$\begingroup\$ @Jonah It refers to the enclosing function. See this tips post. \$\endgroup\$
    – att
    Dec 29, 2021 at 1:10
  • 1
    \$\begingroup\$ If[#<1,{5},ToCharacterCode[ToString@#0[#-1]][[2;;#+1]]]& \$\endgroup\$
    – alephalpha
    Dec 30, 2021 at 12:07
6
\$\begingroup\$

Charcoal, 26 bytes

≔⊗⊖⊗Nθ≔5ηW‹Lηθ≔⪫Eη℅κ, η…ηθ

Try it online! Link is to verbose version of code. Outputs the first n elements, joined with comma and space. Explanation:

≔⊗⊖⊗Nθ

Calculate the length of the desired output.

≔5η

Start with the initial 5, whose ASCII code starts with itself.

W‹Lηθ

Until the string is long enough...

≔⪫Eη℅κ, η

... join its ASCII codes with comma space.

…ηθ

Output the desired number of terms.

\$\endgroup\$
6
\$\begingroup\$

Vyxal, 10 bytes

5?(‛, jC)Ẏ

Try it Online!

Outputs the first n terms, although it actually calculates the first n^3 terms.

5          # Starting with 5
 ?(     )  # input times...
   ‛, j    # Join by `, `
       C   # Get charcodes
         Ẏ # At end, get first n
\$\endgroup\$
2
  • \$\begingroup\$ Your second answer will never terminate, and therefore never print anything \$\endgroup\$
    – pxeger
    Dec 29, 2021 at 0:11
  • \$\begingroup\$ @pxeger Oh ok :( \$\endgroup\$
    – emanresu A
    Dec 29, 2021 at 0:12
4
\$\begingroup\$

Haskell + hgl, 24 bytes

q=53:tl(Or<ic", "(sh<q))

This defines q an infinite list representing the sequence.

If you want the actual string of the sequence you can do that for 1 more byte:

q=ic", "$sh<Or<('5':tl q)

Explanation

So here we define q in terms of itself.

A naive answer might look like:

q=Or<ic", "(sh<q)

Which takes q maps show across it to convert all the numbers to strings, intercalates ", " with ic, to get the string and maps Or to get the char points.

However if we define this the resulting list is just an infinite loop and never manages to produce the first element. So we need to tell it what the first element is. To do this we take what we had, chop off the first element and put the correct answer in it's place.

This allows Haskell to skip to the second element when calculating this list which it can calculate in terms of the first element just fine. And from there every successive element can be calculated just fine.

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

J, 40 37 bytes

$_2".@}.[:,0&(]', ',~"#.3":"+@u:":)&5

Try it online!

-3 thanks to Bubbler's idea of taking first n terms with $ instead of returning the nth term

Inspired by emanrasu A's answer

Yikes.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ A quick golf: ]0&(...)5: -> 0&(...)&5 \$\endgroup\$
    – Bubbler
    Dec 29, 2021 at 2:33
  • 1
    \$\begingroup\$ And change <:{ to $ to get first n terms instead of the n-th term. \$\endgroup\$
    – Bubbler
    Dec 29, 2021 at 2:39
3
\$\begingroup\$

Stax, 10 bytes

▓░δΓ╙öâ'╜Ä

Run and debug it

freezes at 10.

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

C (gcc), 76 bytes

f(n){char*s=calloc(n,8),*t=s;for(*s=53;n--;)t+=sprintf(t,"%d, ",*s++);n=*s;}

Try it online!

Inputs a \$0\$-based index \$n\$.
Returns the \$n^\text{th}\$ element.

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

R, 83 79 74 59 bytes

function(n){x=5
for(i in 1:n)x=utf8ToInt(toString(x))
x[n]}

Try it online!

Credit to Dominic van Essen for -4 bytes

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

BQN, 63 35 28 bytes

Edit: -28 and then -7 more bytes (!) thanks to Razetime

{𝕩↑{-⟜@¨∾∾⟜", "¨•Fmt¨𝕩}⍟𝕩⥊5}

Try it at BQN online REPL

Outputs first n elements of sequence for input n. But, to get this, calculates the first 4^n elements. So times-out (or crashes) on the online REPL for even moderate n.

Ungolfed, commented (try it here):

Log10 ← 10⊸⋆⁼                                        # base 10 logarithm
N2d ← Number_to_digits ← {(10⋆⌽↕⌈Log10 𝕩)(10|·⌊÷)˜𝕩} # get base 10 digits
N2s ← Number_to_string ← '0'⊸+¨ N2d                  # string representation
S2a ← String_to_ASCII ← @⊸(-˜)¨                      # ASCII codes of string

ASCII_srs ← {𝕩↑{S2a∾´(∾⟜", ")∘N2s¨𝕩}⍟𝕩 ⟨5⟩} 
                                       ⟨5⟩}  # start with ⟨5⟩,
                                    ⍟𝕩       # repeat input times:
                              N2s¨𝕩}         #  get string representations,
                    (∾⟜", ")∘               #  join ", " to each,
                  ∾´                         #  join it all together, 
              {S2a                           #  and convert to ASCII codes;
           {𝕩↑                               # finally get input elements.
\$\endgroup\$
4
  • 1
    \$\begingroup\$ @⊸(-˜)¨ -> -⊸@¨, does the same thing as ∾´. A golfier but worse way to get N2d would be '0'-˜•Fmt \$\endgroup\$
    – Razetime
    Dec 31, 2021 at 7:29
  • \$\begingroup\$ Nice! Thanks v much (x3)! \$\endgroup\$ Dec 31, 2021 at 16:07
  • 1
    \$\begingroup\$ You don't need the ˜ in . You can change (∾⟜", ")∘{•Fmt𝕩}¨ to ∾⟜", "¨•Fmt¨, and ⟨5⟩ is ⥊5 or ⋈5. \$\endgroup\$
    – Razetime
    Jan 1 at 3:35
  • 1
    \$\begingroup\$ @Razetime - Thanks again (very belatedly). I didn't update this at the time because I didn't understand it well enough then, and subsequently forgot about it... \$\endgroup\$ May 2 at 13:17
2
\$\begingroup\$

Ruby, 40 bytes

->n{a=*5
n.times{a=(a*", ").bytes}
a[n]}

Try it online!

a lambda that returns the n-th element

\$\endgroup\$
1
\$\begingroup\$

Wolfram Language (Mathematica), 83 bytes

a@1={53};a[n_]:=a[n]=Join[a[n-1],ToCharacterCode@StringTake[ToString@a[n-1],{n+1}]]

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Perl 5 + -pa, 42 bytes

$_=53;$_.=", ".ord+(/./g)[++$;]while"@F">$

Try it online!

Explanation

Naiive approach, builds the string from 53 and appends the ordinal values. 0-indexed, prints up to the nth term.

Uses $; to store the counter to save a byte at the end from the -p flag.

\$\endgroup\$
1
\$\begingroup\$

Pari/GP, 49 bytes

f(n)=if(n,Vec(Vecsmall(Str(f(n-1)))[2..n+1]),[5])

Try it online!

1-indexed. Based on the PARI/GP code on the OEIS page.

\$\endgroup\$
1
\$\begingroup\$

Japt, 15 bytes

@Zq,ú2)cY}h#5ìL

Try it

\$\endgroup\$
1
\$\begingroup\$

Excel VBA, 69 50 bytes

Saved 19 bytes thanks to a total re-write by Taylor Raine

?"53";:t=3:Do:k=", "&Asc(t):t=Mid(t &k,2):?k;:Loop

The function is typed directly into the immediate window and output is in the same window. It will run until it's stopped (ESC) or it hits a software / hardware limitation like running out memory.

Colons are line line breaks in VBA. Here's a version with some nicer formatting and comments.

?"53";                 ' Print "53" without a line break at the end
t = 3                  ' Seed the value for t
Do                     ' Start a loop
   k = ", " & Asc(t)   ' Store the ASCII value for the first character in t
   t = Mid(t & k, 2)   ' Set t be everything in t & k except the first character
   ?k;                 ' Print the value of k without a line break at the end
Loop                   ' Go back to "Do"
\$\endgroup\$
1
  • 1
    \$\begingroup\$ You can get this down to 50 bytes by rearranging and converting to an immediate window function that outputs to VBE immediate window - ?"53";:t=3:Do:k=", "&Asc(t):t=Mid(t &k,2):?k;:Loop \$\endgroup\$ Jan 7 at 16:31
0
\$\begingroup\$

APL+WIN, 60 bytes

Prompts for required term number. Index origin = 0

i←0⋄s←53 51 44 32⋄⍎∊(n←⎕)⍴⊂'s←s,(⎕av⍳⍕s[i←i+1]),44 32⋄'⋄s[n]

TIO examples generate the first column of the tabular form of the series as depicted in the question.

Try it online! Thanks to Dyalog Classic

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

Husk, 17 bytes

↑¹!¡ȯmcJ", "ms;53

Try it online!


Husk, 16 bytes

↑¹!¡ȯJ", "mosc"5

With output as character string (ASCII values represent sequence A109648)

Try it online!

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

05AB1E, 9 bytes

5Δ„, ýÇI£

Outputs the first \$n\$ results.

Try it online.

Explanation:

5          # Start with a 5
 Δ         # Loop until the result no longer changes:
  „, ý     #  Join with ", " delimiter
      Ç    #  Convert it to a list of its codepoint integers
       I£  #  Only leave the first input amount of values
           # (after the loop, the resulting list is output implicitly)
\$\endgroup\$

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.