# 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

# MBASIC, 102 94 bytes

1 INPUT N:FOR I=0 TO N-1:IF I>0 THEN PRINT MID$(STR$(I),2);
2 PRINT MID$(STR$(I+1),2);" ";:NEXT


Output:

? 3
1 12 23

? 10
1 12 23 34 45 56 67 78 89 910

? 16
1 12 23 34 45 56 67 78 89 910 1011 1112 1213 1314 1415 1516


Could have been much cleaner, but the STR$(n) number-to-string conversion function returns with a leading space that had to be dealt with. Turns out the variable for NEXT and the trailing PRINT are not needed, saving 8 bytes. # ><>, 15 13 bytes ln1-:?!;aoln:  Try it online! We take in the input as a command line argument. Thanks to @jo king for 2 byte loss (noticing the input loop value could be used as stack length. Explanation (simple): ln1-:?!;aoln: ln : Add the length of the stack to the stack and print. 1-:?!; : Take 1 off the input loop and check if zero, if 0, end. ao : Print new line ln: : Add the length of the stack to the stack, print and duplicate the input loop.  • 13 bytes. Also note that you don't have to count flags as bytes anymore – Jo King Oct 17 '18 at 5:35 • @JoKing I know I haven't been super active recently but when was that change? Also that is a nice change to mine, didn't even think about using the input as the length. – Teal pelican Oct 19 '18 at 8:30 • Herr's the meta discussion. – Jo King Oct 19 '18 at 9:46 • @JoKing Perfect, Thank you. – Teal pelican Oct 19 '18 at 11:39 # Tcl, 59 bytes proc C n {puts [incr i] time {puts$i[incr i]} [expr $n-1]}  Try it online! PS: I will golf it more later! # Jelly, 8 6 bytes ṭ’DFḌ)  Try it online! ṭ’DFḌ) Monadic link with argument n ) For each int in the range 1..n ’ n-1 ṭ [n-1, n] D Digits of n-1 and n F Flatten into one list Ḍ Convert back to an integer.  # Haskell, 57 55 bytes f n=read<$>zipWith((.show).(++).show)[0..][1..n]::[Int]


A function which takes a number and returns a list.

EDIT: -2 Bytes thanks to Cat Wizard

Try it online!

• My answer has been outdone by @Doorknob, go check out his. – Amphibological Jul 4 '18 at 1:00
• You can save a byte by using [0..n] and [1..n] instead. – Ad Hoc Garf Hunter Jul 4 '18 at 1:45

# CJam, 11 bytes

{{_)s+si}%}


Try it online!

• {_)s+si}%p <s>saves one byte</s> (nevermind, it's not allowed since it's not a function) – maxb Jul 4 '18 at 11:32

# Python 2, 43 bytes

lambda i:[1]+[x+x+1for x in range(1,i)]


Try it online!

First element is an integer, the rest are strings.

## Perl 5, 29 bytes

say"@{[1,map$_-1 .$_,2..<>]}"


# Julia 0.6, 30 bytes

n->["1";["$i$(i+1)"for i=1:n]]


Try it online!

Alternative version with numeric output:

### 34 bytes

n->[10^ndigits(i)*~-i+i for i=1:n]


Try it online!

(⊢(⊢+⊣×10*1+∘⌊10⍟⊢)1+⊢)¨0,⍳


Repository

Must be called like: ((⊢(⊢+⊣×10*1+∘⌊10⍟⊢)1+⊢)¨0,⍳) <value>, as I broke assignment of functions when I implemented shy results.

Note: this should also work in Dyalog APL, and due to that: -1 byte thanks to @Adám!

The ⍳ can either be the APL symbol or the greek one if run in RAD, but must be the APL version ifran in Dyalog APL

• +(⌊10⍟⊢)+∘⌊10⍟⊢ – Adám Jul 4 '18 at 6:24
• Thanks! Outgolfed in my own language ... somewhat, but this is also APL code, so not really. – Zacharý Jul 4 '18 at 13:21

# C# (Visual C# Compiler), 54 bytes

Uses space as seperator character.

n=>{var r="";for(;n-->1;)r=" "+n+(n+1)+r;return"1"+r;}


Try it online!

Ungolfed full code:

