# Concatenating n with n + 1

## Introduction

OEIS sequence A127421 is the sequence of numbers whose decimal expansion is a concatenation of 2 consecutive increasing non-negative numbers. Put simply, every number in the sequence is formed by putting together n with n+1 for some non-negative, integer value of n. The first several terms are:

1, 12, 23, 34, 45, 56, 67, 78, 89, 910, 1011, 1112, 1213, 1314, 1415, 1516, 1617, 1718, 1819, 1920, 2021, 2122, 2223, 2324, 2425, 2526, 2627, 2728, 2829, 2930, 3031, 3132, 3233, 3334, 3435, 3536, 3637, 3738, 3839, 3940, 4041, 4142, 4243, 4344, 4445, 4546, …

## Challenge

Given a single positive integer n, print the first n entries of OEIS sequence A127421 in increasing order.

• Input and output can be in any acceptable format. Strings or numbers are fine for output.
• Leading zeroes are not permitted.
• Either a full program or function is permitted.
• For the purposes of this challenge, n will be positive and under 100.
• Standard loopholes are disallowed by default.
• This question is code golf, so lowest byte-count wins.
• Here is some sample input and output:

1 => 1
2 => 1, 12
3 => 1, 12, 23
10 => 1, 12, 23, 34, 45, 56, 67, 78, 89, 910

If you have any questions, don't hesitate to ask. Good luck.

P.S this is my first challenge, so hopefully this all makes sense.

EDIT: Removed output restriction to allow numbers or strings.

• Can it be 0 indexed?
– Jo King
Jul 4, 2018 at 1:09
• @Jo King No. 1 should refer to the first iteration of the sequence as per the challenge spec. Jul 4, 2018 at 1:14
• No-one's said it yet, but welcome to PPCG! Nice first question, not too hard, yet not completely trivial either, and there's a number of different approaches
– Jo King
Jul 4, 2018 at 1:40
• @Jo King Thanks, I'm glad you liked it. Jul 4, 2018 at 1:41
• Do the outputs have to be in order? Can we mix strings and numbers?
– xnor
Jul 4, 2018 at 2:56

# Jelly, 3 bytes

ŻVƝ

A monadic link accepting an integer which yields a list of integers

Try it online!

### How?

ŻVƝ - Link: integer       e.g. 59
Ż   - zero-range               [0,1,2,3,4,5,6, ... ,58,59]
Ɲ - apply to each pair: i.e: [0,1] or [5,6]  or  [58,59]
V  -   evaluate* jelly code   1     or 56     or  5859
-                       -> [1,12,23,45,56, ... 5859]

* When given a list V actually joins the Python string values and evaluates that
...so e.g.: [58,59] -> ['58','59'] -> '5859' -> 5859

# Python 3, 39 bytes

f=lambda n:1//n or f'{f(n-1)} {n-1}{n}'

Try it online!

• Never thought f-strings can be used for golfing! Nice idea. Jul 6, 2018 at 10:17

# R, 32 bytes

strtoi(paste0((x=1:scan())-1,x))

Try it online!

Outgolfed by MickyT, so go upvote that answer!

• There’s been an edit to allow strings... no need for strtoi! Jul 4, 2018 at 14:10
• @JayCe it's necessary to strip the leading 0 from the first output. Jul 4, 2018 at 16:08
• couldn't you remove the leading zero by ending with [-1]rather than using strtoi or does that fail in some edge case or other?
– JDL
Jul 6, 2018 at 12:53
• @JDL strtoi is being used to convert from "01" to 1 because paste0 will return c("01","12","23","34",...) and we aren't allowed to return "01". Jul 6, 2018 at 13:09
• @CriminallyVulgar unfortunately that will fail for input of 1 Aug 9, 2018 at 11:09

f n=("":)>>=zipWith(++)$show<$>[1..n]

Try it online!

Thanks to Cat Wizard for a byte!

Try it online!

