# Count up diagonally!

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

• Are leading spaces allowed, or does the first number have to be exactly on the left side of the screen? – Nathan.Eilisha Shiraini Jul 31 '17 at 9:51
• @NathanShiraini Leading newlines are allowed – Mr. Xcoder Jul 31 '17 at 9:52
• Related – Stephen Jul 31 '17 at 11:36
• @StepHen This one's a bit harder though, thanks for the reference. – Mr. Xcoder Jul 31 '17 at 11:40
• @Adnan You may have a leading newline or a consistent leading space on each line. – Mr. Xcoder Jul 31 '17 at 12:54

a%b=scanl((.show).(++).(' '<$))""[a..b]  Try it online! # 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


# Ruby, 18 bytes

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


Just for reference, but does not work on TIO:

Try it online!

# PowerShell, 49 bytes

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


Try it online!

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

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

# Tcl, 80 bytes

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


Try it online!

# 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. # 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.  • This is only 43 bytes. – 12Me21 Aug 2 '17 at 12:10 • Huh, you're right. Not sure how I miscounted there. – calc84maniac Aug 2 '17 at 12:54 # 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! # Perl 5, 4342 31 + 1 (-a) 0 = 43 31 bytes map{say$l=$l=~y// /cr.$_}<>..<>


Try it online!

# PHP 7.1, 66 bytes

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


Run with -nr or try them online.

# 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!

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


# 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

# 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


# 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. # ><>, 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-:?/~...


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