Concatenating n with n + 1

44

4

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.

Amphibological

Posted 2018-07-03T23:48:31.700

Reputation: 1 394

1Can it be 0 indexed? – Jo King – 2018-07-04T01:09:26.330

1@Jo King No. 1 should refer to the first iteration of the sequence as per the challenge spec. – Amphibological – 2018-07-04T01:14:16.000

4No-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 – 2018-07-04T01:40:56.073

@Jo King Thanks, I'm glad you liked it. – Amphibological – 2018-07-04T01:41:53.140

Do the outputs have to be in order? Can we mix strings and numbers? – xnor – 2018-07-04T02:56:57.490

Can the output be space-separated? – xnor – 2018-07-04T03:07:02.083

@xnor, yes, they have to be in order. You can mix strings and numbers freely, and space separated is fine. – Amphibological – 2018-07-04T03:20:00.973

3After 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 – 2018-07-04T09:13:26.097

2

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 – 2018-07-04T09:21:50.910

Ok, @user202729, do you think I should just remove that criterion? – Amphibological – 2018-07-04T13:10:48.957

1@Amphibological It's a personal choice; some of us still accept answers. There's no need to specify a date though, and I wouldn't accept while the challenge is still getting more answers. – Dennis – 2018-07-04T13:20:22.473

2@Dennis Ok, i'll remove the date from the challenge; maybe I'll accept when no more new answers are coming. – Amphibological – 2018-07-04T13:41:29.520

1Is 01 an acceptable output for the first member of the sequence? – Giuseppe – 2018-07-04T15:04:12.257

@Guiseppe, No. There should be no leading zeroes. – Amphibological – 2018-07-04T15:13:01.197

@user202729 which other order? I'm not quite sure what you mean. – Amphibological – 2018-07-04T16:01:39.300

@user202729 No. The order should be the same as the sample output. – Amphibological – 2018-07-04T16:04:40.600

Answers

13

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

Jonathan Allan

Posted 2018-07-03T23:48:31.700

Reputation: 67 804

Outgolfed Dennis! – Okx – 2018-07-05T19:32:07.810

10

R, 32 bytes

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

Try it online!

Outgolfed by MickyT, so go upvote that answer!

Giuseppe

Posted 2018-07-03T23:48:31.700

Reputation: 21 077

There’s been an edit to allow strings... no need for strtoi! – JayCe – 2018-07-04T14:10:32.630

2@JayCe it's necessary to strip the leading 0 from the first output. – Giuseppe – 2018-07-04T16:08:27.253

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 – 2018-07-06T12:53:54.393

@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 – 2018-07-06T13:09:17.277

You can do the highly inelegant combine to match MickyT's 29, but I'm not a fan. Try it online!

– CriminallyVulgar – 2018-08-09T02:23:40.697

1@CriminallyVulgar unfortunately that will fail for input of 1 – Giuseppe – 2018-08-09T11:09:29.407

@Giuseppe You say "unfortunately"... It's always the edge cases that get me, good catch. – CriminallyVulgar – 2018-08-10T12:05:32.733

10

Python 3, 39 bytes

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

Try it online!

Dennis

Posted 2018-07-03T23:48:31.700

Reputation: 196 637

2Never thought f-strings can be used for golfing! Nice idea. – Chromium – 2018-07-06T10:17:55.653

8

Haskell, 38 37 bytes

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

Try it online!

Thanks to Cat Wizard for a byte!

Doorknob

Posted 2018-07-03T23:48:31.700

Reputation: 68 138

As far as golfing goes you can also use <$> as a substitute for map, that can be infixed. – Post Rock Garf Hunter – 2018-07-04T01:05:24.067

7

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.

Jo King

Posted 2018-07-03T23:48:31.700

Reputation: 38 234

7

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.

MickyT

Posted 2018-07-03T23:48:31.700

Reputation: 11 735

5

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.

MickyT

Posted 2018-07-03T23:48:31.700

Reputation: 11 735

29 bytes! nice work on this, I never would have thought of it! – Giuseppe – 2018-07-05T21:36:19.427

@Giuseppe thanks for the extra byte. – MickyT – 2018-07-05T21:49:44.643

4

APL (Dyalog), 13 12 bytes

1 byte saved thanks to @FrownyFrog

(⍎⍕,∘⍕1∘+)¨⍳

Try it online!

Uriel

Posted 2018-07-03T23:48:31.700

Reputation: 11 708

Wow, our answers tied – Zacharý – 2018-07-04T00:59:37.037

@Zacharý yours is more APLish though :) – Uriel – 2018-07-04T01:05:28.780

Save 1: (⍎⍕,∘⍕1∘+)¨⍳ – FrownyFrog – 2018-07-04T01:31:19.070

4

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

Jo King

Posted 2018-07-03T23:48:31.700

Reputation: 38 234

Did you intend to edit out the original description "Anonymous function that returns a list"? – Esolanging Fruit – 2018-07-04T05:44:48.550

@EsolangingFruit Oopsie, fixed! Thanks – Jo King – 2018-07-04T05:54:59.180

Maybe I am missing something but this doesn't seem to have '12' as the second element. – ElPedro – 2018-07-04T08:17:09.487

2@ElPedro That can be fixed by saving a byte with n and – Mr. Xcoder – 2018-07-04T08:36:09.463