• @DLosc The %m$format specifier "denotes the position in the argument list of the desired argument, indexed starting from 1" (printf(3) man page). It's pretty handy as long as your C library supports it! Jul 8, 2018 at 5:20 • Thanks... but I'm still confused why %d%d (and switching the order of the arguments) doesn't work. (I tried it, but don't know why it produces no output.) Jul 8, 2018 at 22:11 • @DLosc If you change the format string, make sure to change the offset after it (e.g. " %d%d" should have +3*!f(i); otherwise, the +5 offset points to the NUL at the end of the string.) Jul 8, 2018 at 23:02 • Oh, okay--I finally get it: the "#2, then #1" is necessary because in the base case, the shortened format string becomes just "#1" and so you need the first printf argument to be i+1, not i. Very interesting. Jul 9, 2018 at 14:48 • 41 bytes abusing undefined behaviour in the form of unsequenced modification and access to i. – c-- Oct 9, 2022 at 20:28 # Python 3, 55 48 47 43 bytes f=lambda n:n-1and f(n-1)+[f"{n-1}{n}"]or[1] Try it online! Recursive function that takes an integer and returns a mixed list of strings and numbers. # Pyth, 98 6 bytes ms+dh Try it online! Explanation: - implicit output m - map function with argument d: + - concatenate d - argument d  - to string h - into implicit d + 1 - into Q (implicit input) • Welcom to PPCG! :) Jul 6, 2018 at 11:41 • @Shaggy Thank you, this is my first time doing this. Jul 6, 2018 at 13:39 # Fig, $$\8\log_{256}(96)\approx\$$ 6.585 bytes Mrx'_Jx} Try it online! Mrx'_Jx} Mrx' # For every number in the range [0, input) } # Input + 1 Jx # Prepend the input to that _ # Parse as number to remove leading 0s • This doesn't work for 1 - leading zeros aren't allowed. (Also, the challenge does say to output the first n terms...) Oct 9, 2022 at 19:00 • @Steffan but it is tagged sequence, so therefore the i/o defaults are allowed? Oct 9, 2022 at 19:23 • the i/o defaults are not allowed if the question overrides them. they are defaults, not requirements Oct 9, 2022 at 19:24 • @Steffan oof. done Oct 9, 2022 at 19:28 # Jelly, 4 bytes ḶżRV Try it online! ### How it works ḶżRV Main link. Argument: n Ḷ Unlength; yield [0, ..., n-1]. R Range; yield [1, ... n]. ż Zipwith; yield [[0, 1], ..., [n-1, n]]. V Eval; cast each array to string and evaluate, yielding integers. # Python 2, 44 bytes for i in range(input()):printi*(i>0)+i+1 Try it online! # 05AB1E, 6 bytes >GNJ,N Try it online! Explanation >G # for N in [1 ... input] N # push N J # join stack , # print N # push N (for next iteration) LεD<ìï would work for same byte count but with list output # APL (Dyalog Classic), 9 bytes 1,2,/⍕¨∘⍳ Try it online! • Nice job, I can't believe I didn't think of that. Jul 4, 2018 at 13:19 # Haskell, 37 bytes f x=[[y-1|y>1]++[y]>>=show|y<-[1..x]] Try it online! # Japt-m, 6 5 bytes ó2 ¬n Try it online! As always, know the flags. ### Unpacked & How it works -m Convert to range and map... Uó2 q n Uó2 Construct [U, U+1] q Join n Convert to number Implicit output (Array is printed as comma-delimited values) • 5 bytes. Don't know why ó doesn't work here without the 2. Jul 4, 2018 at 10:39 • I have 2 other 5 byte solutions (both using the same method) that don't use a flag, if anyone else wants to take a stab at them. Jul 4, 2018 at 11:04 • I think 5 + 2 = 7 bytes because of flag? Jul 7, 2018 at 6:18 • Jul 8, 2018 at 7:11 # C# (Visual C# Interactive Compiler), 1037164 56 bytes Golfed Try it online! i=>{for(int x=0;x<i;)Write($"{(x>0?$",{x}":"")}{++x}");} Ungolfed i => { for( int x = 0; x < i; ) Write($"{( x > 0 ? $",{x}" : "")}{ ++x }" ); } Full code Action<Int32> a = i => { for( int x = 0; x < i; ) Write($"{( x > 0 ? $",{x}" : "")}{ ++x }" ); }; Int32[] testCases = new Int32[] { 1, 2, 3, 10, }; foreach( Int32[] testCase in testCases ) { WriteLine($" Input: {testCase}\nOutput:" );
a(testCase);
WriteLine("\n");
}

Older versions:

• v1.2, 64 bytes

i=>{for(int x=0;x<i;)Write($"{(x>0?$",{x}":"")}{++x}");}

• v1.1, 71 bytes

i=>{for(int x=0;x<i;)System.Console.Write($"{(x>0?$",{x}":"")}{++x}");}

• v1.0, 103 bytes

i=>{for(int x=0;x<i;)System.Console.Write($"{(x>0?",":"")}{x++*System.Math.Pow(10,$"{x}".Length)+x}");}

Releases

• v1.3 - - 8 bytes - Removed Console thanks again to raznagul
• v1.2 - - 7 bytes - Removed System thanks to raznagul
• v1.1 - -32 bytes
• v1.0 - 103 bytes - Initial solution.

Notes

• None
• The C# Interactive Compiler has static imports for System.Console. So you can save 15 bytes by removing it. Jul 4, 2018 at 13:34
• Right! Habit of having to use them Jul 4, 2018 at 13:50
• You can also remove Console.: TIO Jul 4, 2018 at 13:58

# J, 14 bytes

(,&.":>:)"0@i.

Try it online!

• 2,&.":/\i.@>: for 13 bytes. Try it online! Jul 5, 2018 at 4:41

## ABAP, 101 bytes

Not really a golfing language, but I'm having a lot of fun with it

WHILE x<w.
CLEAR z.
IF x=1.
WRITE x.
ELSE.
CONCATENATE y x INTO z.
WRITE z.
ENDIF.
y=x.
x=x+1.
ENDDO.

W is the input term, X is the counter from 1, Y is X-1 from the second pass onward, Z is concatenated string.

# Powershell, 27 26 bytes

1.."$args"|%{"$p$_";$p=$_} -1 byte: thanks AdmBorkBork Test script:$f = {
1.."$args"|%{"$p$_";$p=$_} } &$f 1
""
&$f 2 "" &$f 3
""
&$f 10 "" &$f 46
• You can save a byte doing 1.."\$args" instead. Jul 5, 2018 at 13:41

# Python 2, 41 bytes

lambda l:[n[:n]+n+1for n in range(l)]

Try it online!