Count up diagonally!

30

3

We have lots of horizontal axis for numbers, but I honestly think they're kind of boring. Your task today is to build me a portion of a diagonal axis between two distinct non-negative integers given as input.

How to build a diagonal axis?

  • Let's take an example, with the input 0, 5. Our axis should look like this:

    0
     1
      2
       3
        4
         5
    
  • However, our axis should look nice for numbers that have more digits too! If the input is, for instance 0, 14, the new axis should be:

    0
     1
      2
       3
        4
         5
          6
           7
            8
             9
              10
                11
                  12
                    13
                      14
    
  • The idea is that the first digit of next number on the axis must always be placed exactly after the last digit of the previous number. To understand the idea even better, here is another example with 997, 1004:

    997
       998
          999
             1000
                 1001
                     1002
                         1003
                             1004
    

Rules

  • You may assume that input is in ascending or descending order (you may choose between 5,3 and 3,5).

  • You may also assume that the difference between the two integers is lower than 100.

  • You may have a leading newline or a consistent leading space (on each line). Trailing spaces / newlines are fine as well.

  • Default Loopholes are forbidden.

  • You can take input and provide output by any standard mean.

  • This is , so the shortest code in bytes in every language wins!


Other Test Cases

  • 1, 10:

    1
     2
      3
       4
        5
         6
          7
           8
            9
             10
    
  • 95, 103:

    95
      96
        97
          98
            99
              100
                 101
                    102
                       103
    
  • 999999, 1000009:

    999999
          1000000
                 1000001
                        1000002
                               1000003
                                      1000004
                                             1000005
                                                    1000006
                                                           1000007
                                                                  1000008
                                                                         1000009
    

Mr. Xcoder

Posted 2017-07-31T09:34:58.773

Reputation: 39 774

Are leading spaces allowed, or does the first number have to be exactly on the left side of the screen? – Nathan.Eilisha Shiraini – 2017-07-31T09:51:36.447

@NathanShiraini Leading newlines are allowed – Mr. Xcoder – 2017-07-31T09:52:51.900

Related – Stephen – 2017-07-31T11:36:22.633

@StepHen This one's a bit harder though, thanks for the reference. – Mr. Xcoder – 2017-07-31T11:40:43.983

Are leading spaces allowed? – Adnan – 2017-07-31T12:53:27.623

1@Adnan You may have a leading newline or a consistent leading space on each line. – Mr. Xcoder – 2017-07-31T12:54:08.603

Are trailing newlines/spaces allowed? – Titus – 2017-12-21T17:32:43.030

@Titus Yup, that is allowed. – Mr. Xcoder – 2017-12-21T17:49:38.427

Answers

19

05AB1E, 8 7 6 bytes

Thanks to Magic Octopus Urn for saving a byte!

It somehow works, but honestly I have no idea why.

Code

Ÿvy.O=

Uses the 05AB1E encoding. Try it online!

Explanation

Ÿ          # Create the range [a, .., b] from the input array
 vy        # For each element
   .O      #   Push the connected overlapped version of that string using the
                 previous version of that string. The previous version initially
                 is the input repeated again. Somehow, when the input array is
                 repeated again, this command sees it as 1 character, which gives
                 the leading space before each line outputted. After the first
                 iteration, it reuses on what is left on the stack from the
                 previous iteration and basically attaches (or overlaps) itself 
                 onto the previous string, whereas the previous string is replaced 
                 by spaces and merged into the initial string. The previous string
                 is then discarded. We do not have to worry about numbers overlapping 
                 other numbers, since the incremented version of a number never
                 overlaps entirely on the previous number. An example of 123 and 456:

                 123
                    456

                 Which leaves us "   456" on the stack.
     =     #   Print with a newline without popping

Adnan

Posted 2017-07-31T09:34:58.773

Reputation: 41 965

.O = pop a,b push connected_overlap(b) (deprecated) - Oh, I guess? – Magic Octopus Urn – 2017-07-31T14:49:19.010

@MagicOctopusUrn Yeah, .O is extremely buggy and deprecated for over a year so I have no idea what works and what doesn't. I could swear that I needed Î, but that suddenly doesn't seem to be the case anymore (?). Thanks! :) – Adnan – 2017-07-31T14:55:31.150

1Btw, the Î was needed to reduce the maximum number of leading spaces to 1. – Adnan – 2017-07-31T14:57:03.130

I... Wait... What, how...? – Magic Octopus Urn – 2017-07-31T15:31:35.260

I don't really understand how this works such that it is so short. Can you add an explanation (in case you understand your own answer)? – Mr. Xcoder – 2017-07-31T15:58:39.450

1@Mr.Xcoder added – Adnan – 2017-07-31T18:02:14.327

14

Python 2, 43 bytes

lambda a,b:'\v'.join(map(str,range(a,b+1)))

Makes use of vertical tab to make the ladder effect. The way thet \v is rendered is console dependent, so it may not work everywhere (like TIO).
running code

Rod

Posted 2017-07-31T09:34:58.773

Reputation: 17 588

Can you use a literal \x0b in your code to save a byte? – Dom Hastings – 2017-07-31T12:57:17.703

@DomHastings maybe, I don't know how though – Rod – 2017-07-31T13:12:16.827