1It's not often that a fix saves bytes :-) – ElPedro – 2018-07-04T08:42:58.013

4

Brachylog, 6 bytes

⟦s₂ᶠcᵐ

Try it online!

Explanation

⟦         Range: [0, …, Input]
 s₂ᶠ      Find all substrings of length 2
    cᵐ    Map concatenate

Fatalize

Posted 2018-07-03T23:48:31.700

Reputation: 32 976

4

Haskell, 34 bytes

f n="1":[show=<<[i-1,i]|i<-[2..n]]

Try it online!

Laikoni

Posted 2018-07-03T23:48:31.700

Reputation: 23 676

4

Blossom, 88 bytes

rule e<int x>[1(x)]=>[1(x-1),2(str(x)+str(x+1))];rule c[1(0)]=>[];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)) ]
where x > 0;

rule clean
    [ 1 (0) ]
 => [];

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. 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.

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!

IMP1

Posted 2018-07-03T23:48:31.700

Reputation: 510

3

JavaScript (Node.js), 25 bytes

f=n=>--n?f(n)+','+n+-~n:1

Try it online!

tsh

Posted 2018-07-03T23:48:31.700

Reputation: 13 072

f=n=>--n?[f(n),n]+-~n:1 – l4m2 – 2018-07-23T13:22:24.557

3

C (gcc), 44 43 bytes

f(i){i--&&printf(" %2$d%d"+5*!f(i),i+1,i);}

Try it online!

ErikF

Posted 2018-07-03T23:48:31.700

Reputation: 2 149

@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 – 2018-07-08T05:20:55.423

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 – 2018-07-08T22:11:02.573

@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 – 2018-07-08T23:02:34.180

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 – 2018-07-09T14:48:58.610

3

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]

Al R

Posted 2018-07-03T23:48:31.700

Reputation: 81

3

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.

Hlaaftana

Posted 2018-07-03T23:48:31.700

Reputation: 31

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 – 2018-07-05T14:30:00.870

3

Pyth, 9 8 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)

u_ndefined

Posted 2018-07-03T23:48:31.700

Reputation: 1 253

1Welcom to PPCG! :) – Shaggy – 2018-07-06T11:41:14.187

@Shaggy Thank you, this is my first time doing this. – u_ndefined – 2018-07-06T13:39:04.827

2

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.

Jo King

Posted 2018-07-03T23:48:31.700

Reputation: 38 234

2

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.

Dennis

Posted 2018-07-03T23:48:31.700

Reputation: 196 637

2

Python 2, 44 bytes

for i in range(input()):print`i`*(i>0)+`i+1`

Try it online!

Uriel

Posted 2018-07-03T23:48:31.700

Reputation: 11 708

2

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)

Bubbler

Posted 2018-07-03T23:48:31.700

Reputation: 16 616

5 bytes. Don't know why ó doesn't work here without the 2. – Shaggy – 2018-07-04T10:39:35.457

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 – 2018-07-04T11:04:54.027

I think 5 + 2 = 7 bytes because of flag? – u_ndefined – 2018-07-07T06:18:45.837

2

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

Emigna

Posted 2018-07-03T23:48:31.700

Reputation: 50 798

2

APL (Dyalog Classic), 9 bytes

1,2,/⍕¨∘⍳

Try it online!

ngn

Posted 2018-07-03T23:48:31.700

Reputation: 11 449

Nice job, I can't believe I didn't think of that. – Zacharý – 2018-07-04T13:19:52.523

@Zacharý thanks – ngn – 2018-07-04T13:53:05.787

2

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

mazzy

Posted 2018-07-03T23:48:31.700

Reputation: 4 832

1You can save a byte doing 1.."$args" instead. – AdmBorkBork – 2018-07-05T13:41:06.630

2

Husk, 11 9 bytes

-2 thanks to @BMO!

mSöd+d←dḣ

Try it online!

Explanation

m          map(                                              )
 S                                               <*>
  ö            (           .).    .         .
   d            fromDecimal
    +                         (++)
     d                             toDecimal
      ←                                      (+1)
       d                                            toDecimal
                                                              .
        ḣ                                                      (\n->[1..n])

mSöd+d←dḣ  map((fromDecimal.).(++).toDecimal.(+1)<*>toDecimal).(\n->[1..n])

Esolanging Fruit

Posted 2018-07-03T23:48:31.700

Reputation: 13 542

2

C# (Visual C# Interactive Compiler), 103 71 64 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

auhmaan

Posted 2018-07-03T23:48:31.700

Reputation: 906

1The C# Interactive Compiler has static imports for System.Console. So you can save 15 bytes by removing it. – raznagul – 2018-07-04T13:34:01.553

Right! Habit of having to use them – auhmaan – 2018-07-04T13:50:10.610

You can also remove Console.: TIO

– raznagul – 2018-07-04T13:58:40.093

2

Haskell, 37 bytes

f x=[[y-1|y>1]++[y]>>=show|y<-[1..x]]

Try it online!

user28667

Posted 2018-07-03T23:48:31.700

Reputation: 579

2

J, 14 bytes

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

Try it online!

dram

Posted 2018-07-03T23:48:31.700

Reputation: 61

