# 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 '18 at 1:09
• 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 '18 at 1:40
• After 7 days, I will accept the shortest answer which meets all these criteria. Why is there a need for the challenge to end? – Erik the Outgolfer Jul 4 '18 at 9:13
• Nowadays we tend to not accept an answer, because it discourages further posting of answers. I suppose you take old challenges as a model (which is also discouraged) See things-to-avoid-when-writing-challenges – user202729 Jul 4 '18 at 9:21
• @Dennis Ok, i'll remove the date from the challenge; maybe I'll accept when no more new answers are coming. – Amphibological Jul 4 '18 at 13:41

# 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. – Chromium Jul 6 '18 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! – JayCe Jul 4 '18 at 14:10
• @JayCe it's necessary to strip the leading 0 from the first output. – Giuseppe Jul 4 '18 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 '18 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". – Giuseppe Jul 6 '18 at 13:09
• @CriminallyVulgar unfortunately that will fail for input of 1 – Giuseppe Aug 9 '18 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! – ErikF Jul 8 '18 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.) – DLosc Jul 8 '18 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.) – ErikF Jul 8 '18 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. – DLosc Jul 9 '18 at 14:48 # 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! :) – Shaggy Jul 6 '18 at 11:41 • @Shaggy Thank you, this is my first time doing this. – u-ndefined Jul 6 '18 at 13:39 # 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. – Zacharý Jul 4 '18 at 13:19 • @Zacharý thanks – ngn Jul 4 '18 at 13:53 # 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. – Shaggy Jul 4 '18 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. – Shaggy Jul 4 '18 at 11:04 • I think 5 + 2 = 7 bytes because of flag? – u-ndefined Jul 7 '18 at 6:18 • – Bubbler Jul 8 '18 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. – raznagul Jul 4 '18 at 13:34
• Right! Habit of having to use them – auhmaan Jul 4 '18 at 13:50
• You can also remove Console.: TIO – raznagul Jul 4 '18 at 13:58

# J, 14 bytes

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

Try it online!

• 2,&.":/\i.@>: for 13 bytes. Try it online! – Jonah Jul 5 '18 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. – AdmBorkBork Jul 5 '18 at 13:41 # Python 2, 41 bytes lambda l:[n[:n]+n+1for n in range(l)] Try it online! # PHP, 33 32 bytes while($argv[1]--)echo" $i".++$i;

Try it Online

Old version

for(;$i<$argv[1];)echo" $i".++$i;     // 33 bytes

# Javascript, 43 44,46,49,53 bytes

n=>[...Array(n)].map((_,a)=>~~(a+(a+1+"")))

Previous versions :

n=>[...Array(n)].map((_,a)=>~~(a+(""+ ++a)))
n=>[...Array(n)].map((_,a)=>0- -(a+(""+ ++a)))
n=>[...Array(n).keys()].map(a=>0- -(a+(""+ ++a)))
n=>[...Array(n).keys()].map(a=>parseInt(a+(""+ ++a)))

Saved 3 bytes thanks to @Shaggy's solution (which is better than mine) to remove .keys()

• 39 bytes – Shaggy Jul 6 '18 at 13:08