# Swap the Sequence

Your task is to write some code that outputs an OEIS sequence, and contains the name of the sequence in the code (A______). Easy enough right? Well here's the catch, your code must also output a second separate sequence when the name of the sequence in the code is changed to the name of the second sequence.

## Input Output

Your code can be a function or complete program that takes n via a standard input method and outputs the nth term of the sequence as indexed by the provided index on the OEIS page.

You must support all values provided in the OEIS b files for that sequence, any number not in the b files need not be supported.

## Scoring

This is . Your score will be the number of bytes in your code, with less bytes being better.

## Example

Here's an example in Haskell that works for A000217 and A000290.

f x|last"A000217"=='0'=x^2|1>0=sum[1..x]


Try it online!

• To clarify: Your code should work for two sequences where putting the name of the sequence in that part of the code will output the number of that sequence? – hyper-neutrino Aug 2 '17 at 16:27
• @HyperNeutrino Yes. When the name of the sequence is substituted in it should change the function of the program to be the second sequence. – Wheat Wizard Aug 2 '17 at 16:28
• Do the sequences in the code have to have leading zeros. – pppery Aug 2 '17 at 16:31
• @ppperry Yes it should. – Wheat Wizard Aug 2 '17 at 16:31
• Is the A required? – Okx Aug 2 '17 at 16:33

## JavaScript (ES6), 16 15 bytes

n=>4&~0xA000004


Works with A000004 (all 0s) and A010709 (all 4s).

Previous 17-byte solution works with A010850 to A010859 inclusive:

n=>~-0xA010850%36


Previous 25-byte solution works with A010850 to A010871 inclusive:

n=>"A010850".slice(5)-39