12,&.":/\i.@>: for 13 bytes. Try it online! – Jonah – 2018-07-05T04:41:47.697

2

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.

Noir Antares

Posted 2018-07-03T23:48:31.700

Reputation: 469

2

PHP, 33 32 bytes

while($argv[1]--)echo" $i".++$i;

Try it Online

Old version

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

Crypto

Posted 2018-07-03T23:48:31.700

Reputation: 862

2

Python 2, 41 bytes

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

Try it online!

TFeld

Posted 2018-07-03T23:48:31.700

Reputation: 19 246

2

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()

IEatBagels

Posted 2018-07-03T23:48:31.700

Reputation: 189

139 bytes – Shaggy – 2018-07-06T13:08:36.620

2

Python 3, 44 bytes

lambda n:[f"{j or''}{j+1}"for j in range(n)]

Try it online!

JathOsh

Posted 2018-07-03T23:48:31.700

Reputation: 31

1Welcome to the site! You can save bytes by removing the space between your string and the for. Also since this is an anonymous function there is no need for f=, so you can save 2 bytes by removing it. – Post Rock Garf Hunter – 2018-07-09T04:28:23.237

@CatWizard Thanks! But what do you mean by anonymous function? is there a way to call an anonymous function? – JathOsh – 2018-07-09T05:08:17.653

2An anonymous function is any function that is not associated with a name. In python the lambda keyword makes an anonymous function. Anonymous functions can be set to variables as you did, they can also be called directly without assignment (that's what makes them anonymous) by wrapping them in parentheses e.g. (lambda x:x+1)(6). For TIO you can put f=\ in the "header" section and call the function with f. – Post Rock Garf Hunter – 2018-07-09T05:12:42.677

@CatWizard Thanks that is super helpful – JathOsh – 2018-07-09T05:29:14.000

1

How about having the condition for 1 inside the format string? 44 bytes

– Jo King – 2018-07-09T06:28:54.153

@JoKing Thanks! now i get to learn something more about python, I haven't seen the or operator used like that before – JathOsh – 2018-07-18T03:30:04.987

1

K (ngn/k), 13 bytes

{.,/$x+!2}'!:

Try it online!

! generate the list 0 1 ... n-1

{ } is a function with argument x

' applied to each

!2 is 0 1

x+!2 is x, x+1

$ format as strings

,/ concatenate

. evaluate (convert to number)

ngn

Posted 2018-07-03T23:48:31.700

Reputation: 11 449

Strings or numbers are fine for output. – So . should not be needed. – Mr. Xcoder – 2018-07-04T05:14:21.810

@Mr.Xcoder thanks - the challenge has changed since I answered it – ngn – 2018-07-04T06:22:06.290

@Mr.Xcoder unfortunately, if I remove . there's a leading 0 in "01" – ngn – 2018-07-04T06:29:29.417

1

Canvas, 6 bytes

ŗ²;+┤]

Try it here!

Explanation:

{     ]  map over 1..input
 ŗ         convert to string (required as `+` needs 1 arg to be a string to not add)
  ²;       place a 0-indexed version of the index below TOS
    +      join the two
     ┤     cast to number

ŗ²×┤] (or even ²×┤]) would work if I didn't try to push the absolute most out of characters and didn't make × - reverse add - do not that when not receiving 2 strings.

dzaima

Posted 2018-07-03T23:48:31.700

Reputation: 19 048

1

cQuents, 11 bytes

=1::($-1)~$

Try it online!

Way too long for a language that this is supposed to be easy in, guess I should have implemented unary subtract-one and add-one operators.

Explanation

=1            First term in sequence is 1
  ::          Mode: for input n, output first n terms in sequence
              For each term in the sequence:
    ($-1)      Subtract 1 from the current index
         ~$    Concatenate that to the current index

Stephen

Posted 2018-07-03T23:48:31.700

Reputation: 12 293

Note current version uses & instead of ::, saving 1 byte – Stephen – 2019-02-01T04:53:51.730

1

APL (Dyalog Classic), 13 bytes

2{⍎∊⍕¨⍺⍵}/0,⍳

Try it online!

Zacharý

Posted 2018-07-03T23:48:31.700

Reputation: 5 710

1

Perl 5, 24 21 bytes

@DomHastings came up with a way to save 3 bytes

say$i++.$i|0for 1..<>

Try it online!

Xcali

Posted 2018-07-03T23:48:31.700

Reputation: 7 671

Nice! Much shorter than my first approach using a while and $\! Using yours as a base though, you can save a couple of bytes using eval and x<>: Try it online! or even Try it online!

– Dom Hastings – 2018-07-04T11:44:33.157

Wait, combining the two gives 21: Try it online!

– Dom Hastings – 2018-07-04T11:46:48.217

1

Momema, 36 bytes

z0w+1=*0-8*0w00+1*0-8*0-9 10z=+_M-*0

Try it online! Requires the -i interpreter flag.

Explanation

                                                     #  i = 0
d   0            #  d0:  nop                         #  do {
i   (+ 1 =*0)    #  i0:  jump to i(![0])             #    if i {
-8  *0           #       print [0]                   #      print i
i   0            #  i1:  nop                         #    }
0   (+ 1 *0)     #       [0] = [0] + 1               #    i += 1
-8  *0           #       print [0]                   #    print i
-9  10           #       print chr(10)               #    print \n
d   =(+ _M -*0)  #  d1:  jump to d(!!(input - [0]))  #  } while (input - i != 0)