I've just tested it and it appears to work. For getting the character into the file to test, I used Sublime Text and did a find and replace in regex mode for \\v and replaced with \x0B which shows up a VT character in its place for scoring you can either post a reversible hexdump (xxd or something) or just state that: "\v is a literal vertical tab", I think that would be fair. Hope that helps! – Dom Hastings – 2017-07-31T18:46:18.023

13

Charcoal, 9 8 bytes

F…·NN⁺¶ι

Try it online!

Link is to the verbose version of the code. Input in ascending order.

  • 1 byte saved thanks to ASCII-only!

Charlie

Posted 2017-07-31T09:34:58.773

Reputation: 11 448

Nice, Charcoal wins this again! – Mr. Xcoder – 2017-07-31T09:46:23.300

28 bytes – ASCII-only – 2017-07-31T10:35:26.567

EDIT: Charcoal got outgolfed... Wow – Mr. Xcoder – 2017-07-31T15:59:15.540

2@Mr.Xcoder at least I know how my answer works. :-D – Charlie – 2017-07-31T16:35:12.097

7

R, 70 69 61 bytes

function(a,b)for(i in a:b){cat(rep('',F),i,'
');F=F+nchar(i)}

Function that takes the start and end variable as arguments. Loops over the sequence, and prints each element, prepended with enough spaces. F starts as FALSE=0, and during each iteration, the amount of characters for that value is added to it. F decides the amount of spaces printed.

Try it online!

-8 bytes thanks to @Giuseppe

JAD

Posted 2017-07-31T09:34:58.773

Reputation: 2 898

I see 70 bytes there. Using scan() twice it can be reduced to 67 bytes for(i in scan():scan()){cat(rep(' ',F),i,'\n',sep='');F=F+nchar(i)}. – djhurio – 2017-07-31T10:35:41.330

Unfortunately you have to reset F, otherwise the function can be used only once in a new sessions. F=0;for(i in scan():scan()){cat(rep(' ',F),i,'\n',sep='');F=F+nchar(i)} (71 byte) – djhurio – 2017-07-31T10:43:31.067

@djhurio Inside a function, that is not necessary, since F is only modified in its own namespace. Also, I count 69 bytes, using nchar. – JAD – 2017-07-31T10:44:40.493

Yet manually counting I do get 70. This is weird... – JAD – 2017-07-31T10:47:23.717

You are right about the function. nchar('\n') == 1 ;) – djhurio – 2017-07-31T10:48:02.007

... that makes sense. sorta... – JAD – 2017-07-31T10:48:40.320

1But replacing \n for an actual newline works too, and that doesn't cost two bytes apparently. – JAD – 2017-07-31T10:50:06.120

61 bytes with the spec "consistent leading space" – Giuseppe – 2017-07-31T21:44:36.777

1Nice, I thought of abusing the automatic spacing of cat, but I couldn't think straight and figure it out for some reason. – JAD – 2017-08-01T06:33:24.410

@Giuseppe One more byte

– JayCe – 2018-06-07T15:59:10.103

6

Python 2, 58 54 bytes

def f(a,b,s=''):print s;b<a or f(a+1,b,' '*len(s)+`a`)

Try it online!

Arfie

Posted 2017-07-31T09:34:58.773

Reputation: 1 230

Wow, surprising recursive solution and out-golfs most python answers, +1. – officialaimm – 2017-07-31T10:58:53.857

Very good job Ruud, your solution is also OS and console-independent by not using the vertical tab character like Rod did. – Raphaël Côté – 2017-08-02T17:03:36.867

6

C#, 90 89 85 bytes

s=>e=>{var r="";for(int g=0;e>s;g+=(s+++"").Length)r+="".PadLeft(g)+s+"\n";return r;}

Saved 1 byte thanks to @LiefdeWen.
Saved 4 bytes thanks to @auhmaan.

Try it online!

Full/Formatted version:

namespace System
{
    class P
    {
        static void Main()
        {
            Func<int, Func<int, string>> f = s => e =>
            {
                var r = "";
                for (int g = 0; e > s; g += (s++ + "").Length)
                    r += "".PadLeft(g) + s + "\n";

                return r;
            };

            Console.WriteLine(f(0)(5));
            Console.WriteLine(f(0)(14));
            Console.WriteLine(f(997)(1004));
            Console.WriteLine(f(1)(10));
            Console.WriteLine(f(95)(103));
            Console.WriteLine(f(999999)(1000009));

            Console.ReadLine();
        }
    }
}

TheLethalCoder

Posted 2017-07-31T09:34:58.773

Reputation: 6 930

1+1, now you don't have 5k precisely ;D – Mr. Xcoder – 2017-07-31T11:22:27.743

1 byte at i<=e to e>i – LiefdeWen – 2017-07-31T11:41:19.867

@LiefdeWen Thanks :) – TheLethalCoder – 2017-07-31T11:46:38.583

I believe you can save more 4 bytes by removing the i and reusing the s instead – auhmaan – 2017-07-31T12:22:48.873

@auhmaan Thanks don't know why I never think of using the input variable. – TheLethalCoder – 2017-07-31T12:25:12.437

6

Mathematica, 59, bytes

