39
\$\begingroup\$

Introduction

It may sound strange, but we haven't got ONE challenge for counting from 1 to n, inclusive.

This is not the same thing. That one is a (closed) not well-explained challenge.
This is not the same thing. That one is about counting up indefinitely.

Challenge

Write a program or function that prints every integer from 1 to n inclusive.

Rules

  • You can get n any way.
  • You can assume that n will always be a positive integer.
  • You can get n in any base, but you should always output in decimal.
  • Output must be separated by any character (or pattern) not in 0123456789. Non-decimal leading or trailing characters are allowed (for example when using arrays such as [1, 2, 3, 4, 5, 6]).
  • Standard loopholes are denied.
  • We want to find the shortest approach in each language, not the shortest language, so I will not accept any answer.
  • You must update your answer(s) after this edit, answers posted before the last edit must comply with the change rule about standard loopholes (I didn't want to deny them, but I didn't want to make the community roar, so I denied them).
  • You can use any post-dating language version (or language). You cannot use any language or language version made just for this challenge.

Bonuses

20%

  • Your program must be able to count at least up to 18446744073709551615 (2^64-1). For example, if a new datatype is the only way to support big integers, you must construct it. If your language does not have any way to support huge integers up to 2^64-1, the upper limit of that particular language must be supported instead.

EDIT: I've changed the limit from 2^64 to 2^64-1 to allow more answers.

EDIT: I made the 2^64-1 rule a bonus, since there has not been much interest in this challenge. If your answer supports 2^64-1, you can now edit it to include the bonus. Also, you can post an answer not supporting it, if it is shorter.

\$\endgroup\$
11
  • 7
    \$\begingroup\$ Related. \$\endgroup\$ Commented Apr 25, 2016 at 12:20
  • \$\begingroup\$ "You can get n any way." Does that mean we can assume n to be saved in a variable? \$\endgroup\$
    – flawr
    Commented May 21, 2016 at 20:50
  • \$\begingroup\$ @flawr You can get n any way. You can save it in a variable, but it must not be hardcoded. \$\endgroup\$ Commented May 22, 2016 at 10:26
  • \$\begingroup\$ It might be useful to link to the accepted I/O methods \$\endgroup\$
    – Ephphatha
    Commented Jun 2, 2017 at 12:26
  • \$\begingroup\$ @Ephphatha Yes it probably is, this challenge is from the old times where I was an utter newb. \$\endgroup\$ Commented Jun 2, 2017 at 12:29

145 Answers 145

1
2 3 4 5
67
\$\begingroup\$

MarioLANG, 29 bytes

;
)    <
+===="
>:(-[!
=====#

Try it online!

I know my code is sadly super-sad or angry:




>:(

Happy MarioLANG, 46 bytes

;
)       <
+======="
>  >((-[!
=:)^====#
 ===

Try it online!

A happier approach:





 :)

Non-emotional MarioLANG, 41 bytes

;
)     <
+====="
> >(-[!
= "===#
 :!
 =#

Try it online!

\$\endgroup\$
3
  • 1
    \$\begingroup\$ There is still emotions in the last snippet, :! ;) \$\endgroup\$
    – user63331
    Commented Mar 26, 2017 at 11:15
  • 4
    \$\begingroup\$ @cookie In that case you can see a lot of things as an emoticon with some fantasy, like =#, or >(, or (-[, etc. Also, no idea why, but there is apparently a List of emoticons Wikipedia page, which doesn't contain :! nor any of the ones I mentioned. \$\endgroup\$ Commented Mar 28, 2017 at 11:18
  • 1
    \$\begingroup\$ 19 bytes inspired by another question. \$\endgroup\$
    – Dorian
    Commented Sep 17, 2019 at 11:06
29
\$\begingroup\$

Pyth, 1 byte

S

Body must be at least 30 characters; you entered 14.

\$\endgroup\$
7
  • 3
    \$\begingroup\$ You say so? I was struggling with the title! \$\endgroup\$ Commented Apr 25, 2016 at 12:17
  • 48
    \$\begingroup\$ That's because you failed to add an explanation. How are we supposed to understand such complicated code without an explanation? \$\endgroup\$
    – Luis Mendo
    Commented Apr 25, 2016 at 13:53
  • 13
    \$\begingroup\$ Nah. This code is way beyond my comprehension. Too lengthy, I can't grasp such complicated logical structure :-P \$\endgroup\$
    – Luis Mendo
    Commented Apr 25, 2016 at 16:17
  • 9
    \$\begingroup\$ @LuisMendo I know... orlp must've been a genius to comprehend such a lengthy piece of code with such advanced logic. :P \$\endgroup\$
    – hyperneutrino
    Commented Apr 25, 2016 at 18:48
  • 1
    \$\begingroup\$ You are still the current winner! \$\endgroup\$ Commented Jul 21, 2016 at 9:43
16
\$\begingroup\$

Cjam, 5 bytes

{,:)}

Try it online!

This is an unnamed block which expects n on the stack and leaves a list with the range [1...n] on it.
Works by just building the range with , and then incrementing every range element with :) to make the range one-based.

\$\endgroup\$
3
  • 10
    \$\begingroup\$ +1 for a smiley that mysteriously appeared in the code: :) \$\endgroup\$
    – user48538
    Commented Apr 25, 2016 at 12:29
  • 1
    \$\begingroup\$ @zyabin101 the smiley face is a very common CJam occurrence! \$\endgroup\$
    – A Simmons
    Commented Apr 25, 2016 at 13:19
  • 5
    \$\begingroup\$ @ASimmons concluding Cjam is happy? \$\endgroup\$ Commented Apr 25, 2016 at 16:12