The Momema reference interpreter provides an "interactive mode", enabled by -i, which is intended to be used on the command line.

One of the features it allows is the ability to add holes, denoted by _, which effectively allow one to substitute an integer read from STDIN into an expression. This is already shorter than *-8 (read from memory-mapped I/O location -8), which does the same thing without interactive mode and without displaying a prompt to STDERR.

Crucially, holes can also be named with a sequence of capital letters after the _. Evaluation of named holes is memoized. Input will be read the first time a named hole is evaluated but subsequent evaluations of a hole with the same name will reuse the input number. This means that we can use _M to stand in for "the input", but input will only be read on the first iteration of the loop.

Esolanging Fruit

Posted 2018-07-03T23:48:31.700

Reputation: 13 542

1

Red, 56 bytes

func[n][prin"1 "repeat i n - 1[prin rejoin[i i + 1" "]]]

Try it online!

Galen Ivanov

Posted 2018-07-03T23:48:31.700

Reputation: 13 815

1

Rust, 56 bytes

|n|(0..n).map(|n|format!("{}{}",n,n+1).parse().unwrap())

Try it online!

Konrad Borowski

Posted 2018-07-03T23:48:31.700

Reputation: 11 185

1

Java, 48 bytes

String f(int n){return--n>0?f(n)+","+n+-~n:"1";}

Port of tsh's JavaScript answer. Try it online here.

Ungolfed:

String f(int n) { // recursive function taking an integer as argument and returning a String
    return --n > 0 ? f(n) // decrement n and recurse if n is still positive after
                   + "," + n // return the result of the recursive call concatenated with n and ...
                   + (- ~n) // ... n+1; writing it as -~n gives it precedence over the concatenation
                   : "1"; // if n is now 0 on the other hand, return "1"
}

O.O.Balance

Posted 2018-07-03T23:48:31.700

Reputation: 1 499

1

MATL, 9 bytes

:"@qV@VhU

Try it online!

              % implicit input n
:             % range, push 1..n
"             % for loop:
 @            % push for loop index
 q            % decrement
 V            % convert to string (num2str)
 @            % push for loop index
 V            % convert to string (num2str)
 h            % horizontally concatenate
 U            % convert to number (str2num)
              % implicit end of for loop
              % implicit end of program, display stack contents

Giuseppe

Posted 2018-07-03T23:48:31.700

Reputation: 21 077

1

Panacea, 6 bytes

re
D>j

Explanation:

r        Range [0.. input]
 e       Map each element with the following line
D        Duplicate
 >       Increment
  j      Join digits; multiply by ten and add
         Since this works with integers, it removes the preceding 0.

Okx

Posted 2018-07-03T23:48:31.700

Reputation: 15 025

1

Japt, 5 bytes

õÈsiY

Try it


Explanation

          :Implicit input of integer U
õ         :Range [1,U]
 È        :Map each integer at index Y
  s       :  Convert to string
   iY     :  Prepend index
          :  Implicitly convert back to integer
          :Implicit output of resulting array

Alternative

Ç°s+Z

Try it

          :Implicit input of integer U
Ç         :Map each integer Z in the range [0,U)
 °        :  Postfix increment
  s       :  Convert to string
   +Z     :  Append (the now incremented) Z
          :  Implicitly convert back to integer
          :Implicit output of resulting array

Shaggy

Posted 2018-07-03T23:48:31.700

Reputation: 24 623

1

J, 20 bytes

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

Try it online!

ljeabmreosn

Posted 2018-07-03T23:48:31.700

Reputation: 341

1

Forth (gforth), 33 bytes

: f dup 1 ?do i . i 1 .r loop . ;

Try it online!

Explanation

Loops through all numbers in range and outputs the number twice, the first with a space appended, and the second without.

This results in the first output being appended to the previous output. To fix the last case, the input is outputted so that it can be appended to the last number in the loop.

Code Explanation

: f                   \ start a new word definition
  dup 1               \ duplicate the input and put a 1 on the stack
  ?do                 \ begin counted loop from 1 to n (does nothing if 1 == n)
    i .               \ output loop index with a space appended
    i 1 .r            \ output loop index right-aligned with minimum 1 character length
  loop                \ end the loop
  .                   \ output the input we duplicated earlier
;                     \ end the word definition

reffu

Posted 2018-07-03T23:48:31.700

Reputation: 1 361

1

Yabasic, 37 bytes

An anonymous function that takes input from STDIN and outputs to STDOUT.

Input""n
?1
For i=2TO n?i-1,"",i
Next

Try it online!

-14 bytes thanks to @ErikF

Taylor Scott

Posted 2018-07-03T23:48:31.700

Reputation: 6 709

You can get it down to 31 bytes by not counting the input assignment and making use of , between output fields in PRINT to combine them: Try it online!

– ErikF – 2018-07-06T08:42:05.610

@ErikF, input must be taken explicitly per community rules and cannot be taken from a predefined variable. That said I had never seen the ?n,"",m trick - that is really quite clever.

– Taylor Scott – 2018-07-06T10:56:39.250

1

Excel VBA, 29 bytes