class P
{
static void Main()
{
System.Func<int, string> f =
n =>
{
var r = "";        //Declare variable for the result
for (; n--> 1;)    //Loop until n is 1

r =            //Set the result to:
" " +      //Seperator +
n +        //Value of n as string
(n + 1) +  //Value of n + 1 as string
r;         //Previous content of the result

return "1" + r;    //Return 1 (first item) + the result.
}
;

System.Console.WriteLine(f(1));
System.Console.WriteLine(f(2));
System.Console.WriteLine(f(3));
System.Console.WriteLine(f(10));
System.Console.WriteLine(f(100));
}
}


# C# (Visual C# Compiler), 46 bytes

If you are allowed to have some using static directives in the top whose bytes do not count:

n=>1+Concat(Range(1,n-1).Select(x=>","+x+++x))


Try it online!

Will explode if input n is 0.

It is interesting that, while the C# rules say ","+x+++x means ( "," + (x++) ) + x, if it had meant ( "," + x ) + (++x) instead, the program would still work!

• The using Statements should be included in the byte count. See this meta questions. Only using statements that are automatically included by the environment do not need to be counted. (Eg. TIO automatically adds using static System.Console for Visual C# Interactive Compiler. – raznagul Jul 5 '18 at 8:48

# Clojure, 54 bytes

#(reduce(fn[a n](conj a(str n(inc n))))[1](range 1 %))


Try it online!

Just a reduction over a range between 1 (inclusive) and n (exclusive).

(defn concat-n-n+1 [n]
(reduce (fn [acc m]
(conj acc (str m (inc m))))
[1]
(range 1 n)))


The first element of the list is a number, the rest are strings. This seems to be allowed by the spec.

# K (oK), 12 bytes

Solution:

,/'$1,2':1+!  Try it online! Examples: ,/'$1,2':1+!1
,,"1"
,/'$1,2':1+!2 (,"1" "12") ,/'$1,2':1+!3
(,"1"
"12"
"23")
,/'$1,2':1+!10 (,"1" "12" "23" "34" "45" "56" "67" "78" "89" "910")  Explanation: ,/'$1,2':1+! / the solution
! / range 0..n
2':    / sliding window of 2
1,       / prepend 1
$/ convert to strings ,/' / flatten each  ## C Sharp 51 bytes n=>new int[n].Select((_,o)=>int.Parse($"{o}{o+1}"))


# Attache, 15 bytes

{N!_'-~_}=>Iota


Try it online!

## Explanation

{N!_'-~_}=>Iota
{       }=>        map the inside function:
Iota    (over each number k from 0 to n-1)
'              array concatenate:
_               k
-~_           k+1
N!                convert [k, k + 1] to an integer (concatenates and returns a number)


# Rutger, 108 bytes

x=$Input; f=For[$x];
f=f[@i];
f=f[{p=Subtract[$i];r=Concat[Str[p[1]]];Print[Integer[r[Str[$i]]]];}];
Do[$f];  Try it online! ## Ungolfed input =$Input;
for = For[$input]; for = for[@index]; for = for[{ dec = Subtract[$index];
ret = Concat[Str[dec[1]]];
Print[Integer[ret[Str[$index]]]]; }]; Do[$for];


The basic concept of Rutger is the lack of multi-adic commands: every command takes a single argument, and if the command needs multiple argument, each new call returns a curried function.

First, we take evaluated input and store it in $x$. We then create a For object, a tri-adic command. The first two calls create a variable $f$, that will loop $x$ times, using the iteration variable $i$, starting at $i := 1$. The third call indicates the code to be run:

{p=Subtract[$i];r=Concat[Str[p[1]]];Print[Integer[r[Str[$i]]]];}


This creates a block of code containing 3 statements. Our first two are variable assignments. First, we create a curried function Subtract[$i], which prepares to subtract a value from $i$. This curried function is saved in the $p$ variable. Next, we create a second curried variable, $r$, which starts by calling p[1], subtracting $1$ from $i$. We then convert $i-1$ to a string and pass it as the first argument to the Concat function. Finally, we convert $i$ to a string, concatenate it to $str(i - 1)$ and convert it to an integer to reomve the leading $0$ when $i = 1$. This is then printed. The last line, Do[$f];, runs the for loop.

0,(⊢+10×⊣)⍁¨∊¨(⌽∘⌊(⊢|⍨10*(⍳(1+∘⌊10⍟⊢)))÷10*1-⍨(⍳(1+∘⌊10⍟⊢)))¨¨(⊢,1+⊢)¨⍳⎕


I wanted to try to see if I could do it in a "non-mathematical" way by splitting a number up into its digits.

C, 39 bytes

x(n){n&&x(n-1);printf("%d%d, ",n,n+1);}


eliminated the ternary conditional and shaved off 3 bytes.

• Leaving the main function out is allowed per meta consensus, since it often is shorter than a full program in C submissions often only implement a function. If you want to leave your submission as a whole program, I suggest removing the two spaces in "%d%d, " and char **n. n==0?:x(n-1); can also be n&&x(n-1);. – Jonathan Frech Jul 8 '18 at 21:30

# ARBLE, 23 20 bytes

Saved a handful of bytes by using better named variables.

range(0,n)//(x..y|0)


Try it online!

# Python 2.7, 52 bytes

I tried my best. Not yet familiar with this golfing thing.

def a(n):
for e in range(n):
print int(e+e+1)


The int() removes the leading zero in the first output, as specified in the rules.

• Changing this to an anonymous lambda function returning a list of numbers gets it down to 42 bytes – Jo King Jul 23 '18 at 1:38

# Twig, 72 bytes

Twig is very verbose, causing some issues when trying to reduce the length.

{%macro f(a)%}{%for i in 1..a%}{{o~i}}
{%set o=i%}{%endfor%}{%endmacro%}


This requires that "strict variables" is disabled (default).

## How to use?

Simply import the macro and call it:

{% import "fn.twig" as fn %}
{{ fn.f(<number>) }}


You can test it on https://twigfiddle.com/lah1a5

f n="1":map(show.(-1+)<>show)[2..n]


Try it online! 1

## Explanation / Ungolfed

The operator (<>) is the addition of Semigroups, in case of the Semigroup a -> b (where b needs to be a Semigroup) it is defined as:

(f <> g) = \x-> f x <> g x


And in case of the Semigroup String it is the same as concatenation, so the code becomes:

f n = "1" : map (\x-> show (x-1) ++ show x) [2..n]


1 (imports (<>) since it's not part of the Prelude in GHC 8.2.2)

## TI-Basic, 22 bytes

:seq(A,A,1,Ans
:Ans+(Ans-1)10^(1+int(log(Ans


# Bash, 56 bytes

echo 1;for i in $(seq$(($1-1)));do echo$i$((i+1));done  A pretty naive approach. # Lua, 62 bytes loadstring't={1}for i=2,(...)do t[#t+1]=(i-1)..i end return t'  Try it online! ### Explanation This is an anonymous function. t={1} -- initializes the return table, with the number 1 already in it for i = 2, (...) do -- loop from 2 to the number of the input -- (this is actual code, ... gets the arguments of the program/function t[#t+1] = (i-1)..i -- append to the table i-1 concatenated with i end return t -- returns the table  • You can do [i] instead of [#t+1] and remove the brackets around .... 57 bytes – Jo King Jul 29 '18 at 8:38 • Or it's shorter to have a full program. 40 bytes – Jo King Jul 29 '18 at 8:42 • About the first comment: yeah, I didn't pay attention :/ About the second: can I?! Hahah I thought the output had to be in the same line, as shown in the "question", that's why I did all of that table thing. – Visckmart Jul 29 '18 at 16:37 # Ruby, 34 33 bytes ->n{$><<i||=p(1);p(i+=1)<n&&redo}


Try it online!

Pseudocode:

loop
if i is undefined
set i to 1
print 1
print newline
end if
print i
increment i by 1
print i
print newline
if i >= n
break and return
end if
end loop


# Swift 4, 43 bytes

print(1);(1..<n).map{print("\($0)\($0+1)")}


Try it online!

n is the input of the program

# Noether, 15 bytes

I(iWi1+W+WP?!i)


Try it online!

## Explanation

I(             ) - Loop until the top of the stack equals the input
iW             - Push i and convert it to a string
i1+W         - Add one to i and convert to string
+        - Concatenate two strings
WP      - Convert string to a number and print it
?     - Print a newline
!i   - Increment i


VBA (Excel), 31 bytes

using immediate window and Cell [A1] as input

for x=1to[a1]:?int(x-1 &x):next