11
\$\begingroup\$

The task here is to write a program that takes an natural number, \$n\$, and produces the \$n\$th term of an OEIS sequence. That sequence should have an identifier in the form of A followed by 6 digits. Now when you take your source code and reverse the order of it's bytes to produce a new program, that program should also implement an OEIS sequence. The new sequence should be identified by an A followed by the same 6 digits as last time but in reverse order (including leading zeros).

Now to keep things from being trivial neither the OEIS identifier number nor your program can be palindromes. That is the sequences and programs should be different. You cannot choose a sequence for which it's reverse does not exist or is empty.

For each of your sequences you may choose to either use 0 or 1 indexing. They do not have to use the same indexing. Since some OEIS sequences have a limited domain you need only output the correct numbers for the domain of the sequence. Your required behavior is undefined outside of the domain (you can output 0, crash, order a pizza, etc.).

This is so answers will be scored in bytes with fewer bytes being better.

\$\endgroup\$
  • \$\begingroup\$ Do leading zeroes get included in the sequence number reversing? \$\endgroup\$ – pppery Jul 11 at 0:15
  • 1
    \$\begingroup\$ @pppery They have to be, since OEIS numbers have exactly 6 digits. (it also explicitly says so in the question) \$\endgroup\$ – Jo King Jul 11 at 0:17
  • \$\begingroup\$ Can we take the input (index) as a string? \$\endgroup\$ – TFeld Jul 11 at 7:50
10
\$\begingroup\$

05AB1E, 9 4 bytes (A000040 and A040000)

Ø=>≠

Try it online!

!enilno ti yrT

Explanation:

Ø          # nth prime
 =         # output
  >≠       # ignored

:noitanalpxE

≠          # boolean negation (0 if n == 1, 1 otherwise)
 >         # increment
  =        # output
   Ø       # ignored
\$\endgroup\$
4
\$\begingroup\$

Perl 6, 55 bytes (A055642 and A246550)

+*.comb#}]1-_$[)4+_$^**X]_$^[)*..2,emirp-si&(perg(tros{

Try it online!

This is a anonymous Whatever lambda implementing the OEIS sequence A055642 (length of the decimal representation of \$n\$) 0-indexed.

{sort(grep(&is-prime,2..*)[^$_]X**^$_+4)[$_-1]}#bmoc.*+

Try it online!

The reverse is the sequence A246550 (the ordered list of \$x^e\$ where \$x\$ is prime and \$e \ge 4\$) 1-indexed.

Most of this challenge was just finding a good sequence with a not too complicated reverse.

Update: Using torcado's answer, this can be 19 bytes (A010851 and A158010)

{256*$_**2-$_}#{21}

Try it online!

\$\endgroup\$
2
\$\begingroup\$

\/\/>, 15 14 bytes (A010851 and A158010)

cn;n*-1*"Ā":j

effectively cn, output 12

j:"Ā"*1-*n;nc

effectively j:"Ā"*1-*n, n(256n-1)

thanks to a friend for finding incredibly simple sequences!

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

Haskell, 47 bytes (A000010 and A010000)

Both sequences are relatively simple.

p n=sum[1|x<-[1..n],gcd x n<2]--2+n*n=n p;1=0 p

Try it online!

p n = the Euler totient function of n (A000010) (1-indexed)

Reversed:

p 0=1;p n=n*n+2--]2<n x dcg,]n..1[-<x|1[mus=n p

Try it online!

p n = 1 if n = 0, otherwise n^2 + 2

It would be interesting to see an answer which doesn't use comments...

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

Python 2, 59 bytes (A030000 and A000030)

f=lambda n,k=0:k if`n`in`2**k`else f(n,k+1)#]0[`n`:n adbmal

Try it online!

Defines a function f, returning the nth term of A030000 (smallest nonnegative number \$k\$ such that the decimal expansion of \$2^k\$ contains the string \$n\$), 0-indexed

lambda n:`n`[0]#)1+k,n(f esle`k**2`ni`n`fi k:0=k,n adbmal=f

Try it online!

An anonymous function returning the nth term of A000030 (Initial digit of \$n\$), 0-indexed


Shorter version, which takes strings as input (for both sequences), and both still 0-indexed:

Python 2, 56 bytes

f=lambda n,k=0:`k`*(n in`2**k`)or f(n,k+1)#]0[n:n adbmal

Try it online!

lambda n:n[0]#)1+k,n(f ro)`k**2`ni n(*`k`:0=k,n adbmal=f

Try it online!

\$\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.