An anonymous VBE immediate window function that takes input from cell [A1] and outputs to the console.

?1:For i=2To[A1]:?i-1 &i:Next

Taylor Scott

Posted 2018-07-03T23:48:31.700

Reputation: 6 709

I've always wanted to use Excel VBA for one of these. I have SO much to learn! – seadoggie01 – 2018-07-06T15:16:53.993

@seadoggie01 Its a great way to get more familiar with the language - and fortunately, VBA has a very well made up Tips Page that can help you to get started :)

– Taylor Scott – 2018-07-06T16:17:35.300

@seadoggie01 oh, and if you are interested in VBA answers, I have a couple that I am really quite proud of, such as Let's Draw Mona Lisa, Embiggen your Input, and Visualize Visual Eyes

– Taylor Scott – 2018-07-06T16:20:18.980

1Ha! The first thing I found after this question was the Tips page :) – seadoggie01 – 2018-07-06T16:29:45.430

1

dc, 29 bytes

[d1-d0<F]dsFx+p[npz1<G]sGz1<G

Try it online!

This is a good showing for dc because its printing capabilities are so limited, but line up perfectly with the challenge spec. Input is from the stack (and must be the only thing on the stack), output is to stdout. There's some duplication near the end I can't figure out how to get rid of without breaking the case n=1

Explanation

F will be the macro [d1-d0<F]
d        copy the top of the stack
 1-      decrement
   d0<F  repeat (tail recursion) until a 0 is on top

G will be the macro [npz1<G]
n        print the top (pop, but no newline)
 p       print the new top (newline, but no pop)
  z1<G   repeat (tail recursion) until only one number is on the stack

Full program (example input: 4)
[d1-d0<F]dsFx      Store F and run it: new stack is 0 1 2 3 4
+                  Drop the zero (can't just recurse to 1, or n=1 breaks)
p                  Print (no pop) the '1': stack is 1 2 3 4
[npz1<G]sG        Store G
z1<G               Run G if there's more than one number on the stack

Sophia Lechner

Posted 2018-07-03T23:48:31.700

Reputation: 1 200

1

dc, 34 bytes

sj1psi[lid1+dsiZAr^*li+pzlj>M]dsMx

Try it online!

Completely different (and less golfy, unfortunately) approach than Sophia's dc answer. I juggle a lot of register activity here that I wish I could cut down, seems the likeliest way to golf a couple of bytes. Expects input as the sole stack entry.

sj1psi stores the input into register j, prints the initial 1, and stores 1 in register i. Macro M duplicates i, increments it, and then multiplies it by 10 to the power of however many digits the incremented value has (ZAr^*). Fetches the newly incremented version, and adds the two together. Compares register j to the number of entries on the stack, and runs until they match.

brhfl

Posted 2018-07-03T23:48:31.700

Reputation: 1 291

1

MATLAB 45 63 bytes

@(j)eval('for a=0:j-1;disp([num2str(a)*a/a,num2str(a+1)]);end')

Somewhat ugly *a/a in order to avoid printing leading zero for the first element

Fixed by wrapping into disp and anonymous function

aaaaa says reinstate Monica

Posted 2018-07-03T23:48:31.700

Reputation: 381

You can't assume the input is predefined as a variable unfortunately. You have to do j=input(''); or create a function. Anyway, +1, as I'm assuming you'll fix it. Anonymous function with eval is often shortest when loops are involved. – Stewie Griffin – 2018-07-08T17:47:12.357

@StewieGriffin thanks for advice, i am still learning ways around golfing – aaaaa says reinstate Monica – 2018-07-08T18:43:29.807

@StewieGriffin by anonymous function + eval you mean something like f = @(j) eval('for ..... end') ? – aaaaa says reinstate Monica – 2018-07-08T18:53:56.037

1Yes :-) you don't need to include f= in the byte count, since the function can be used unnamed like: ans(6). – Stewie Griffin – 2018-07-08T19:57:09.120

1

yup, 48 bytes

0eee0ee-0ee-*:0e#[:@]0e-{]:[:]-:#0e0~--#]:@]0e-}

Try it online!

Explanation

yup only knows of a few commands. To modify data, I'll be using 0 (nilad pushing that number), e (natural exponentiation), and - (subtraction).

For example, the snippet 0e is equal to 1, since \$e^0=1\$.

This program is divided into two parts: initialization and iteration.

Initialization

0eee0ee-0ee-*:0e#[:@]0e-

0eee pushes \$e^e\approx15.1543\$ and 0ee pushes \$e\approx2.7183\$. Thus, the expression 0eee0ee-0ee- pushes:

$$e^e-e-e\approx9.7177$$

This encodes 0x10 (the linefeed), since numbers are rounded to the nearest integer before being outputted. This is our numeric separator.

The next part is to initialize the stack with data. *: pushes the input twice, and 0e# outputs a 1. [:@] outputs a linefeed without popping it from the stack, and 0e- decrements the input. This handles the edge case of outputting 1 instead of 01. Rather than handle this with a conditional, hardcoding the first entry is shorter.

Iteration

{]:[:]-:#0e0~--#]:@]0e-}

{...} loops while the TOS is defined and positive. In this case, it will stop when it hits zero. Each iteration starts off with a stack like this:

[9.7177, input, iterator]