• This is just showing off (I don't know OEIS well enough to see how clever this is :P) – TheLethalCoder Aug 2 '17 at 16:30
• Strange -- two answers started at 25 bytes and were both golfed to 17 bytes in a minute – pppery Aug 2 '17 at 16:33
• @ppperry Heh, but I could port your answer and it would be only 15 bytes... – Neil Aug 2 '17 at 16:36
• JS tied with Jelly?! Very nicely done – Shaggy Aug 2 '17 at 17:03
• @Shaggy Nope; a new shorter jelly answer was posted. – pppery Aug 2 '17 at 21:44

# C#, 28 bytes

n=>n*n*("A000290"[6]<49?1:n)


Works with A000290 (Squares) and A000578 (Cubes).

Try it online!

• Nice job using a non-constant sequence. – AdmBorkBork Aug 2 '17 at 18:55

f x|"A000012"!!6<'3'=1|1<2=x


The second sequence is A007953. Try it online!

# cQuents, 16 bytes

=A000007//5#|A:0


Try it online!, A000007, 1,0,0,0,0...

=A000004//5#|A:0


Try it online!, A000004, 0,0,0,0,0...

## Explanation

                    Implicit input A
=A000007            First item in the sequence equals A * 7
//5                                                 intdiv 5 = 1
#|A      n equals A
:     Mode : (sequence): output nth item (1-based)
0    Rest of the sequence is 0

                    Implicit input A
=A000004            First item in the sequence equals A * 4
//5                                                 intdiv 5 = 0
#|A      n equals A
:     Mode : (sequence): output nth item (1-based)
0    Rest of the sequence is 0


Thanks to Conor O'Brien for 4//5 = 0 and 7//5 = 1.

If the spec was more flexible, it would be O7A$ and O4A$.

# Cubix, 28 bytes

I:uU**...L..A000578@O\s<s(;?


returns the perfect cubes, a(n)=n^3.

Try it online!

On the other hand,

I:uU**...L..A068601@O\s<s(;?


returns the perfect cubes minus one, a(n)=n^3-1.

# dc, 13 bytes

Edit: Apparently OEIS lists the powers from 0th to 30th - I just did a search on these sequences and it turns out the original 13 byte solution is the golfiest. But I found another solution for just 1 byte more that works for 9 sequences.

Solution for A000012 (constant 1's sequence):

?A000012 4%^p


Try it online!

Solution for A001477 (non-negative integers):

?A001477 4%^p


Try it online!

Solution for A000290 (perfect squares sequence):

?A000290 4%^p


Try it online!

### Ungolfed/Explanation

These solutions make use of the fact that dc interprets A as 10, so A001477 becomes the value 10001477. Further it exploits that the sequences are n^0, n^1 and n^2 which coincides with 10000012 % 4 == 0, 10001477 % 4 == 1 and 10000290 % 4 == 2.

So these sequences are xyz(n) = n ^ (xyz % 4).

Command          Description          Example (3)
?              # Push the input       [3]
A000290       # Push sequence name   [3,10000290]
4%    # Top %= 4             [3,2]
^   # Pop x,y & push y^x   [9]
p  # Print the top        [9]


### 14 byte solution for 9 sequences

The idea is still the same, this time we need to do a % 97, to get the right power - it works for sequences A010801, A010802, A010803, A010804, A010805, A010806, A010807, A010808 and A010809 (these are the sequences n^13,...,n^21).

Here's the first one:

?A010801 97%^p


Try it online!

• +1 for supporting more than two sequences! – Neil Aug 3 '17 at 8:58

# Python 2, 25 17 bytes

print'A000012'[5]


Works for A000004 and A000012. (input is ignored because the sequences are all constant terms).

# Befunge 98, 10 bytes

#A000012\$q


Also works for A000004. Output by exit code.

# Jelly, 17 bytes

“A000578”OS%⁵ạ6*@


Try it online!

“A000578”OS%⁵ạ6*@  Main link
“A000578”          String
O         Codepoints
S        Sum (364 for A000290, 373 for A000578)
%⁵      Modulo 10 (4 for A000290, 3 for A000578)
ạ6    Absolute Difference with 6 (2 for A000290, 3 for A000578)
*@  [left argument] ** [result of last link (right argument)]


Also works with A000290

• Good job using non-constant sequences. – AdmBorkBork Aug 2 '17 at 19:00

# PowerShell, 23 bytes

+(0xA000012-eq160mb+18)


Try it online!

Uses A000012 (the all ones sequence) and A000004 (the all zeros sequence).

Leverages several neat tricks. We use 0x as the hexadecimal operator onto the sequence which gives us 167772178. That's compared to see if its -equal to 160mb+18 using the mb operator (160mb is 167772160). That Boolean result is then cast as an int with + to output the proper 1 or 0. Note that any sequence in the code other than A000012 will result in 0 being output.

# Neim, 10 9 bytes

A000012ᛄ>


Explanation:

A            Push 42
000012      Push 4
or
A007395     Push 7395
ᛄ     Modulo 2
>    Increment


A000012 (all ones) and A007395 (all twos)

A function that takes the input on the top of the stack and leaves the output on the top of the stack.

Try it online!

# Gaia, 9 bytes

A000012₉/


Works with A000012 and A000004.

Try A000012!

Try A000004!

### Explanation

A          Undefined (ignored)
000012    Push 12
₉   Push 9
/  Integer division, results in 1


A          Undefined (ignored)
000004    Push 4
₉   Push 9
/  Integer division, results in 0

• Why does everyone keep posting A00004 and A00012? – pppery Aug 2 '17 at 16:39
• @ppperry A000004 is the zero sequence and A000012 is the ones sequence. Simply floor divide the numbers by 9 and output the result forever. – Engineer Toast Aug 2 '17 at 20:47

# PowerShell, 12 bytes

'A000012'[5]


Try it online!

Works for A000012 (the all ones sequence) and A000004 (the all zeros sequence).

# 05AB1E, 9 bytes

A000004¨θ


Try it online!

Works for A000004 and A000012.

# Actually, 10 bytes

A000004X.⌂


Try it online!

Works for A000004 and A000012.

# Jelly, 10 bytes

6ị“A000004


Try it online!

Works for A000004 and A000012.

# Pyth, 11 bytes

@"A000004"5


Try it here.

Supports A000004 and A000012.

# Husk, 20 bytes

This one returns a bit more interesting sequences, again solutions are 1-indexed.

This works for A000040 (the prime numbers):

!!i→"A000040"e:0İfİp


Try it online!

And this one for A000045 (the Fibonacci numbers):

!!i→"A000045"e:0İfİp


Try it online!

### Explanation

This makes use of the fact that the last digit of the sequence names have a different parity:

                      -- implicit input N
e        -- construct a list with:
:0İf    --   list of Fibonacci numbers (prepend 0)
İp  --   list of the prime numbers
i→"Axxxxx?"         -- get the last character and convert to number,
!                    -- use it as modular index (0 -> primes, 5 -> Fibonacci)
!                     -- get the value at the Nth index


# AHK, 40 bytes

a:=SubStr("A000004",6)//9
Loop
Send %a%,


Output: 0,0,0,0,0,0,0,0,0,0,0,0,...

a:=SubStr("A000012",6)//9
Loop
Send %a%,


Output: 1,1,1,1,1,1,1,1,1,1,1,1,...

This might not be the shortest code but I bet it's the shortest sequence pair we can find. A000004 is the zero sequence and A000012 is the ones sequence. Simply floor divide the numbers by 9 and output the result forever.

# QBIC, 28 bytes

p=!_s@A000035,-1|!?:%2+5-p


This switches between the sequences A000034 (1, 2, 1, 2, 1 ...) and A000035 (0, 1, 0, 1, 0, 1 ...)

## Explanation

p=                  Set p to
!            !    A numeric representation of
_s         |     a substring of
@A000035      our sequence code (either A0035 or A0034)
,-1            taking just one character from the right.
?:%2                PRINT <n> MOD 2 (gives us a either 0 or 1)
+5-p            Plus 1 for seq A24 (5-4), or plus 0 for A35


# Husk, 16 bytes

Both solutions are 1-indexed.

This works for A000351 (powers of 5):

!¡*i!6"A000351"1


Try it online!

And this one for A000007 (powers of 0):

!¡*i!6"A000007"1


Try it online!

### Explanation

It makes use that the names A000351, A000007 contain the right digit D at the position 6, such that the sequence is D^0,D^1,D^2,...:

                  -- implicit input N
i!6"AxxxxDx"   -- get the right digit D and convert to number,
¡*            1  -- iterate (D*) infinitely beginning with 1,
!                 -- extract the value at Nth position


# MATL, 14 bytes

A000027 The positive integers

A000027 3\Gw-&


Try it online!

A001477 The nonnegative integers

A001477 3\Gw-&


Try it online!