# 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

• Outgolfed Dennis! – Okx Jul 5 '18 at 19:32

# 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

# 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

## Haskell, 38 37 bytes

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


Try it online!

Thanks to Cat Wizard for a byte!

• As far as golfing goes you can also use <$> as a substitute for map, that can be infixed. – Wheat Wizard Jul 4 '18 at 1:05 # Cubix, 19 bytes I.1.W)>OSo;u.uO;@!-  Try it online! This wraps onto the cube as follows  I . 1 . W ) > O S o ; u . u O ; @ ! - . . . . .  Watch It Run Got a little room to play with yet, but at the moment • W redirect to the top face heading down • I1> set up the stack with the input and 1 then redirect into the main loop • OSo;u output the top of stack, add space to stack, output, remove and uturn • -!@;Ou) subtract TOS from input, if 0 halt else pop result, output TOS, uturn and increment TOS. Back into the main loop. # Perl 6, 19 18 bytes {(^$_ Z~1..$_)X+0}  Try it online! Anonymous code block that zips the range 0 to n-1 with 1 to n using the concatenation operator, then adds 0 to every element to force it to a number and remove leading 0s. # R, 30 29 bytes An extra byte thanks to @Giuseppe 10^nchar(n<-1:scan())*(n-1)+n  Try it online! A mostly mathematical solution, except for using nchar() rather than floor(log10()). I was really surprised that it came in shorter than the string version. • 29 bytes! nice work on this, I never would have thought of it! – Giuseppe Jul 5 '18 at 21:36 • @Giuseppe thanks for the extra byte. – MickyT Jul 5 '18 at 21:49 # APL (Dyalog), 13 12 bytes 1 byte saved thanks to @FrownyFrog (⍎⍕,∘⍕1∘+)¨⍳  Try it online! • Wow, our answers tied – Zacharý Jul 4 '18 at 0:59 • @Zacharý yours is more APLish though :) – Uriel Jul 4 '18 at 1:05 • Save 1: (⍎⍕,∘⍕1∘+)¨⍳ – FrownyFrog Jul 4 '18 at 1:31 # Brachylog, 6 bytes ⟦s₂ᶠcᵐ  Try it online! ### Explanation ⟦ Range: [0, …, Input] s₂ᶠ Find all substrings of length 2 cᵐ Map concatenate  # Python 2, 42 41 bytes f=lambda n:n-1and f(n-1)+[n-1+n]or[1]  Try it online! Recursive function that returns a mixed list of strings and integers • Did you intend to edit out the original description "Anonymous function that returns a list"? – Esolanging Fruit Jul 4 '18 at 5:44 • @EsolangingFruit Oopsie, fixed! Thanks – Jo King Jul 4 '18 at 5:54 • Maybe I am missing something but this doesn't seem to have '12' as the second element. – ElPedro Jul 4 '18 at 8:17 • @ElPedro That can be fixed by saving a byte with n and – Mr. Xcoder Jul 4 '18 at 8:36 • It's not often that a fix saves bytes :-) – ElPedro Jul 4 '18 at 8:42 # Haskell, 34 bytes f n="1":[show=<<[i-1,i]|i<-[2..n]]  Try it online! # Blossom, 88 bytes rule e<int x>[1(x)]=>[1(x-1),2(str(x)+str(x+1))|1->2];rule c[1(0),2|1->2]=>[2("12")];e!c  Blossom is a graph programming language I'm working on. It can only take graphs as inputs, so this programme expects a graph comprising a single node with its label an integer. It returns a graph of connected edges to form the closest to an array I can get, and the resultant graph is printed to output. An unminified version of the code is this: rule expand <int x> [ 1 (x) ] => [ 1 (x-1), 2(str(x)+str(x+1)) | 1->2 ] where x > 0; rule clean [ 1 (0), 2 ("12") | 1->2 ] => [ 2 ("12") ]; expand! clean  It defines two rules: one called expand, which (while there is a node with an integer-valued label in the current graph) creates another node with its increment concatenated, and lowers the value. It also creates an edge between these two nodes. This rule also has the condition that x is greater than 0. The ! executes this rule for as long as it can be applied on the graph, so in this case it will execute until x is 0. And then the clean rule removes this 0 node and its edge. Blossom was not made for golfing, but it doesn't do too badly, I don't think., considering what it is. There currently isn't really an easy way for people to test blossom code (and the interpreter I'm working on at the moment is not quite finished and a little buggy), but this isn't exactly a competing entry! # JavaScript (Node.js), 25 bytes f=n=>--n?f(n)+','+n+-~n:1  Try it online! • f=n=>--n?[f(n),n]+-~n:1 – l4m2 Jul 23 '18 at 13:22 ## Shakespeare, 703 bytes Q.Ajax,.Ford,.Act I:.Scene I:.[enter Ajax and Ford]Ford:Open mind!Scene V:.Ajax:You is the sum of thyself the sum of myself the sum of a big bad fat old red pig a big bad fat old lie!Ford:Open mind!Is you nicer zero?Ajax:If so, you is twice the sum of the sum of twice thyself twice thyself thyself!If so,Let us Scene V!Ford:You a cat!Open heart!Scene X:.Ajax:You is the sum of thyself a pig!Is you worse than a cat?If so,let us Scene C.Remember thyself.You is the sum of the sum of a big old red cute rich cat a big old red cute joy a big old pig!Speak mind!You is a big old red cute rich cat!Speak mind!Recall!Ford:Open heart!You is the sum of thyself a joy!Open heart!Let us Scene X.Scene C:.[exeunt]  try it here ## ungolfed version 127421th Night. Ajax, likes to read the stars. Ford, someone Ajax can always count on. Act I:. Scene I: Ajax reads a star. [enter Ajax and Ford] Ford: Open your mind! Scene V: Ford counts what ajax has learned. Ajax: you are the sum of thyself and the sum of myself and the sum of a big bad fat old red pig and a big bad fat old lie! Ford: Open Your mind! Are you nicer than zero? Ajax: If so, you are twice the sum of the sum of twice thyself and twice thyself and thyself! If so, Let us Scene V! Ford: You are a cat! Open your heart! Scene X: Ajax and Ford recall the nights. Ajax: You are the sum of thyself and a pig! Are you worse than a cat? If so, Let us Scene C. Remember thyself. You are the sum of the sum of a big old red cute rich cat and a big old red cute joy and a big old pig! Speak you mind! You are a big old red cute rich cat! Speak your mind! Recall your finest hour! Ford: Open your heart! You are the sum of thyself and a joy! Open your heart! Let us Scene X. Scene C: Fin. [exeunt]  # Groovy, 35 bytes {(0..<it)*.with{""+it+++it as int}}  Try it online! I came up last minute with the idea of using *.with instead of .collect. I have no idea what it+++it parses to but whether it's it++ + it or it + ++it they both do the same thing. I tried to think of a way of getting rid of the < in ..< by turning it into 1..it and decrementing but I don't think it would get any shorter. • Welcome to PPCG; nice first post! Regarding the parsing of a+++b, this test suggests it is parsed from left to right, meaning (a++)+b. – Jonathan Frech Jul 5 '18 at 14:30 # C (gcc), 44 43 bytes f(i){i--&&printf(" %2$d%d"+5*!f(i),i+1,i);}


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