iterator starts at input - 1. ]:[:]- calculates input - iterator and gives us our true iterator value. Then, :#0e0~--# first outputs the true iterator then the same number plus 1, where 0e0~-- encodes \$-(-n-e^0)=-(-n-1)=n+1\$. Then, ]:@] restores the stack to its initial shape and 0e- subtracts 1 from the iterator, continuing our loop. This repeats until iterator reaches 0, at which point the loop stops and the program terminates.

Conor O'Brien

Posted 2018-07-03T23:48:31.700

Reputation: 36 228

1

D, 93 bytes

import std.math;_[]f(_)(_ n){_[]k;foreach(i;0..n)k~=++i+10^^(cast(_)i--.log10+1)*i;return k;}

Try it online!

I couldn't find a nice (short) solution that evades an import, and this was the shortest of the bunch.

Conor O'Brien

Posted 2018-07-03T23:48:31.700

Reputation: 36 228

You can save two bytes by making auto be _[] – Zacharý – 2018-07-08T16:15:13.443

@Zacharý Good point! – Conor O'Brien – 2018-07-08T17:21:50.230

WOuldn't it just be easier to do std.conv trickery? – Zacharý – 2018-07-11T02:04:13.283

1

QBasic, 60 53 bytes

INPUT n
?1
FOR i=2TO n
?STR$(i-1)MID$(STR$(i),2)
NEXT

A math-based solution, because converting numbers to strings in QBasic is a lot more complicated than it ought to be. Nope, strings are still shorter, you just have to special-case the first item. The problem with STR$(i) is that it adds a space to the start of positive numbers, so we take all but the first character by using MID$. Other than that, it's pretty straightforward.

DLosc

Posted 2018-07-03T23:48:31.700

Reputation: 21 213

1

DC, 33 bytes

si[lidZAr^spd1-dsilp*+li0<d]dsdxf

Explanation

si[lidZAr^spd1-dsilp*+li0<d]dsdxf  Whole program.
si                                 Save the value on the stack to the i register.
  [                        ]dsdx   Create a macro, duplicate it, store it in the d register, and execute it.
   li                              Put the value from the i register on the stack.
     dZ                            Duplicate the top value, and change it to the number of digits it has.
       Ar                          Push 10 on the stack, and reverse the top two values.
         ^sp                       Do 10^x, and store it in the p register.
            d1-                    Duplicate the top value, and subtract 1 from it.
               dsi                 Duplicate the top value, and store it in the i register.
                  lp*+             Put the value from the p register on the stack, and multiply it by the the value we just put in the i register. Then, add the top two values together.
                      li0<d        Put the value from the i register and then 0 on the stack. If 0 < li, then we run the d macro again.
                                f  Print the stack.

Input is the number of numbers to be generated, on the stack.

Output is printed.

FlexEast

Posted 2018-07-03T23:48:31.700

Reputation: 31

Welcome to PPCG! – DLosc – 2018-07-12T20:16:06.913

Thanks! I've been lurking for a while, figured I'd finally give it a shot! – FlexEast – 2018-07-12T20:17:44.550

1

Kotlin, 48 bytes

{"1, "+(2..it).map{"$it${it+1}"}.joinToString()}

Yes I know, I could save 1 more byte by removing the blank behind the first comma, but it looks nicer with it :-)

Try it online!

Roland Schmitz

Posted 2018-07-03T23:48:31.700

Reputation: 161

1

Shakespeare Programming Language, 310 bytes

,.Ajax,.Ford,.Page,.Act I:.Scene I:.[Enter Ajax and Ford]Ford:Listen tothy.Ajax:You cat.Open heart.[Exit Ajax][Enter Page]Scene V:.Ford:Am I worse Ajax?If notlet usScene X.You be twice the sum ofa cat a big big cat.Speak thy.Page:Open heart.You be the sum ofyou a cat.Open heart.Let usScene V.Scene X:.[Exeunt]

Try it online!

JosiahRyanW

Posted 2018-07-03T23:48:31.700

Reputation: 2 600

If you don't mind ending in an error, you can get rid of scene X for 293 bytes

– Jo King – 2018-09-22T22:01:39.650

1

MathGolf, 8 6 5 4 bytes

{└§p

Try it online!

Outputs a newline separated series.

Explanation:

{└§p
{       Start a loop over the range(0, input)
 └      Push the top of stack (implicitly the index of the loop) + 1
  §     Concatenate the two (this removes leading 0s)
   p    And print the value

Jo King

Posted 2018-07-03T23:48:31.700

Reputation: 38 234

Really nice solution! Splitting the printing into two different loop iterations was really clever! I saw that you used the "push n+1 without popping" operator too, it worked really well for this task. – maxb – 2018-09-24T10:56:04.453

1

Runic Enchantments, 33 bytes

/01iR1-:0)?;{1+:
\$1<\}$q}:+1{$ '

Try it online!

Uncompressing the entry sequence and moving the reflectors to the other side:

>1$01iR1-:0)?;{1+:\
      \}$q}:+1{$ '/

Entry sequence (>1$01i) is fairly straight forward. Push and print 1, push 0, push 1, read input and push it to the top of the stack.

At R we enter the program's main loop (unrolled with directional control characters removed):

1-:0)?;{1+:' ${1+:}q$}

At this point the stack is [0,1,i] where i is the input value.

The loop subtracts 1 from the input value (1-), compares it to greater than 0 (if true, skip terminator, else terminate; :0)?;).