Grid[(DiagonalMatrix@Range[1+##]/. 0->""+1)-1,Spacings->0]&

input

[10,15]

-3 bytes @JungHwanMin
problem with 0 fixed (see comments for details)
thanx to @ngenisis

J42161217

Posted 2017-07-31T09:34:58.773

Reputation: 15 931

1Wow, an answer that actually contains the word Diagonal – Mr. Xcoder – 2017-07-31T13:44:10.040

You need to add Spacings -> 0 if you want this to be character-exact. – Mr.Wizard – 2017-07-31T22:31:56.900

The input is only non-negative, not guaranteed to be positive. – user202729 – 2017-08-01T04:51:45.573

Grid[(DiagonalMatrix@Range[1+##]/. 0->""+1)-1,Spacings->0]& is the shortest way I could find to fix those problems – ngenisis – 2017-08-02T22:51:24.963

5

Jelly, 9 bytes

rD⁶ṁ$;¥\Y

Try it online!

Leaky Nun

Posted 2017-07-31T09:34:58.773

Reputation: 45 011

5

C, 166 134 95 82 Bytes

New Answer

Just as a function not as a whole program.

f(a,b){int s=0,i;while(a<=b){i=s;while(i--)printf(" ");s+=printf("%i\n",a++)-1;}}

Thanks to Falken for helping knock off 13 Bytes (and fix a glitch)!

Thanks to Steph Hen for helping knock off 12 Bytes!

Thanks to Zacharý for help knock off 1 Byte!

Old Answers

Got rid of the int before main and changed const char*v[] to char**v and got rid of return 0;

main(int c,char**v){int s=0;for(int a=atoi(v[1]);a<=atoi(v[2]);a++){for(int i=0;i<s;i++)printf(" ");printf("%i\n",a);s+=log10(a)+1;}}


int main(int c,const char*v[]){int s=0;for(int a=atoi(v[1]);a<=atoi(v[2]);a++){for(int i=0;i<s;i++)printf(" ");printf("%i\n",a);s+=log10(a)+1;}return 0;}

This is my first time golfing and I wanted to try something in C. Not sure if I formatted this correctly, but I had fun making it!

int main(int c, const char * v[]) {
    int s = 0;
    for(int a=atoi(v[1]); a<=atoi(v[2]); a++) {
        for(int i=0; i<s; i++) printf(" ");
        printf("%i\n",a);
        s += log10(a)+1;
    }
    return 0;
}

Explanation

int s = 0; // Number of spaces for each line

for(int a=atoi(argv[1]); a<=atoi(argv[2]); a++) { // Loop thru numbers

for(int i=0; i<s; i++) printf(" "); // Add leading spaces

printf("%i\n",a); // Print number

s += log10(a)+1; // Update leading spaces

Usage

enter image description here

Asleepace

Posted 2017-07-31T09:34:58.773

Reputation: 311

Welcome to PPCG! I believe you can rename argc and argv to one letter variables. – Stephen – 2017-08-01T00:14:27.017

I think you can move the int s=0 to the for loop, as in for(int s=0;a<=b;a++). – Zacharý – 2017-08-01T13:29:46.660

Ahh your right thanks, I updated the post! – Asleepace – 2017-08-01T17:58:41.453

Using int i=s;while(i--) instead of for(int i=0;i<s;i++) for the inner loop will save two bytes. – Falken – 2017-08-02T10:25:39.663

Also, it looks like this fails if the starting number is zero. Fortunately that can be fixed and the code can be made even shorter by using the return value of printf, like so: s+=printf("%i\n",a)-1; – Falken – 2017-08-02T10:33:34.400

Last one: both s and i can be combined into a single int declaration, saving two more bytes. Here's the final code: f(a,b){int s=0,i;while(a<=b){i=s;while(i--)printf(" ");s+=printf("%i\n",a++)-1;}} – Falken – 2017-08-02T10:42:55.537

1Ahhh your right forgot about log10 on 0 and negatives, I've updated the solution thanks! – Asleepace – 2017-08-02T20:31:57.987

55 bytes – ceilingcat – 2019-11-12T21:22:45.730

5

Mathematica, 48 bytes

Rotate[""<>Table[ToString@i<>" ",{i,##}],-Pi/4]&

since there are so many answers, I thought this one should be included

input

[0,10]

output
enter image description here

J42161217

Posted 2017-07-31T09:34:58.773

Reputation: 15 931

1This isn't valid, is it? But +1 just for taking the title literally. – Zacharý – 2017-08-01T13:45:13.893

4

Retina, 81 78 bytes

.+
$*
+`\b(1+)¶11\1
$1¶1$&
1+
$.& $.&
 (.+)
$.1$* 
+1`( *)(.+?)( +)¶
$1$2¶$1$3

Try it online! Takes input as a newline-separated list of two integers. Edit: Saved 3 bytes by stealing the range-expansion code from my answer to Do we share the prime cluster? Explanation:

.+
$*

Convert both inputs to unary.

+`\b(1+)¶11\1
$1¶1$&

While the last two elements (a, b) of the list differ by more than 1, replace them with (a, a+1, b). This expands the list from a tuple into a range.

1+
$.& $.&

Convert back to decimal in duplicate.

 (.+)
$.1$* 

Convert the duplicate copy to spaces.

+1`( *)(.+?)( +)¶
$1$2¶$1$3

Cumulatively sum the spaces from each line to the next.

Neil

Posted 2017-07-31T09:34:58.773

Reputation: 95 035

4

APL (Dyalog), 25 24 bytes

-1 thanks to Zacharý.

Assumes ⎕IO←0 for zero based counting. Takes the lower bound as left argument and the upper bound as right argument.

{↑⍵↑⍨¨-+\≢¨⍵}(⍕¨⊣+∘⍳1--)

Try it online!

() apply the following tacit function between the arguments:

- subtract the upper lower from the upper bound

1- subtract that from one (i.e. 1 + ∆)

⊣+∘⍳ left lower bound plus the integers 0 through that

⍕¨ format (stringify) each

{} apply the following anonymous on that (represented by ⍵):

≢¨ length of each (number)

+\ cumulative sum

- negate

⍵↑⍨¨ for each stringified number, take that many characters from the end (pads with spaces)

 mix list of strings into character matrix

Adám

Posted 2017-07-31T09:34:58.773

Reputation: 37 779

Could +-⍨ be --? – Zacharý – 2017-07-31T11:46:57.747

@Zacharý Yes, of course. Thanks. – Adám – 2017-07-31T11:47:25.757

4

C++, 167 165 bytes

-2 bytes thanks to Zacharý

#include<string>
#define S std::string
S d(int l,int h){S r;for(int m=0,i=l,j;i<=h;){for(j=0;j<m;++j)r+=32;S t=std::to_string(i++);r+=t;r+=10;m+=t.size();}return r;}

HatsuPointerKun

Posted 2017-07-31T09:34:58.773

Reputation: 1 891

>

  • Could you move the int m=0,i=l,j to the first for loop to save a byte? 2. Can you change r+=t;r+=10 to r+=t+10? 3. I beat someone, yay.
  • < – Zacharý – 2017-07-31T13:05:28.570

    @Zacharý I can do r+=t+=10 but not r+=t+10, it gave me an error – HatsuPointerKun – 2017-07-31T13:13:12.990

    But r+=t+=10 does work? Wouldn't that affect t.size()? – Zacharý – 2017-07-31T13:14:18.720

    @Zacharý Yes, it works, with only +, it says it can't find an overload with int as parameter, but with += it uses the overload with the char – HatsuPointerKun – 2017-07-31T13:21:27.490

    Oh, could you move the ++i to the std::to_string(i) as std::to_string(i++) to save one more byte? – Zacharý – 2017-07-31T13:34:46.587

    3

    Python 2, 65 63 62 61 bytes

    -2 bytes Thanks to @Mr. Xcoder: exec doesn't need braces

    -1 bye thanks to @Zacharý: print s*' ' as print' '*s

    def f(m,n,s=0):exec(n-m+1)*"print' '*s+`m`;s+=len(`m`);m+=1;"
    

    Try it online!

    officialaimm

    Posted 2017-07-31T09:34:58.773

    Reputation: 2 739

    1You do not need the braces for exec. m,n=input();s=0;exec(n-m+1)*"print s*' '+`m`;s+=len(`m`);m+=1;" suffices. – Mr. Xcoder – 2017-07-31T10:03:28.463

    1I think you can change print s*' ' to print' '*s to save one byte. – Zacharý – 2017-08-01T13:35:43.253

    3

    Pyth, 14 13 bytes

    V}FQ
    =k+*dlkN
    

    Try it online!

    Leaky Nun

    Posted 2017-07-31T09:34:58.773

    Reputation: 45 011

    3

    LOGO, 53 bytes

    [for[i ? ?2][repeat ycor[type "\ ]pr :i fd count :i]]
    

    There is no "Try it online!" link because all online LOGO interpreter does not support template-list.

    That is a template-list (equivalent of lambda function in other languages).

    Usage:

    apply [for[i ? ?2][repeat ycor[type "\ ]pr :i fd count :i]] [997 1004]
    

    (apply calls the function)

    will print

    997
       998
          999
             1000
                 1001
                     1002
                         1003
                             1004
    

    Note:

    This uses turtle's ycor (Y-coordinate) to store the number of spaces needed to type, therefore:

    • The turtle need to be set to home in its default position and heading (upwards) before each invocation.
    • window should be executed if ycor gets too large that the turtle moves off the screen. Description of window command: if the turtle is asked to move past the boundary of the graphics window, it will move off screen., unlike the default setting wrap, which if the turtle is asked to move past the boundary of the FMSLogo screen window, it will "wrap around" and reappear at the opposite edge of the window.

    Explanation:

    for[i ? ?2]        Loop variable i in range [?, ?2], which is 2 input values
    repeat ycor        That number of times
    type "\            space character need to be escaped to be typed out.
    pr :i              print the value of :i with a newline
    fd count :i        increase turtle's y-coordinate by the length of the word :i. (Numbers in LOGO are stored as words)
    

    user202729

    Posted 2017-07-31T09:34:58.773

    Reputation: 14 620

    3

    Japt, 12 bytes

    òV
    £¯Y ¬ç +X
    

    Takes input in either order and always returns the numbers in ascending order, as an array of lines.

    Try it online! with the -R flag to join the array with newlines.

    Explanation

    Implicit input of U and V.

    òV
    £
    

    Create inclusive range [U, V] and map each value to...

    ¯Y ¬ç
    

    The values before the current (¯Y), joined to a string (¬) and filled with spaces (ç).

    +X
    

    Plus the current number. Resulting array is implicitly output.

    Justin Mariner

    Posted 2017-07-31T09:34:58.773

    Reputation: 4 746

    3

    JavaScript (ES8), 69 67 62 bytes

    Takes input as integers, in ascending order, using currying syntax. Returns an array of strings.

    x=>y=>[...Array(++y-x)].map(_=>s="".padEnd(s.length)+x++,s="")
    

    Try it

    o.innerText=(f=
    
    x=>y=>[...Array(++y-x)].map(_=>s="".padEnd(s.length)+x++,s="")
    
    )(i.value=93)(j.value=105).join`\n`
    oninput=_=>o.innerText=f(Math.min(i.value,j.value))(Math.max(i.value,j.value)).join`\n`
    label,input{font-family:sans-serif}input{margin:0 5px 0 0;width:100px;}
    <label for=i>x: </label><input id=i type=number><label for=j>y: </label><input id=j type=number><pre id=o>

    Shaggy

    Posted 2017-07-31T09:34:58.773

    Reputation: 24 623

    3

    05AB1E, 8 bytes

    Ÿʒ¾ú=þv¼
    

    Try it online!

    -2 thanks to Adnan.

    Erik the Outgolfer

    Posted 2017-07-31T09:34:58.773

    Reputation: 38 134

    Ahh, that is very clever. You can replace vy by ʒ and gF by v to save 2 bytes. – Adnan – 2017-07-31T13:18:35.190

    @Adnan I didn't expect the good old ʒ trick to still be used... – Erik the Outgolfer – 2017-07-31T13:21:18.413

    2

    C (gcc), 41 38 bytes

    -3 bytes Thanks to ASCII-only

    t(x,v){while(x<=v)printf("%d\v",x++);}
    

    Works on RedHat6, accessed via PuTTY

    Proof

    Try it online!

    Giacomo Garabello

    Posted 2017-07-31T09:34:58.773

    Reputation: 1 419

    1This doesn't produce correct output. – Erik the Outgolfer – 2017-07-31T09:50:36.047

    it's tricky, output to a file and then use more on that file – Giacomo Garabello – 2017-07-31T09:51:14.407

    2@GiacomoGarabello You must provide the full code in order for us to be able to run your program. If you do not provide a working test ground / do not provide instructions on how to run your program such that it produces correct output, please delete this answer. – Mr. Xcoder – 2017-07-31T09:56:31.423

    Linefeed may return to begin of line, it depends. This does work when it does not. – user202729 – 2017-07-31T10:04:12.420

    @Mr.Xcoder Edited – Giacomo Garabello – 2017-07-31T10:04:23.213

    @user202729 char11 is vertical Tab – Giacomo Garabello – 2017-07-31T10:04:54.143

    Ok, I don't remember ASCII. printf("%d\xB",x++) should work and save some bytes. – user202729 – 2017-07-31T10:06:50.637

    38 bytes – ASCII-only – 2017-07-31T10:38:36.950

    printf("%d\v",x++) should also save one more byte – Nahuel Fouilleul – 2017-07-31T10:50:34.993

    @ASCII-only thanks! – Giacomo Garabello – 2017-07-31T12:14:32.617

    Can you use a literal \x0b in your code to save another byte? – Dom Hastings – 2017-07-31T12:56:58.477

    2

    Python 2, 78 77 79 bytes

    def f(a,b):
     for i in range(a,b+1):print sum(len(`j`)for j in range(i))*' '+`i`
    

    Try it online!

    f(A, B) will print the portion of the axis between A and B inclusive.

    First time I answer a challenge!

    Uses and abuses Python 2's backticks to count the number of spaces it has to add before the number.

    -1 byte thanks to Mr.Xcoder

    +2 because I forgot a +1

    Nathan.Eilisha Shiraini

    Posted 2017-07-31T09:34:58.773

    Reputation: 561

    4Welcome to PPCG! nice first answer. sum(len(`j`)) for can become sum(len(`j`)for, -1 bytes – Mr. Xcoder – 2017-07-31T10:01:18.327

    1To make this answer valid, you must replace range(a,b) with range(a,b+1), because Python has semi inclusive ranges. – Mr. Xcoder – 2017-07-31T10:02:31.333

    Indeed, I missed that. What's more surprising is that I did add that +1 when I made my tests! No wonder I had 2 bytes missing when I typed it into TiO... – Nathan.Eilisha Shiraini – 2017-07-31T10:05:04.363

    2

    JavaScript, 57 bytes

    f=(x,y,s='')=>y>=x?s+`
    `+f(x+1,y,s.replace(/./g,' ')+x):s
    

    tsh

    Posted 2017-07-31T09:34:58.773

    Reputation: 13 072

    55 bytes: y=>g=(x,s='')=>y<x?s:s+'\n'+g(x+1,s.replace(/./g,' ')+x) Call with currying with the integers reversed: f(103)(95). – Shaggy – 2017-07-31T10:09:49.783

    54 bytes: x=>y=>g=(s='')=>y<x?s:s+'\n'+g(s.replace(/./g,' ')+x++) Call as f(x)(y)(). – Shaggy – 2017-07-31T12:16:17.563

    2

    Python 2, 60 59 bytes

    -1 byte thanks to Mr.Xcoder for defining my s=0 as an optional variable in my function.

    def f(l,u,s=0):
     while l<=u:print' '*s+`l`;s+=len(`l`);l+=1
    

    Try it online!

    I think it is possible to transfer this into a lambda version, but I do not know how. I also think that there is some sort of mapping between the spaces and the length of the current number, but this I also did not figure out yet. So I think there still is room for improvement.

    What i did was creating a range from the lowerbound lto the upper bound u printing each line with a space multiplied with a number s. I am increasing the multiplier with the length of the current number.

    Simon

    Posted 2017-07-31T09:34:58.773

    Reputation: 111

    59 bytes – Mr. Xcoder – 2017-07-31T10:17:45.133

    Alternative 59 bytes – Mr. Xcoder – 2017-07-31T10:19:44.140

    I'll figure out you did with that "exec"-version later this day. Maybe it will help me in future codings. Thanks – Simon – 2017-07-31T10:25:28.413

    Lambda version, 62 bytes – ASCII-only – 2017-07-31T11:41:56.750

    2

    MATL, 11 bytes

    vii&:"t~@Vh
    

    Try it online!

    Explanation

    This works by generating a string for each number and concatenating it with a logically-negated copy of the previous string. Thus char 0 is prepended 0 as many times as the length of the previous string. Char 0 is displayed as a space, and each string is displayed on a different line

    v       % Concatenate stack (which is empty): pushes []
    ii      % Input two numbers
    &:      % Range between the two numbers
    "       % For each
      t     %   Duplicate
      ~     %   Logical negation. This gives a vector of zeros
      @     %   Push current number
      V     %   Convert to string
      h     %   Concatenate with the vector of zeros, which gets automatically 
            %   converted into chars.
            % End (implicit). Display stack (implicit), each string on a diferent
            % line, char 0 shown as space
    

    Luis Mendo

    Posted 2017-07-31T09:34:58.773

    Reputation: 87 464

    2

    D, 133 127 126 125 121 119 bytes

    import std.conv,std.stdio;void f(T)(T a,T b,T s=0){for(T j;j++<s;)' '.write;a.writeln;if(a-b)f(a+1,b,s+a.text.length);}
    

    Jelly and APL were taken.

    Try it online!

    If you're fine with console-dependent results (goes off the same principle as Giacomos's C answer) here's one for 72 71 bytes:

    import std.stdio;void f(T)(T a,T b){while(a<=b){a++.write;'\v'.write;}}
    

    How? (Only D specific tricks)

    • f(T)(T a,T b,T s=0) D's template system can infer types
    • for(T j;j++<s;) Integers default to 0.
    • ' '.write;a.writeln D lets you call fun(arg) like arg.fun (one of the few golfy things D has)
    • a.text.length Same as above, and D also allows you to call a method with no parameters as if it was a property (text is conversion to string)
    • One thing that might be relevant (I didn't use this though) newlines can be in strings!

    Zacharý

    Posted 2017-07-31T09:34:58.773

    Reputation: 5 710

    2

    V, 16 bytes

    ÀñÙywÒ $pça/jd
    

    Try it online!

    This would be way easier if I could take start end - start but I think that's changing the challenge a bit too much.

    This takes the start number as input in the buffer and the end number as an argument. It actually creates the ladder from start to start + end and then deletes everything after the end number.

    nmjcman101

    Posted 2017-07-31T09:34:58.773

    Reputation: 3 274

    2

    Perl, 19 bytes

    Note: \x0b is counted as one byte.

    Along with others, I thought using cursor movements would be the shortest route, this does mean it doesn't work on TIO:

    print"$_\x0b"for<>..<>
    

    Usage

    perl -e 'print"$_\x0b"for<>..<>' <<< '5
    10'
    5
     6
      7
       8
        9
         10
    

    Dom Hastings

    Posted 2017-07-31T09:34:58.773

    Reputation: 16 415

    Nice, haven't seen Perl at all in a while. Could you add a testing link? Additionally, I was wondering what the 1.. does there, since you are given two integers. – Mr. Xcoder – 2017-07-31T12:57:25.453

    @Mr.Xcoder Yeah, 1.. was me not fully reading the spec, that's fixed now! As for testing it online, because the output contains the vertical tab, it doesn't render as expected. Trying to see if I can find a renderer that does support control chars... If not, that might be my new project! – Dom Hastings – 2017-07-31T13:07:25.073

    2

    Swift 4, 115 bytes

    I think nobody would have posted a Swift solution anyway...

    func f(l:Int,b:Int){for i in l...b{print(String(repeating:" ",count:(l..<i).map{String($0).count}.reduce(0,+)),i)}}
    

    Try it online!

    Mr. Xcoder

    Posted 2017-07-31T09:34:58.773

    Reputation: 39 774

    2

    Japt, 10 9 bytes

    òV åÈç +Y
    

    Test it online! Returns an array of lines; -R flag included to join on newlines for easier viewing.

    Explanation

     òV åÈ   ç +Y
    UòV åXY{Xç +Y}   Ungolfed
                     Implicit: U, V = inputs, P = empty string
    UòV              Create the range [U, U+1, ..., V-1, V].
        åXY{     }   Cumulative reduce: Map each previous result X and current item Y to:
            Xç         Fill X with spaces.
               +Y      Append Y.
                     Implicit: output result of last expression
    

    Old version, 10 bytes:

    òV £P=ç +X
    

    Test it online!

     òV £  P= ç +X
    UòV mX{P=Pç +X}  Ungolfed
                     Implicit: U, V = inputs, P = empty string
    UòV              Create the range [U, U+1, ..., V-1, V].
        mX{       }  Map each item X to:
             Pç        Fill P with spaces.
                +X     Append X.
           P=          Re-set P to the result.
                       Implicitly return the same.
                     Implicit: output result of last expression
    

    ETHproductions

    Posted 2017-07-31T09:34:58.773

    Reputation: 47 880

    Dang, I had just come up with the same solution as an improvement to my own answer. – Justin Mariner – 2017-07-31T17:33:02.910

    2

    Java 8, 79 bytes

    (a,b)->{for(String s="";a<=b;System.out.printf("%"+s.length()+"d\n",a++))s+=a;}
    

    Try it online!

    Justin Mariner

    Posted 2017-07-31T09:34:58.773

    Reputation: 4 746

    You can save a byte by changing (a,b)-> to b->a->. (And you could save three more bytes by going to Java 10 and changing String to var.) Try it online.

    – Kevin Cruijssen – 2018-06-06T09:31:17.813

    2

    Haskell, 39 bytes

    a%b=scanl((.show).(++).(' '<$))""[a..b]
    

    Try it online!

    xnor

    Posted 2017-07-31T09:34:58.773

    Reputation: 115 687

    1

    QBIC, 25 bytes

    [:,:|A=space$(_lA|)+!a$?A
    

    Explanation:

    [:     FOR a = <input 1 from cmd line>
    ,:|    TO <input 2 from cmd line>
    A=         SET A$ to 
     space$      a number of spaces equal to 
     (_lA|)      the current length of A$ (starts as "" = 0)
    +!a$         and add a cast-to string of the current loop iterator
    ?A     PRINT A$
               Loop auto-closed by QBIC
    

    steenbergh

    Posted 2017-07-31T09:34:58.773

    Reputation: 7 772

    1

    Ruby, 18 bytes

    ->a,b{[*a..b]*?\v}
    

    Just for reference, but does not work on TIO:

    Try it online!

    G B

    Posted 2017-07-31T09:34:58.773

    Reputation: 11 099

    1

    PowerShell, 49 bytes

    $a,$b=$args;$a..$b|%{$l=($z=" "*$l+$_).length;$z}
    

    Try it online!

    Takes input as two command-line arguments, $a and $b, forms a range .. out of them, then loops |%{} over that range. Each iteration, we construct a string $z of a certain number of spaces " "*$l concatenated with our current number $_. We then pull out the .length of that, re-store it into $l for next time, and leave $z on the pipeline. Output is implicit.

    AdmBorkBork

    Posted 2017-07-31T09:34:58.773

    Reputation: 41 581

    1

    Bash + coreutils, 10

    seq -s^K $@
    

    Here ^K is a literal vertical tab and control character. The xxd dump of this script is as follows - use xxd -r to regenerate the actual script:

    00000000: 7365 7120 2d73 0b20 2440                 seq -s. $@
    

    Input range is given as two integers at the command-line.

    Not sure if much of an explanation is needed here - seq simply does the counting (from a to b, passed in the $@ parameter), with -s specifying the separator as a vertical tab. This causes the next number to be printed after the previous one, down one line, as required.

    Digital Trauma

    Posted 2017-07-31T09:34:58.773

    Reputation: 64 644

    1

    Haskell, 46 bytes

    a%b=[([a..x-1]>>=show>>" ")++show x|x<-[a..b]]
    

    Try it online! Usage: 0%20. Returns a list of lines. Use putStr . unlines $ 0%20 for pretty-printing.

    Laikoni

    Posted 2017-07-31T09:34:58.773

    Reputation: 23 676

    1

    dc, 51 bytes

    sj0skp[32Plkll1+dsl<S]sS[0sldZlk+sklSx1+pdlj>M]dsMx
    

    Try it online!

    This pretty much has to be suboptimal, my brain is clearly still in Monday mode. Pretty much just macro S printing spaces, and macro M doing the rest of the work. Register l restarts at zero spaces before running S, and compares against register k, which we always increment by the number of digits of top-of-stack.

    brhfl

    Posted 2017-07-31T09:34:58.773

    Reputation: 1 291

    1

    Perl 5, 43 42 31 + 1 (-a) 0 = 43 31 bytes

    map{say$l=$l=~y// /cr.$_}<>..<>
    

    Try it online!

    Xcali

    Posted 2017-07-31T09:34:58.773

    Reputation: 7 671

    1

    WendyScript, 50 bytes

    <<f=>(x,y){<<s=""#i:x->y+1{s+i#i!=0{s+=" "i\=10}}}
    
    f(95, 103)
    

    Try it online!

    Only issue is once you get past 100000, numbers are outputted in scientific notation (which I should probably change to always display in full form). The online syntax highlighter also dislikes "" but it is parsed correctly.

    Felix Guo

    Posted 2017-07-31T09:34:58.773

    Reputation: 211

    1

    Tcl, 80 bytes

    proc P a\ b {while \$a<=$b {puts [format %[incr i [string len $a]]d $a];incr a}}
    

    Try it online!

    sergiol

    Posted 2017-07-31T09:34:58.773

    Reputation: 3 055

    1

    SmileBASIC, 43 bytes

    INPUT A,B
    FOR I=A TO B?" "*C;I;
    C=CSRX?NEXT
    

    Explanation

    ?" "*C;I;    'Print C (initially 0) spaces followed by I, with no newline.
    C=CSRX       'Set C to the horizontal cursor position.
    ?            'Print a newline.
    

    calc84maniac

    Posted 2017-07-31T09:34:58.773

    Reputation: 165

    This is only 43 bytes. – 12Me21 – 2017-08-02T12:10:57.587

    Huh, you're right. Not sure how I miscounted there. – calc84maniac – 2017-08-02T12:54:31.823

    1

    SNOBOL4 (CSNOBOL4), 85 bytes

    	M =INPUT
    	N =INPUT
    O	OUTPUT =S M
    	S =S DUPL(' ',SIZE(M))
    	M =LT(M,N) M + 1 :S(O)
    END
    

    Try it online!

    Giuseppe

    Posted 2017-07-31T09:34:58.773

    Reputation: 21 077

    1

    PHP 7.1, 66 bytes

    for([,$i,$z]=$argv;$i<=$z;)printf("%".($e+=strlen($i))."d
    ",$i++);
    

    Run with -nr or try them online.

    Titus

    Posted 2017-07-31T09:34:58.773

    Reputation: 13 814

    0

    Python 3, 85 bytes

    f=lambda a,b,n,z:'\n'+' '*(a+n-z)+str(a)+f(a+1,b,n+len(str(a))-1,z) if a!=b+1 else ''
    

    Try it online!

    Kavi

    Posted 2017-07-31T09:34:58.773

    Reputation: 31

    0

    K3, 29 bytes

    {`0:{(1_0+\#:'$:'x)$'x}x+!y-x}
    

    example:

      {`0:{(1_0+\#:'$:'x)$'x}x+!y-x}[1;15]
    1
     2
      3
       4
        5
         6
          7
           8
            9
             10
               11
                 12
                   13
                     14
    

    tangentstorm

    Posted 2017-07-31T09:34:58.773

    Reputation: 111

    0

    JavaScript (ES6) + CSS, 72 + 12 = 84 bytes

    a=>b=>{for(i=0;a<=b;)document.write(`<x>${"<br>".repeat(i++)+a++}</x>`)}
    
    x{float:left
    

    Takes input in currying syntax with the smaller number first. Outputs the result to the page in HTML.

    Test Snippet

    let f=
    
    a=>b=>{for(i=0;a<=b;)document.write(`<x>${"<br>".repeat(i++)+a++}</x>`)}
    
    f(0)(8)
    f(5)(14)
    f(998)(1003)
    x{float:left

    Justin Mariner

    Posted 2017-07-31T09:34:58.773

    Reputation: 4 746

    0

    Excel VBA, 41 Bytes

    Anonymous VBE immediate window function that takes input from range A1:B1 and outputs to the VBE immediate window

    For i=[A1]To[B1]:?spc(j)i:j=j+len(i):Next
    

    Taylor Scott

    Posted 2017-07-31T09:34:58.773

    Reputation: 6 709

    0

    Sinclair ZX81/Timex TS1000/1500 BASIC ~73 tokenized BASIC bytes

     1 LET X=SGN PI
     2 LET Y=CODE "="
     3 LET A=NOT PI
     4 FOR I=X TO Y
     5 PRINT TAB A;I
     6 LET A=A+LEN STR$ I
     7 NEXT I
    

    This newer solution has fewer bytes but slightly slower. SGN PI is 1, CODE "=" is 20 and NOT PI is 0; the PRINT TAB command does what you might expect, except a TAB in ZX81 land is 1 space; A is increased by the length of the I variable once converted to a string.

    Old answer (~98 tokenized bytes)

     1 LET X=1
     2 LET Y=20
     3 LET A$=""
     4 FOR I=X TO Y
     5 PRINT A$;I
     6 FOR T=1 TO LEN STR$ I
     7 LET A$=A$+" "
     8 NEXT T
     9 NEXT I
    

    I'm using the most expensive methods here in terms of bytes (i.e., SGN PI is 1, and counts as two bytes in ZX81 land, whereas 1 counts as four bytes), so I could cut the byte count by increasing the typing and making the listing less readable, and slower.

    The 'spacing' works by converting the I number to a string and taking the string literal length, using that in a FOR/NEXT loop as the destination [line 6]. X is the start number, and Y is the end number.

    There are a few limitations to consider, such as only having a 32 columns display by default, and only allowing 22 rows without some POKEing. Also, the screen doesn't scroll when it is full unless you tell it to, with the command SCROLL.

    enter image description here

    Shaun Bebbers

    Posted 2017-07-31T09:34:58.773

    Reputation: 1 814

    0

    ><>, 56+3 = 59 bytes

    1</+1$,a\.0e:/o" "\
    :1>$:a)?/~}r+\1-:?/~r:n&:&:&=?;&1+ao
    

    Try It Online

    +3 bytes for -v. Not sure whether I actually need to add this for a function, but better to err on the side of caution

    How It Works

    1<................\     Initialises the stack with the space counter on top of the inputted numbers
    ................../~...
    
    ...................                  Print the first number
    ....................r:n&:&:&=?;&1+ao If the first number is equal to the end, exit program. Otherwise increment the first number and print a newline
    
    ../+1$,a\... Count the number of digits in the number
    :1>$:a)?/... By incrementing a counter and dividing the number by 10 until it's below 10
    
    ........\.0e:/... Add the amount of digits to the counter
    .......?/~}r+\...
    
    ............./o" "\     Print the counter amount of spaces and loop around again
    .............\1-:?/~...
    

    Jo King

    Posted 2017-07-31T09:34:58.773

    Reputation: 38 234

    0

    NotQuiteThere, 5 bytes

    yr-11
    

    Try it online!

    Uses the vertical tab trick in Rod's python answer, so doesn't really work on TIO. Input is taken in descending order (11, 7)

    caird coinheringaahing

    Posted 2017-07-31T09:34:58.773

    Reputation: 13 702