15
\$\begingroup\$

Hexagony, 19

$@?!{M8.</(=/>').$;

Or in the expanded hexagon format:

  $ @ ?
 ! { M 8
. < / ( =
 / > ' ) 
  . $ ;

Huge thanks to Martin for basically coming up with this program, I just golfed it to fit in a side length 3 hexagon.

Try it online!

I don't have Timwi's fantastic Hexagony related programs, so this explanation won't be very colourful. Instead, you get to read a huge blob of text. Isn't that nice?

In any case, the IP starts at the top left corner, on the $, moving Eastward if you imagine this program were placed with North facing upward on a map. The $ causes us to skip the next instruction, which would be @, which would end the program. Instead, we execute ? which sets the current memory edge to be the input number. Now we reach the end of the row, which takes us to the middle row of the hexagon, still moving Eastward.

Most of the rest of the program is a loop. We start with . which is a no-op. Next we encounter a fork in the... uh... hexagon... the < instruction causes the IP to rotate 60 degrees to the right if the current memory edge is positive, otherwise we rotate 60 degrees left. Since we are moving Eastward, we either end up with our heading being South or North East. Since the input is greater than zero (and hence positive) we always start by going South East.

Next we hit a > which redirects us Eastward; these operators only fork if you hit the fork part. Then we hit ' which changes what memory edge we are looking at. Then we hit ) which increments the value of the current memory edge. Since all memory edges start at 0, the first time we do this we get a value of 1. Next we jump up to the second to top line and execute ! which prints out our number. Then we move to another edge with { and store the ASCII value of M multiplied by 10 plus 8 (778). Then we jump back to the second to last line of the hexagon, and hit the /. This results in us moving North West. We go past the . on the middle row, and come out on the ; at the bottom right. This prints out the current memory edge mod 256 as ASCII. This happens to be a newline. We hit ' which takes us back to the first edge that has the value we read in. The we hit / which sets us to move Eastward again. Then we hit ( which decrements the value. = causes us to face the right direction again for the future memory edge jumping.

Now, since the value is positive (unless it is zero) we go back to the bottom of the hexagon. Here we hit . then we jump over the ; so nothing happens, and we go back to the start of the loop. When the value is zero we go back to the beginning of the program, where the same stuff happens again but ? fails to find another number, and we take the other branching path. That path is relatively simple: we hit { which changes the memory edge, but we don't care anymore, then we hit @ which ends the program.

\$\endgroup\$
14
\$\begingroup\$

Mathematica, 5 bytes

Range

Simple enough.

\$\endgroup\$
5
  • 37
    \$\begingroup\$ Not simple when you have to PAY to afford this language :( \$\endgroup\$ Commented Apr 25, 2016 at 13:38
  • 1
    \$\begingroup\$ @ΈρικΚωνσταντόπουλος I would argue now that rich people have it easier, but you managed to beat this answer by 4 bytes ;) \$\endgroup\$
    – Sebb
    Commented Apr 27, 2016 at 13:23
  • \$\begingroup\$ @EʀɪᴋᴛʜᴇGᴏʟғᴇʀ I know it is a long time after your comment, but you don't pay to afford the language, you pay for the language. \$\endgroup\$ Commented Jun 16, 2016 at 15:55
  • \$\begingroup\$ @NoOneIsHere to afford means to claim ownership of something by paying. I think you mean that there is a subscription instead of a one-time payment. \$\endgroup\$ Commented Jun 17, 2016 at 7:30
  • \$\begingroup\$ @EʀɪᴋᴛʜᴇGᴏʟғᴇʀ There is a ~$150 one time payment, but to keep arguing, let's go to chat. \$\endgroup\$ Commented Jun 17, 2016 at 16:18
12
\$\begingroup\$

MATL, 1 byte

:

Example output:

15
1  2  3  4  5  6  7  8  9 10 11 12 13 14 15

Try it online here

\$\endgroup\$
1
  • 2
    \$\begingroup\$ How does this work? I don't understand how this advanced code structure works. :-P \$\endgroup\$
    – hyperneutrino
    Commented Nov 29, 2016 at 4:53
11
\$\begingroup\$

GNU Coreutils, 6 bytes

seq $1

split answer to pure bash, see below...

\$\endgroup\$
1
  • 1
    \$\begingroup\$ for me, the best bash/etc answer ^^ perfect tool-to-job ratio. \$\endgroup\$ Commented Apr 25, 2016 at 15:49
10
\$\begingroup\$

R, 13 bytes

cat(1:scan())

Body must be at least 30 characters.

\$\endgroup\$
7
  • \$\begingroup\$ I can't edit your answer lol. \$\endgroup\$ Commented Apr 25, 2016 at 13:12
  • \$\begingroup\$ @ΈρικΚωνσταντόπουλος You can only suggest edits, which have to be approved, with your current reputation. And please note that editing code is not welcome here. If you have golfing advice, write a comment so the author can test it before updating the solution. \$\endgroup\$
    – Denker
    Commented Apr 25, 2016 at 13:28
  • \$\begingroup\$ @DenkerAffe I meant the edit button was grayed out before. \$\endgroup\$ Commented Apr 25, 2016 at 13:28
  • 2
    \$\begingroup\$ I do if I want it to write it even when you call the script. \$\endgroup\$
    – Masclins
    Commented Apr 25, 2016 at 15:24
  • 10
    \$\begingroup\$ I thought a CAT Scan was best suited for viewing bone injuries, diagnosing lung and chest problems, and detecting cancers, not counting. \$\endgroup\$ Commented Apr 26, 2016 at 6:21
10
\$\begingroup\$

Javascript 182 177 160 154 139 138 132 bytes (valid)

1 byte saved thanks to @ShaunH

n=>{c=[e=0];for(;c.join``!=n;){a=c.length-1;c[a]++;for(;a+1;a--){c[a]+=e;e=0;if(c[a]>9)c[a]=0,e++;}e&&c.unshift(1);alert(c.join``)}}

Arbitary precision to the rescue!

Because javascript can only count up to 2^53-1 (Thanks goes to @MartinBüttner for pointing it out), I needed to create arbitary precision to do this. It stores data in an array, and each "tick" it adds 1 to the last element, then goes trough the array, and if something exceedes 9, it sets that element to 0, and adds 1 to the one on the left hand.

Try it here! Note: press F12, to actually see the result, as I didn't want to make you wait for textboxes.

BTW.: I was the only one, who didn't know, ternary operators are so useful in codegolf?

if(statement)executeSomething();

is longer than

statement?executeSomething():0;

by 1 byte.

Javascript, 28 bytes (invalid - can't count to 264)

n=>{for(i=0;i++<n;)alert(i)}
\$\endgroup\$
10
  • 2
    \$\begingroup\$ Yep, you were the only one :P \$\endgroup\$ Commented Apr 26, 2016 at 8:06
  • \$\begingroup\$ Can the invalid version count up to 2^64-1? If so it's valid thanks to the new rules. \$\endgroup\$ Commented Apr 26, 2016 at 11:05
  • \$\begingroup\$ @ΈρικΚωνσταντόπουλος No, only up to 2^53-1 \$\endgroup\$
    – Bálint
    Commented Apr 26, 2016 at 12:05
  • \$\begingroup\$ For if's with no else && can be useful as well, just gotta be careful about cohersion. condition&&action() \$\endgroup\$
    – Shaun H
    Commented Apr 26, 2016 at 13:32
  • 1
    \$\begingroup\$ e?c.unshift(1):0 to e&&c.unshift(1) saves a byte \$\endgroup\$
    – Shaun H
    Commented Apr 26, 2016 at 18:40
9
\$\begingroup\$

Java 8, 43/69/94 bytes

Crossed out 44 is still a regular 44 -- wait, I didn't cross it out I just replaced it :(

If I can return a LongStream: (43 bytes)

n->java.util.stream.LongStream.range(1,n+1)

This is a lambda for a Function<Long,LongStream>. Technically, I should use rangeClosed instead of range, as I'm cutting off one from my maximum input in this way, but rangeClosed is longer than range.

If I have to print in the function: (69 bytes)

n->java.util.stream.LongStream.range(1,n+1).peek(System.out::println)

This is a lambda for a Consumer<Long>. Technically I'm abusing peek, as it is an intermediate operation, meaning this lambda is technically returning a LongStream like the first example; I should be using forEach instead. Again, golf is not nice code.

Unfortunately, since long's range is a signed 64-bit integer, it does not reach the requested 2^64-1, but merely 2^63-1.

However, Java SE 8 provides functionality to treat longs as if they were unsigned, by calling specific methods on the Long class explicitly. Unfortunately, as Java is still Java, this is rather long-winded, though shorter than the BigInteger version that it replaces. (94 bytes)

n->{for(long i=0;Long.compareUnsigned(i,n)<0;)System.out.println(Long.toUnsignedString(++i));}

This is a Consumer<Long>, as the previous.

And just too long to avoid scroll.

\$\endgroup\$
10
  • \$\begingroup\$ 2^64-1 limit changed :D \$\endgroup\$ Commented Apr 26, 2016 at 8:14
  • 1
    \$\begingroup\$ Shouldn't the first function be n->java.util.stream.LongStream.range(1,n+1)? \$\endgroup\$
    – user45941
    Commented Apr 26, 2016 at 9:11
  • 3
    \$\begingroup\$ @zyabin101 >.> you saw nothing \$\endgroup\$
    – CAD97
    Commented Apr 26, 2016 at 12:02
  • 1
    \$\begingroup\$ @KevinCruijssen It would help, except the reason for using the BigInteger is that using an int (or even long) for the iterator isn't big enough. \$\endgroup\$
    – CAD97
    Commented Apr 26, 2016 at 14:26
  • 1
    \$\begingroup\$ I was mistaken; J8 provides methods for using long in an unsigned manner, so utilizing those is shorter than the BigInteger approach. (It would not have been had we had to implement our own unsigned long treatment as you had to before J8.) \$\endgroup\$
    – CAD97
    Commented Apr 26, 2016 at 19:55
8
\$\begingroup\$

05AB1E, 1 byte

Code:

L

Try it online!.

A more interesting approach:

FN>,

Explanation:

F     # For N in range(0, input):
 N>   #   Push N + 1
   ,  #   Pop and print with a newline

Try it online!.

\$\endgroup\$
8
\$\begingroup\$

MarioLANG, 19 bytes

;
)<
+"
:[
(-
>!
=#

Try it online!

Vertical programs are usually more golfable for simple loops in MarioLANG. I'm not sure what the interpreter does when encountering [ inside an elevator, but it seems to terminate the program when the current cell is 0. That's probably a useful trick in general.

Explanation

MarioLANG is a Brainfuck-like language (with an infinite memory tape of arbitrary-precision integers) where the instruction pointer resembles Mario walking and jumping around.

Mario starts in the top left corner and falls downward. ; reads an integer from STDIN and places it in the current memory cell. Now note that = is a ground cell for Mario to walk on, the " and # form an elevator (with # being the start) and ! makes mario stop on the elevator so that he doesn't walk off right away. The > and < set his movement direction. We can see that this gives a simple loop, containing the following code:

)   Move memory pointer one cell right.
+   Increment (initially zero).
:   Print as integer, followed by a space.
(   Move memory pointer one cell left.
-   Decrement.
[   Conditional, see below.

Now normally [ would conditionally make Mario skip the next depending on whether the current cell is zero or not. That is, as long as the counter is non-zero this does nothing. However, it seems that when Mario encounters a [ while riding an elevator and the current cell is 0, the program simply terminates immediately with an error, which means we don't even need to find a way to redirect him correctly.

\$\endgroup\$
8
  • \$\begingroup\$ It terminates the program because it "falls" I think. \$\endgroup\$ Commented Apr 25, 2016 at 14:02
  • \$\begingroup\$ You chose 56 too? \$\endgroup\$ Commented Apr 25, 2016 at 14:02
  • \$\begingroup\$ @ΈρικΚωνσταντόπουλος I can't seem to find any place Mario falls to. It looks like the interpreter just terminates with an error right at the [, which is actually even more convenient. \$\endgroup\$ Commented Apr 25, 2016 at 14:04
  • \$\begingroup\$ TIO has a tendency not to show error messages (STDERR) without Debug enabled. It seems it is indeed an error. \$\endgroup\$ Commented Apr 25, 2016 at 14:05
  • \$\begingroup\$ @ΈρικΚωνσταντόπουλος Yeah, and that's actually good, because STDERR is ignored unless specified otherwise. \$\endgroup\$ Commented Apr 25, 2016 at 14:07
7
\$\begingroup\$

MATLAB, 7 bytes

An unnamed anonymous function:

@(n)1:n

Run as:

ans(10)
ans =
     1     2     3     4     5     6     7     8     9    10

Test it here!


If a full program is required, 17 bytes:

disp(1:input(''))
10
     1     2     3     4     5     6     7     8     9    10

Test it here!

\$\endgroup\$
0
7
\$\begingroup\$

ArnoldC, 415 bytes

IT'S SHOWTIME
HEY CHRISTMAS TREE n
YOU SET US UP 0
GET YOUR ASS TO MARS n
DO IT NOW
I WANT TO ASK YOU A BUNCH OF QUESTIONS AND I WANT TO HAVE THEM ANSWERED IMMEDIATELY
HEY CHRISTMAS TREE x
YOU SET US UP n
STICK AROUND x
GET TO THE CHOPPER x
HERE IS MY INVITATION n
GET DOWN x
GET UP 1
ENOUGH TALK
TALK TO THE HAND x
GET TO THE CHOPPER x
HERE IS MY INVITATION n
GET DOWN x
ENOUGH TALK
CHILL
YOU HAVE BEEN TERMINATED

The only thing of interest is to use n-x (where n is the goal and x the incremented variable) to test the end of the while loop instead of having a dedicated variable, so I end up having n-x and n-(n-x) = x in each loop run

Note: I can only count to 2^31-1. Well I guess the Terminators are not a real danger after all.

\$\endgroup\$
1
  • 4
    \$\begingroup\$ Of course there is a programming language designed around Arnold Schwarzenegger memes... \$\endgroup\$
    – Nzall
    Commented Apr 27, 2016 at 11:44
6
\$\begingroup\$

Haskell, 10 bytes

f n=[1..n]

Usage example: f 4-> [1,2,3,4].

\$\endgroup\$
3
  • \$\begingroup\$ You must not hardcode n, you must take n. \$\endgroup\$ Commented Apr 26, 2016 at 8:19
  • 4
    \$\begingroup\$ @ΈρικΚωνσταντόπουλος n isn't hardcoded here - it's a function argument. Haskell syntax can be strange to people used to C-like syntax. \$\endgroup\$
    – user45941
    Commented Apr 26, 2016 at 9:13
  • \$\begingroup\$ @Mego Oh, I was confused with the usage example. \$\endgroup\$ Commented Apr 26, 2016 at 15:24
6
\$\begingroup\$

Joe - 2 or 6

While you can use the inclusive variant of the range function..

1R

..that's boring! Let's instead take the cumulative sum (\/+) of a table of ones of shape n (1~T).

\/+1~T
\$\endgroup\$
2
  • \$\begingroup\$ Can you provide a link to the language \$\endgroup\$
    – Downgoat
    Commented Apr 28, 2016 at 3:39
  • \$\begingroup\$ @Downgoat github.com/JaniM/Joe \$\endgroup\$
    – seequ
    Commented Apr 28, 2016 at 4:35
4
\$\begingroup\$

Pyth - 3 2 bytes

1 bytes saved thanks to @DenkerAffe.

Without using the builtin.

hM

Try it online.

\$\endgroup\$
5
  • \$\begingroup\$ hM if you wanna get real fancy :) \$\endgroup\$
    – Denker
    Commented Apr 25, 2016 at 12:48
  • \$\begingroup\$ @DenkerAffe oh yeah, true. \$\endgroup\$
    – Maltysen
    Commented Apr 25, 2016 at 12:51
  • \$\begingroup\$ You forgot to update your byte count. \$\endgroup\$ Commented Apr 25, 2016 at 13:00
  • \$\begingroup\$ @CᴏɴᴏʀO'Bʀɪᴇɴ -.- \$\endgroup\$
    – Maltysen
    Commented Apr 25, 2016 at 13:00
  • \$\begingroup\$ @ΈρικΚωνσταντόπουλος orlp already did the builtin answer. \$\endgroup\$
    – Maltysen
    Commented Apr 25, 2016 at 13:11
4
\$\begingroup\$

Pyke, 1 byte

S

Try it here!

Or 2 bytes without the builtin

mh

Try it here!

#h

Try it here!

Lh

Try it here!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Pyth and Pyke at the same time \$\endgroup\$
    – Bálint
    Commented Apr 25, 2016 at 12:56
4
\$\begingroup\$

dc, 15

?[d1-d1<m]dsmxf

Input read from stdin. This counts down from n, pushing a copy of each numbers to the stack. The stack is then output as one with the f command, so the numbers get printed in the correct ascending order.

Because all the numbers are pushed to the stack, this is highly likely to run out of memory before getting anywhere near 2^64. If this is a problem, then we can do this instead:


dc, 18

?sn0[1+pdln>m]dsmx
\$\endgroup\$
4
  • \$\begingroup\$ Maybe it works with 2^64-1 (the new limit). \$\endgroup\$ Commented Apr 26, 2016 at 8:11
  • \$\begingroup\$ The first one will run out of memory long before you reach 2^64-1. The second will keep on happily going until our sun goes supernova \$\endgroup\$ Commented Apr 26, 2016 at 14:56
  • \$\begingroup\$ @DigitalTraumaskcsockso I meant that you can edit your second answer if it's shorter for 2^64-1. \$\endgroup\$ Commented Apr 26, 2016 at 15:24
  • \$\begingroup\$ @ΈρικΚωνσταντόπουλος dc, like bc, uses arbitrary precision math by default, and thus such boundaries are irrelevant for this language. \$\endgroup\$ Commented Apr 26, 2016 at 18:35
4
\$\begingroup\$

Piet, 64 Codels codelsize 1

With codelsize 20:

codelsize 20

Npiet trace images

First loop:

tracestart

Remaining trace for n=2:

traceend

Notes

  • No Piet answer yet? Let me fix that with my first ever Piet program! This could probably be shorter with better rolls and less pointer manipulation though...

  • The upper supported limit depends on the implementation of the interpreter. It would theoretically be possible to support arbitraryly large numbers with the right interpreter.

  • The delimeter is ETX (Ascii 3), however this cannot be properly displayed in this answer so I'll just leave them out. It works in the console:

enter image description here

Output

Input:  1
Output: 1

Input:  20
Output: 1234567891011121314151617181920

Input:  100
Output: 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100

Undefined behaviour:

Input:  -1
Output: 1

Input:  0
Output: 1

Npiet trace for n=2

trace: step 0  (0,0/r,l nR -> 1,0/r,l lB):
action: in(number)
? 2
trace: stack (1 values): 2

trace: step 1  (1,0/r,l lB -> 2,0/r,l nB):
action: push, value 1
trace: stack (2 values): 1 2

trace: step 2  (2,0/r,l nB -> 3,0/r,l nG):
action: duplicate
trace: stack (3 values): 1 1 2

trace: step 3  (3,0/r,l nG -> 4,0/r,l dY):
action: out(number)
1
trace: stack (2 values): 1 2

trace: step 4  (4,0/r,l dY -> 5,0/r,l lY):
action: push, value 1
trace: stack (3 values): 1 1 2

trace: step 5  (5,0/r,l lY -> 6,0/r,l lG):
action: add
trace: stack (2 values): 2 2

trace: step 6  (6,0/r,l lG -> 7,0/r,l lR):
action: duplicate
trace: stack (3 values): 2 2 2

trace: step 7  (7,0/r,l lR -> 10,0/r,l nR):
action: push, value 3
trace: stack (4 values): 3 2 2 2

trace: step 8  (10,0/r,l nR -> 12,0/r,l dR):
action: push, value 2
trace: stack (5 values): 2 3 2 2 2

trace: step 9  (12,0/r,l dR -> 13,0/r,l lB):
action: roll
trace: stack (3 values): 2 2 2

trace: step 10  (13,0/r,l lB -> 14,0/r,l lG):
action: duplicate
trace: stack (4 values): 2 2 2 2

trace: step 11  (14,0/r,l lG -> 15,2/d,r nG):
action: push, value 3
trace: stack (5 values): 3 2 2 2 2

trace: step 12  (15,2/d,r nG -> 15,3/d,r dG):
action: push, value 1
trace: stack (6 values): 1 3 2 2 2 2

trace: step 13  (15,3/d,r dG -> 14,3/l,l lR):
action: roll
trace: stack (4 values): 2 2 2 2

trace: step 14  (14,3/l,l lR -> 13,1/l,r lC):
action: greater
trace: stack (3 values): 0 2 2

trace: step 15  (13,1/l,r lC -> 11,1/l,r nC):
action: push, value 3
trace: stack (4 values): 3 0 2 2

trace: step 16  (11,1/l,r nC -> 10,1/l,r lB):
action: multiply
trace: stack (3 values): 0 2 2

trace: step 17  (10,1/l,r lB -> 9,1/l,r nY):
action: pointer
trace: stack (2 values): 2 2

trace: step 18  (9,1/l,r nY -> 7,1/l,r dY):
action: push, value 2
trace: stack (3 values): 2 2 2

trace: step 19  (7,1/l,r dY -> 6,1/l,r lY):
action: push, value 1
trace: stack (4 values): 1 2 2 2

trace: step 20  (6,1/l,r lY -> 5,1/l,r nM):
action: roll
trace: stack (2 values): 2 2

trace: step 21  (5,1/l,r nM -> 4,1/l,r dM):
action: push, value 3
trace: stack (3 values): 3 2 2

trace: step 22  (4,1/l,r dM -> 3,1/l,r lG):
action: pointer
trace: stack (2 values): 2 2

trace: step 23  (3,1/d,r lG -> 2,3/l,l nG):
action: push, value 3
trace: stack (3 values): 3 2 2

trace: step 24  (2,3/l,l nG -> 2,2/u,r lY):
action: out(char)

trace: stack (2 values): 2 2
trace: white cell(s) crossed - continuing with no command at 2,0...

trace: step 25  (2,2/u,r lY -> 2,0/u,r nB):

trace: step 26  (2,0/u,r nB -> 3,0/r,l nG):
action: duplicate
trace: stack (3 values): 2 2 2

trace: step 27  (3,0/r,l nG -> 4,0/r,l dY):
action: out(number)
2
trace: stack (2 values): 2 2

trace: step 28  (4,0/r,l dY -> 5,0/r,l lY):
action: push, value 1
trace: stack (3 values): 1 2 2

trace: step 29  (5,0/r,l lY -> 6,0/r,l lG):
action: add
trace: stack (2 values): 3 2

trace: step 30  (6,0/r,l lG -> 7,0/r,l lR):
action: duplicate
trace: stack (3 values): 3 3 2

trace: step 31  (7,0/r,l lR -> 10,0/r,l nR):
action: push, value 3
trace: stack (4 values): 3 3 3 2

trace: step 32  (10,0/r,l nR -> 12,0/r,l dR):
action: push, value 2
trace: stack (5 values): 2 3 3 3 2

trace: step 33  (12,0/r,l dR -> 13,0/r,l lB):
action: roll
trace: stack (3 values): 2 3 3

trace: step 34  (13,0/r,l lB -> 14,0/r,l lG):
action: duplicate
trace: stack (4 values): 2 2 3 3

trace: step 35  (14,0/r,l lG -> 15,2/d,r nG):
action: push, value 3
trace: stack (5 values): 3 2 2 3 3

trace: step 36  (15,2/d,r nG -> 15,3/d,r dG):
action: push, value 1
trace: stack (6 values): 1 3 2 2 3 3

trace: step 37  (15,3/d,r dG -> 14,3/l,l lR):
action: roll
trace: stack (4 values): 2 3 2 3

trace: step 38  (14,3/l,l lR -> 13,1/l,r lC):
action: greater
trace: stack (3 values): 1 2 3

trace: step 39  (13,1/l,r lC -> 11,1/l,r nC):
action: push, value 3
trace: stack (4 values): 3 1 2 3

trace: step 40  (11,1/l,r nC -> 10,1/l,r lB):
action: multiply
trace: stack (3 values): 3 2 3

trace: step 41  (10,1/l,r lB -> 9,1/l,r nY):
action: pointer
trace: stack (2 values): 2 3
trace: white cell(s) crossed - continuing with no command at 9,3...

trace: step 42  (9,1/d,r nY -> 9,3/d,l nR):
\$\endgroup\$
2
  • \$\begingroup\$ Does it have null bytes between numbers? \$\endgroup\$ Commented May 10, 2016 at 12:37
  • \$\begingroup\$ @ΈρικΚωνσταντόπουλος what do you mean? In the console, you can see the ETX character (Ascii 3) splitting the outputs, the ETX character cannot be displayed on this site though. \$\endgroup\$
    – Marv
    Commented May 10, 2016 at 12:38
4
\$\begingroup\$

JavaScript (ES6), 77 76 63 59 58 Bytes

n=>{for(s=a=b=0;s!=n;console.log(s=[a]+b))a+=!(b=++b%1e9)}

Takes input n as a string, should support up to 9007199254740991999999999

Explained:

n=>{ //create function, takes n as input
    for( //setup for loop
        s=a=b=0; //init s, a, and b to 0
        s!=n; //before each cycle check if s!=n
        console.log(s=[a]+b) //after each cycle concat a and b into to s and print
    )
        a+=!(b=++b%1e9) //During each cycle set b to (b+1)mod 1e9, if b == 0 and increment a
} //Wrap it all up
\$\endgroup\$
7
  • \$\begingroup\$ Explanation please. \$\endgroup\$
    – Bálint
    Commented Apr 26, 2016 at 7:59
  • \$\begingroup\$ 2^64-1 is fine I've changed spec. \$\endgroup\$ Commented Apr 26, 2016 at 8:20
  • 1
    \$\begingroup\$ Interesting, I didn't think of just concatenating two numbers to reach the minimum value. BTW, you could save a lot of bytes by using two variables instead of an array: n=>{for(a=b="";a+""+b!=n;console.log(a+""+b))++b-1e9||(++a,b=0)} \$\endgroup\$
    – user81655
    Commented Apr 26, 2016 at 14:59
  • \$\begingroup\$ Thanks for that @user81655, my brain loves arrays for some reason \$\endgroup\$
    – Shaun H
    Commented Apr 26, 2016 at 15:29
  • 1
    \$\begingroup\$ You can save a byte by changing a+""+b to [a]+b \$\endgroup\$ Commented Jun 16, 2016 at 14:27
4
\$\begingroup\$

Oration, 31 bytes

literally, print range(input())
\$\endgroup\$
7
  • \$\begingroup\$ Is this python with literally, in front of every statement? (Question 2: Pre-dates or post-dates if it's yours? both are acceptable unless you made this for this challenge, in which case it's a loophole) \$\endgroup\$ Commented Jun 6, 2016 at 18:28
  • \$\begingroup\$ @EʀɪᴋᴛʜᴇGᴏʟғᴇʀ I believe Oration is by ConorO'Brien. github.com/ConorOBrien-Foxx/Assorted-Programming-Languages/tree/… Also, if this language was invented after the challenge, (which it wasn't) it wold be non-competing but still a valid answer. I'm not a big fan of the "Your language must pre-date the challenge" rule. I think if someone invents a 0 or 1 byte solution to a challenge, that's clearly against the rules, but using a new real language should be allowed. \$\endgroup\$
    – DJMcMayhem
    Commented Jun 6, 2016 at 18:42
  • \$\begingroup\$ @EʀɪᴋᴛʜᴇGᴏʟғᴇʀ this is what Dr Green Eggs said. I'm actually Easterlyirk's chatbot. \$\endgroup\$
    – Żáłģó
    Commented Jun 6, 2016 at 18:49
  • \$\begingroup\$ So no review for you? \$\endgroup\$ Commented Jun 6, 2016 at 18:52
  • \$\begingroup\$ @NoOneIsHere what? \$\endgroup\$
    – Żáłģó
    Commented Jun 6, 2016 at 18:55
3
\$\begingroup\$

GNU bc, 23

n=read()
for(;i++<n;)i

Input read from stdin. bc handles arbitrary precision numbers by default, so the 2^64 max is no problem.

\$\endgroup\$
3
\$\begingroup\$

Actually, 1 byte

R

Boring builtin is boring. Requires a 64-bit version of Python 3 to get all the way up to 2**64.

Try it online! (due to memory and output length restrictions, the online interpreter can't go very high).

Here's a 5-byte version that doesn't require 64-bit Python 3 and is a little nicer on memory usage:

W;DWX

Try it online! (see above caveats)

\$\endgroup\$
6
  • \$\begingroup\$ @StewieGriffin The issue is with addressable RAM, not integer limits (Python seamlessly transitions between native ints and big integers). I tested it with both 32-bit Python 3 and 64-bit Python 3. 32-bit failed, 64-bit didn't. \$\endgroup\$
    – user45941
    Commented Apr 26, 2016 at 6:13
  • \$\begingroup\$ @Mego I have changed the limits, although I don't think 32-bit Python supports 2^64-1, I think it supports up to 2^32-1, so I encourage for the latter to be used in the Python case. \$\endgroup\$ Commented Apr 26, 2016 at 8:01
  • \$\begingroup\$ Why do you call Seriously Actually? \$\endgroup\$ Commented Apr 26, 2016 at 8:01
  • \$\begingroup\$ @ΈρικΚωνσταντόπουλος Like I mentioned to Stewie, the issue isn't 64-bit ints, but memory addressing. Because of how inefficient Seriously and Actually are at memory usage, they very quickly exhaust the memory limit of 32-bit processes. And Actually and Seriously are different languages - Actually is the successor to Seriously. \$\endgroup\$
    – user45941
    Commented Apr 26, 2016 at 9:09
  • \$\begingroup\$ @Mego Oh, I once clicked a link for Actually and it linked me directly to Seriously. \$\endgroup\$ Commented Apr 26, 2016 at 10:40
3
\$\begingroup\$

Fuzzy-Octo-Guacamole, 7 bytes

^!_[+X]

Explanation:

^ get input to ToS
! set for loop to ToS
_ pop
[ start for loop
+ increment ToS (which aparently happens to be 0)
X print ToS
] end for loop
\$\endgroup\$
6
  • \$\begingroup\$ Also, X works instead of o;, for 7 bytes. \$\endgroup\$
    – Riker
    Commented Apr 26, 2016 at 19:03
  • \$\begingroup\$ Wouldn't that print [n]? \$\endgroup\$ Commented Apr 26, 2016 at 19:04
  • \$\begingroup\$ rather than n \$\endgroup\$ Commented Apr 26, 2016 at 19:04
  • \$\begingroup\$ No. : prints the full stack. X is new. \$\endgroup\$
    – Riker
    Commented Apr 26, 2016 at 19:08
  • \$\begingroup\$ Also, another 7 byte solution: ^!$[_;]. $ is range. \$\endgroup\$
    – Riker
    Commented Apr 26, 2016 at 19:11
3
\$\begingroup\$

QBASIC, 43 bytes

1 INPUT a
2 FOR b=1 TO a
3 PRINT b
4 NEXT b
\$\endgroup\$
5
  • \$\begingroup\$ Do you really need INPUT e;a or INPUT a is enough? I don't see you re-using e. \$\endgroup\$ Commented Jun 16, 2016 at 8:33
  • \$\begingroup\$ good point, not sure why that was there. \$\endgroup\$ Commented Jun 16, 2016 at 14:15
  • \$\begingroup\$ Also, do you really need the spaces between the line number and letters and between 1 TO? \$\endgroup\$ Commented Jun 16, 2016 at 14:20
  • \$\begingroup\$ Yes, those are necessary \$\endgroup\$ Commented Jun 16, 2016 at 19:35
  • \$\begingroup\$ What version of QBasic is this? Can you use : between statements instead of a return and a line number? QB4.5 lets me do this: INPUT a: FOR b=1 TO a (\n) ?b:NEXT \$\endgroup\$
    – steenbergh
    Commented Oct 31, 2016 at 17:32
3
\$\begingroup\$

Cubix, 17 bytes

..U;I0-!@;)wONow!

Try it here

Cubix is a 2D language created by @ETHProductions where the commands are wrapped onto a cube. This program wraps onto a cube with an edge length of 2 as follows.

    . .
    U ;
I 0 - ! @ ; ) w
O N o w ! . . .
    . .
    . .
  • I gets the integer input
  • 0 push 0 to the stack
  • - subtract top items of stack
  • ! if truthy jump the next command @ terminate
  • ; pop the subtraction result from the stack
  • ) increment top of stack
  • w move ip to the right and carry on. This causes it to drop to the next line
  • O output the top of stack as a number
  • N push linefeed (10) to the stack
  • o output a linefeed
  • w move ip to the right and carry on. This causes it to drop to the next face
  • ! because TOS truthy, jump the @ terminate
  • ; pop the linefeed from the stack
  • U uturn to the left onto the - subtraction and resume from there
\$\endgroup\$
3
\$\begingroup\$

Sesos, 3 bytes

Hexdump of generated binary file:

0000000: 16f8ce                                            ...

Size   : 3 byte(s)

Try it online!

Assembler:

set numin
set numout
get
jmp
sub 1
fwd 1
add 1
put
rwd 1
           ;implicit jnz

Brainfuck pseudocode: ,[->+.<]

\$\endgroup\$
0
2
\$\begingroup\$

Python 2, 37 33 32 33 bytes

for i in xrange(input()):print-~i

Presumably works up to 2**64 and beyond.

Shot down four bytes thanks to @dieter, and another thanks to @orlp. But apparently, as @Sp3000 found out, range() might have issues with higher values, so the function was changed to xrange(). Note: even xrange() might have issues, at least in 2.7.10.

\$\endgroup\$
10
  • 1
    \$\begingroup\$ Python 2, to be exact :) \$\endgroup\$ Commented Apr 25, 2016 at 12:20
  • \$\begingroup\$ 33 bytes -> for i in range(input()):print i+1 \$\endgroup\$
    – dieter
    Commented Apr 25, 2016 at 12:24
  • 2
    \$\begingroup\$ 32 bytes -> for i in range(input()):print-~i \$\endgroup\$
    – orlp
    Commented Apr 25, 2016 at 12:25
  • 1
    \$\begingroup\$ "Presumably works up to 2**64 and beyond." - doubt it in Python 2, but it might with xrange (edit: even xrange might have issues, at least in 2.7.10) \$\endgroup\$
    – Sp3000
    Commented Apr 25, 2016 at 12:34
  • \$\begingroup\$ How does -~ work? Edit: I figured it out. Also, nice trick! \$\endgroup\$ Commented Apr 27, 2016 at 8:26
2
\$\begingroup\$

Zsh, 12 bytes

echo {1..$1}

This works because variables are expanded before the braces.

\$\endgroup\$
3
  • 2
    \$\begingroup\$ I'm not sure you can count up to 2^64 (or even quite a bit less) ? \$\endgroup\$ Commented Apr 25, 2016 at 15:50
  • \$\begingroup\$ @OlivierDulac 2^64-1 is fine now. \$\endgroup\$ Commented Apr 26, 2016 at 8:17
  • 1
    \$\begingroup\$ zsh's maximum is 2^63 - 1 \$\endgroup\$ Commented Apr 26, 2016 at 14:49
1
2 3 4 5

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.