Then a series of stack manipulations ({1+:{1+:}) and increments to result in [2,(i-1),1,1,2] as well as printing a space (' $). q then concats the top two items on the stack, which is then printed (giving 12 in the output stream).

Finally the stack is rotated once more, leaving [1,2,(i-1)] as the input to the next loop iteration.

Bonus challenge: using two IPs? 40 bytes

>1$0iR1-:0)?;1{+:' \
> F1iU }$~?=am$?=9m/

Try it online!

As there's no way to clone the input to a second instruction pointer (I have thought about stack cloning, so this may be possible in the future, but the spec for it would be difficult to implement), we have to read it from the input stream twice.

Flow results in the second pointer being a step behind the first (avoiding merging) and the Fizzle lets us distinguish the two IPs, letting one print a space and the other discards it. I can't figure out a shorter way of performing this check.

However if it allowable to print two spaces as a separator it can be reduced to this (30 bytes):

>1$0iR1-:0)?;1\
> F1iU}$:+{$ '/

input: 4 4
output: 1  12  23  34

But this is an admittedly dubious answer due to how it has to take input, but 3 bytes shorter than the single IP answer, which is interesting.

Try it online!

Update: Stack transfer

Getting the two pointers to enter the T command in the right execution order is a huge pain. The remaining two spaces in this program can't be removed, as it messes with the timing, but it avoids having to supply the input value twice. Prints 2 spaces between each entry in the sequence (35 bytes).

>1$0y TR1-:0)?;1\
 >1i:1/U}$:+{$ '/

Try it online!

Draco18s no longer trusts SE

Posted 2018-07-03T23:48:31.700

Reputation: 3 053

1

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.

wooshinyobject

Posted 2018-07-03T23:48:31.700

Reputation: 171

1

><>, 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.

Teal pelican

Posted 2018-07-03T23:48:31.700

Reputation: 1 338

113 bytes. Also note that you don't have to count flags as bytes anymore – Jo King – 2018-10-17T05:35:59.297

@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 – 2018-10-19T08:30:45.100

1Herr's the meta discussion. – Jo King – 2018-10-19T09:46:57.020

@JoKing Perfect, Thank you. – Teal pelican – 2018-10-19T11:39:44.733

0

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.

dylnan

Posted 2018-07-03T23:48:31.700

Reputation: 4 993

0

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!

sergiol

Posted 2018-07-03T23:48:31.700

Reputation: 3 055

0

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!

Amphibological

Posted 2018-07-03T23:48:31.700

Reputation: 1 394

My answer has been outdone by @Doorknob, go check out his. – Amphibological – 2018-07-04T01:00:08.047

You can save a byte by using [0..n] and [1..n] instead. – Post Rock Garf Hunter – 2018-07-04T01:45:49.403

0

RAD, 28 27 bytes

(⊢(⊢+⊣×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

Zacharý

Posted 2018-07-03T23:48:31.700

Reputation: 5 710

+(⌊10⍟⊢)+∘⌊10⍟⊢ – Adám – 2018-07-04T06:24:02.157

Thanks! Outgolfed in my own language ... somewhat, but this is also APL code, so not really. – Zacharý – 2018-07-04T13:21:20.203

0

CJam, 11 bytes

{{_)s+si}%}

Try it online!

Esolanging Fruit

Posted 2018-07-03T23:48:31.700

Reputation: 13 542

{_)s+si}%p <s>saves one byte</s> (nevermind, it's not allowed since it's not a function) – maxb – 2018-07-04T11:32:48.670

0

Python 2, 43 bytes

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

Try it online!

First element is an integer, the rest are strings.

ElPedro

Posted 2018-07-03T23:48:31.700

Reputation: 5 301

0

Perl 5, 29 bytes

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

Denis Ibaev

Posted 2018-07-03T23:48:31.700

Reputation: 876

0

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!

sundar - Reinstate Monica

Posted 2018-07-03T23:48:31.700

Reputation: 5 296

0

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));
    }
}

raznagul

Posted 2018-07-03T23:48:31.700

Reputation: 424

0

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!

Jeppe Stig Nielsen

Posted 2018-07-03T23:48:31.700

Reputation: 602

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 – 2018-07-05T08:48:05.627

0

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.

Carcigenicate

Posted 2018-07-03T23:48:31.700

Reputation: 3 295

0

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
         1+  / add 1
      2':    / sliding window of 2
    1,       / prepend 1
   $         / convert to strings
,/'          / flatten each

streetster

Posted 2018-07-03T23:48:31.700

Reputation: 3 635

0

C Sharp 51 bytes

n=>new int[n].Select((_,o)=>int.Parse($"{o}{o+1}"))

IEatBagels

Posted 2018-07-03T23:48:31.700

Reputation: 189

0

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)

Conor O'Brien

Posted 2018-07-03T23:48:31.700

Reputation: 36 228

0

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.

user81536

Posted 2018-07-03T23:48:31.700

Reputation:

0

C, 39 bytes

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

eliminated the ternary conditional and shaved off 3 bytes.

Geo

Posted 2018-07-03T23:48:31.700

Reputation: 91

1Leaving 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 – 2018-07-08T21:30:35.433

0

ARBLE, 23 20 bytes

Saved a handful of bytes by using better named variables.

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

Try it online!

ATaco

Posted 2018-07-03T23:48:31.700

Reputation: 7 898

0

RAD, 72 bytes

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

Link to repository

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

Zacharý

Posted 2018-07-03T23:48:31.700

Reputation: 5 710

0

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

Asone Tuhid

Posted 2018-07-03T23:48:31.700

Reputation: 1 944

0

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.

StealthyPanda

Posted 2018-07-03T23:48:31.700

Reputation: 41

Changing this to an anonymous lambda function returning a list of numbers gets it down to 42 bytes

– Jo King – 2018-07-23T01:38:09.293

0

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

Ismael Miguel

Posted 2018-07-03T23:48:31.700

Reputation: 6 797

0

Haskell, 35 bytes

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)

ბიმო

Posted 2018-07-03T23:48:31.700

Reputation: 15 345

0

TI-Basic, 22 bytes

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

Oki

Posted 2018-07-03T23:48:31.700

Reputation: 311

0

Bash, 56 bytes

echo 1;for i in $(seq $(($1-1)));do echo $i$((i+1));done

A pretty naive approach.

Aneesh Durg

Posted 2018-07-03T23:48:31.700

Reputation: 239

0

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

Visckmart

Posted 2018-07-03T23:48:31.700

Reputation: 151

You can do [i] instead of [#t+1] and remove the brackets around .... 57 bytes

– Jo King – 2018-07-29T08:38:11.117

Or it's shorter to have a full program. 40 bytes

– Jo King – 2018-07-29T08:42:26.510

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 – 2018-07-29T16:37:22.500

0

Swift 4, 43 bytes

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

Try it online!

n is the input of the program

buttercrab

Posted 2018-07-03T23:48:31.700

Reputation: 169

0

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

Beta Decay

Posted 2018-07-03T23:48:31.700

Reputation: 21 478

0

VBA (Excel), 31 bytes

using immediate window and Cell [A1] as input

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

remoel

Posted 2018-07-03T23:48:31.700

Reputation: 511

0

Pepe, 68 bytes

RrEEEEEREeErREEREEEEEREErEEEEEeEErEEEereEEreeErEEEEEeeEReerREEREeRee

Try it online!

Previous code has errors when giving input 0, so this is fixed!

Explanation:

# Preparation

  RrEEEEE # Stack r: [0, 1]

  REeE # Stack R: [input]

# Loop

  rREE # create label input (r flag: skip until REe)

    REEEEE # increment input (loop preparation)
    REE # create label input

      rEEEEEeEE # join all
      rEEEe # move r pointer to last
      reEE # output as int
      reeE # output newline "\n"
      rEEEEEeeE # increment all

    Ree # repeat if input != last content of stack
    rREE # create label input + 1 (r flag: skip until REe)
    REe # stop skipping commands

  Ree # if not 0, go to loop

u_ndefined

Posted 2018-07-03T23:48:31.700

Reputation: 1 253

0

Python 2, 42 bytes

I know there are plenty of shorter answers already.

a=0
exec"print`a`[:a]+`a+1`;a+=1;"*input()

Try it online!

mbomb007

Posted 2018-07-03T23:48:31.700

Reputation: 21 944

0

Kotlin, 43 bytes

Lambda takes an Int and returns a List<Int> representing the sequence.

{(1..it).mapIndexed{i,v->(""+i+v).toInt()}}

Explanation

{                                                   // lambda (Int) -> List<Int>
    (1..it)                                         // range from 1 to input
           .mapIndexed { i, v ->                    // map over "i"ndex and "v"alue
                                 (""+i+v)           // coerce to string and concat
                                         .toInt()}  // convert to int

Try it online!

snail_

Posted 2018-07-03T23:48:31.700

Reputation: 1 982

0

Microscript II, 16 bytes

1vsN-s{lPps1+v}*

Output is newline-separated.

SuperJedi224

Posted 2018-07-03T23:48:31.700

Reputation: 11 342

0

Gol><>, 11 bytes

IFLL?nLPN|;

Try it online!

Explanation:

IFLL?nLPN|;

I           //Take a number as input
 F          //Loop as many times as the input specified
  LL        //  Push the loop counter twice to the stack (same as L:)
    ?n      //  Check wether the count is zero, if not print the counter as the first digit
      LP    //  Push the loop counter and add 1
        N   //  Output the next digits of the number with nl
         |; //Exit code

Gegell

Posted 2018-07-03T23:48:31.700

Reputation: 81

0

jq, 30 characters

range(.)|"\(.)\(.+1)"|tonumber

Sample run:

bash-4.4$ jq 'range(.)|"\(.)\(.+1)"|tonumber' <<< 5
1
12
23
34
45

Try it online!

manatwork

Posted 2018-07-03T23:48:31.700

Reputation: 17 865

0

Dart, 46 45 bytes

f(n)=>List.generate(n,(e)=>e<1?1:'$e${e+1}');

  • -1 byte by replacing e==0 by e<1
  • Try it online!

    Elcan

    Posted 2018-07-03T23:48:31.700

    Reputation: 913