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
\$\begingroup\$

Perl 5, 15 bytes + 8

Works with the -l and -Mbigint switch, and should work up to 2^64 with BigInt. Thanks to @andlrc for the 7 bytes shaved off.

print for 1..<>
\$\endgroup\$
9
  • \$\begingroup\$ You should use BigInt then. \$\endgroup\$ Commented Apr 25, 2016 at 13:45
  • \$\begingroup\$ But you can do arbitary precision, thus you can count to pretty much infinite (2^65536 at least) \$\endgroup\$
    – Bálint
    Commented Apr 25, 2016 at 14:52
  • 1
    \$\begingroup\$ You can use print for 1..<> \$\endgroup\$ Commented Apr 25, 2016 at 15:33
  • \$\begingroup\$ @ΈρικΚωνσταντόπουλος Edited to match this. \$\endgroup\$
    – Sake
    Commented Apr 26, 2016 at 6:49
  • \$\begingroup\$ @Bálint How so? I'm not aware of this in Perl... Did a bit of research on the Perl documentation, but I haven't found anything I guess... :( \$\endgroup\$
    – Sake
    Commented Apr 26, 2016 at 6:51
1
\$\begingroup\$

AutoHotKey

I wasn't the first to post an answer in AHK, but mine are shorter for now. AutoHotKey doesn't like golf so the golfed versions are the same as the ungolfed versions. As for AutoHotKey's integer support:

For integers, 64-bit signed values are supported, which range from -9223372036854775808 (-0x8000000000000000) to 9223372036854775807 (0x7FFFFFFFFFFFFFFF). Any integer constants outside this range are not supported and might yield inconsistent results. By contrast, arithmetic operations on integers wrap around upon overflow (e.g. 0x7FFFFFFFFFFFFFFF + 1 = -0x8000000000000000).

Really Annoying Version - 25 bytes

Prints each number in a message box (super annoying) and takes input as the first argument on the command line.

i=1
Loop %1%
MsgBox % i++

i=1 - Loop counter set at 1
Loop %1% - Loop as many times as specified on the CLI
MsgBox % i++ = Display a message box with the digit in it, then increment

Alternate, Less Annoying Version - 43 bytes

This version displays only one message box but is much longer.

i=1
j=
Loop %1%
j:=j . i++ . " "
MsgBox %j%

i=1 - Loop counter set at 1
j= - Variable j set to an empty string
Loop %1% - Loop as many times as specified on the CLI
j:=j . i++ . " " - concatenate i and a space to j, then increment i
MsgBox %j% = Display a message box with j in it

\$\endgroup\$
4
  • \$\begingroup\$ I hope there's a way to escape the loop! Counting just to 30 would be incredibly annoying. \$\endgroup\$ Commented Apr 26, 2016 at 6:14
  • \$\begingroup\$ @StewieGriffin I mean, you can kill the process... But otherwise, no. \$\endgroup\$
    – Nakaan
    Commented Apr 26, 2016 at 11:46
  • \$\begingroup\$ I think in the maximum signed int64 value you have 2 extra Fs. \$\endgroup\$ Commented May 2, 2016 at 12:45
  • \$\begingroup\$ Here's a 26 byte less annoying version using Send as the output method (using \n to indicate a new line in the program because I need to use the accent/backtick in the program that messes with SE): Loop,%1%{ \n i++ \n Send,` %i% \n } \$\endgroup\$ Commented Mar 28, 2017 at 12:45
1
\$\begingroup\$

Jolf, 29 + 1 = 30 bytes

This in fact is valid! It uses the same technique as the JavaScript answer, keeping an array of digits. It should thus theoretically work, but may not work due to time limitations (browser crashing, etc.) Make sure to have "Pretty Output" enabled if it isn't already. (Apparently, making sure is an extra byte, like a flag, so there's that.) Try it here!

Ζ²1W<ni)aRζEΖZWζγwlζh.ζγonhn}

Ungolfed:

Z ~: 1
W < n i )
  a R ζ E
  Ζ ZW
    ζ
    w lζ
    h .ζ w lζ
  on h n
}

That's real clean-looking for a golfing language! :D

\$\endgroup\$
7
  • \$\begingroup\$ What encoding is this? \$\endgroup\$ Commented Apr 26, 2016 at 18:16
  • \$\begingroup\$ You should add 1 byte because I must choose pretty output on. \$\endgroup\$ Commented Apr 26, 2016 at 18:17
  • \$\begingroup\$ @ΈρικΚωνσταντόπουλος You are right on the latter. Also, it's encoded in ISO-8859-7. You can upload a file on the website. (It's the encoding that bears your name in 1-byte characters ;)) \$\endgroup\$ Commented Apr 26, 2016 at 18:22
  • \$\begingroup\$ That's right. 2 more to go... \$\endgroup\$ Commented Apr 26, 2016 at 18:41
  • \$\begingroup\$ I don't think the encoding has to do something with here, as my name uses Unicode I think. \$\endgroup\$ Commented Apr 29, 2016 at 17:40
1
\$\begingroup\$

C, 61 bytes

long i,n;main(){for(scanf("%ld",&n);i++<n;printf("%ld ",i));}

Essentially the same as my C++ answer, but C (or gcc) is more lenient of missing #includes, a missing return-type for main, and missing return-statements.

\$\endgroup\$
5
  • \$\begingroup\$ I disagree. Not all compilers support missing #includes. So you should add 18 bytes. \$\endgroup\$ Commented Apr 27, 2016 at 12:35
  • \$\begingroup\$ gcc is considered sort of a golden standard as far as C compilers are concerned. Since default gcc has always supported missing #include <stdio.h>, and corner-cutting is in general encouraged in code-golf, I still think this is legit. @Dennis seems to agree in a comment to this question. \$\endgroup\$
    – tucuxi
    Commented Apr 27, 2016 at 13:07
  • \$\begingroup\$ You mean this comment? \$\endgroup\$ Commented Apr 27, 2016 at 13:18
  • \$\begingroup\$ Yes - and thanks to you, I now know how to link comments :-) \$\endgroup\$
    – tucuxi
    Commented Apr 27, 2016 at 16:17
  • \$\begingroup\$ Remember, you always learn, no matter your age. The date of the comment is it's link (click on it to be linked to that particular comment). \$\endgroup\$ Commented Apr 27, 2016 at 17:29
1
\$\begingroup\$

Oracle SQL 11.2, 44 bytes

SELECT LEVEL FROM DUAL CONNECT BY LEVEL<=:1;
\$\endgroup\$
1
  • \$\begingroup\$ Nice to see an answer in SQL derivatives! \$\endgroup\$ Commented Apr 27, 2016 at 15:01
1
\$\begingroup\$

C++, 92 81 bytes

#include<cstdio> 
long i,n;int main(){for(scanf("%ld",&n);i++<n;printf("%ld ",i));}

And another version, using iostream, with the same byte count

#include<iostream>
long i,n;int main(){for(std::cin>>n;i++<n;std::cout<<i<<' ');}

Not using long would result in 32-bit integers in most platforms<; also, C++'s iostream library with their std:: namespace are more verbose than C's I/O. (edit - I stand corrected, this is not true)

Update (-9 bytes): Learnt that return was optional in C++ thanks to @anatolyg

\$\endgroup\$
2
  • \$\begingroup\$ Actually, I get exactly the same character count with cstdio as with iostream. Also, C++ doesn't require return 0. \$\endgroup\$
    – anatolyg
    Commented Apr 27, 2016 at 14:46
  • \$\begingroup\$ Thanks for the tip regarding return; also adding an iostream version, as you are again right - same byte count. \$\endgroup\$
    – tucuxi
    Commented Apr 27, 2016 at 16:23
1
\$\begingroup\$

Common Lisp, 39 bytes

Disclaimer: I'm not responsible for any traumatic effect caused by the extreme density of parentheses. It's the language specification's fault. This one has surprisingly few parentheses!

(loop for a from 1 to(read)do(write a))
\$\endgroup\$
0
1
\$\begingroup\$

Brachylog, 7 bytes

:1:efrw

or alternatively

:1:efr.
\$\endgroup\$
1
\$\begingroup\$

Python 3, 43 42 bytes

x,i=int(input()),0
while i<x:i+=1;print(i)

Explained line-by-line:

x,i=int(input()),0
x  =int(input())   # Convert string input to integer, then assign x to it
 ,              ,  # Separate variables
  i=             0 # Assign i to 0
while i<x:i+=1;print(i)
while    :              # Enter a WHILE loop
      i<x               # Set limit
          i+=1          # Count up
              ;         # Separate statements
               print(i) # Print number

Old answer below. Hopefully this one will be able to count up to incl. 2**64-1.


Python 3, 41 bytes

for n in range(1,int(input())+1):print(n)

Ungolfed

for number in range(1, int(input()) + 1):
    print(number)

Explained for those who can't understand

for n in range(1,int(input())+1):print(n)  # Code
for n in                        :          # Initiate a for loop with n as the number
         range( ,              )           # The list of numbers we want to output in order
               1                           # We start with 1
                     input()               # We get n from string input
                 int(       )              # We convert the input to integer
                             +1            # We add one to the range 'cause we want to include n
                                print( )   # We then output
                                      n    # n is what we output
\$\endgroup\$
14
  • \$\begingroup\$ This won't work for all 64-bit integers, so it is invalid by your own rules. \$\endgroup\$
    – Dennis
    Commented Apr 26, 2016 at 18:07
  • \$\begingroup\$ I think it works (language limit). If there is a way to make it work up to 2^64-1, please tell me. \$\endgroup\$ Commented Apr 26, 2016 at 18:38
  • \$\begingroup\$ You can use xrange(). Note: even xrange() may have issues, at least in 2.7.10. \$\endgroup\$
    – user48538
    Commented Apr 26, 2016 at 19:06
  • \$\begingroup\$ I used it in my (sadly, shorter) Python 2 answer. \$\endgroup\$
    – user48538
    Commented Apr 26, 2016 at 19:07
  • 1
    \$\begingroup\$ @EʀɪᴋᴛʜᴇGᴏʟғᴇʀ as you only use your input once, you can just do while i<int(input)) . Also in your older version at 41 bytes, by removing the 1, in you range and the add 1 after the input, and placing either +1 after or -~ before the n in the print, it will be shorter and get the same answer. Also can I ask why your older answer is shorter, but you're not using it? \$\endgroup\$
    – george
    Commented Jun 15, 2016 at 17:45
1
\$\begingroup\$

UGL, 14 11 bytes

ic^l_u$ocO^^-:
il$d:_locO:

Uses U+0000 as delimiter.

Try it online!

Try it online! (14-byte version)

Explanation

This builds [9,8,7,6,5,4,3,2,1] for an input of 9, and then print them all out (with U+0000 as separator).

Explanation for 14 bytes

ic^l_u$ocO^^-:
i               # n = input()
 c              # i = 0
  ^l_     ^^-:  # while i ~= n:
     u$o        #     print(i++)
        cO      #     print(chr(0))
\$\endgroup\$
1
\$\begingroup\$

PHP, 26 23 31 bytes

<?=join(' ',range(1,$argv[1])); // 31 if using N isnt allowed     
<?=join(' ',range(1,$n)); // 25 if using $n is allowed
<?=join(' ',range(1,N)); // 24 bytes, join() is an alias of implode()
<?=implode(' ',range(1,N)); // 27 bytes

"You can get n any way" -> In this case, N is a constant.
Edit: Apperantly "any way" isn't "any way", it now takes commandline arguments

\$\endgroup\$
7
  • 1
    \$\begingroup\$ Hardcoding inputs is not allowed by default, and the author does not override that default (as you can see from this comment). \$\endgroup\$
    – user45941
    Commented Apr 26, 2016 at 9:33
  • \$\begingroup\$ Updated accordingly \$\endgroup\$
    – Martijn
    Commented Apr 26, 2016 at 9:55
  • \$\begingroup\$ @Mego You are correct, I clearly state you must get n. I didn't do any override. \$\endgroup\$ Commented Apr 26, 2016 at 10:48
  • \$\begingroup\$ Which I interpretted as "I get N from a constant" ;) But, changed my answer to the proper interpretation \$\endgroup\$
    – Martijn
    Commented Apr 26, 2016 at 12:30
  • \$\begingroup\$ Isn't the statement-ending semicolon required? Omitting it on an online PHP codepad gives Fatal error: syntax error, unexpected $end, expecting ',' or ';' \$\endgroup\$
    – nickb
    Commented Apr 27, 2016 at 4:05
1
\$\begingroup\$

Dip, 1 - .2 = .8

l

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

\$\endgroup\$
2
  • \$\begingroup\$ Can you provide a link to a Dip interpreter? I can´t find any reference to that language on the web. \$\endgroup\$
    – Titus
    Commented Jul 7, 2017 at 15:20
  • \$\begingroup\$ It was my language but i deleted it \$\endgroup\$
    – Oliver Ni
    Commented Jul 8, 2017 at 16:24
1
\$\begingroup\$

C#, 105 117 109 107 101 99 59 bytes


Golfed

void m(ulong u){while(u>=0)System.Console.WriteLine(u--);}

Ungolfed

void m( ulong u ) {
    while (u >= 0)
        System.Console.WriteLine(u--);
}

Releases

  • v3.0 - -40 bytes - Changed the output to directly print to the console with a new line at the end. This update allows the usage of ulong. Once again, this is thanks to hstde.
  • v2.4 - -2 bytes - Replaced long with int due to the limitations of the capacity of List<T>, which is capped to the max of Int32.MaxValue in the implementation. The reason for changing to int can be found here. You can also explore this limitation in Reference Source.
  • v2.3 - -6 bytes - Using var instead of List<long>. Thanks to hstde.
  • v2.2 - -2 bytes - Fixed the decrements of the counter and removed brackets.
  • v2.1 - -8 bytes - Update to use the argument, making the code shorter and faster.
  • v2.0 - +12 bytes - Update to List<> since arrays max size is Int32.MaxValue == 2 ^ 32 - 1
  • v1.0 - 105 bytes - Initial release
\$\endgroup\$
6
  • \$\begingroup\$ You're still gonna have a problem with anything bigger than int.MaxValue. But you can still shave off some bytes by replacing List<long>l with var l \$\endgroup\$
    – hstde
    Commented Nov 8, 2016 at 10:46
  • \$\begingroup\$ @hstde Unfortunately, as far as I know, the Array and List object in the .Net have a limitation of Int32.MaxValue ( 2 147 483 647 ) items. Although I haven't explore this fully, for what I've read you would most likely ran out of memory than hit the limitation of the objects. Please, correct me if I'm wrong. \$\endgroup\$
    – auhmaan
    Commented Nov 9, 2016 at 14:41
  • \$\begingroup\$ I played around a little and you indeed get an out of memory exception even when using something other then List<>. So the correct implementation would be an iterative from 0 to c. \$\endgroup\$
    – hstde
    Commented Nov 9, 2016 at 14:57
  • \$\begingroup\$ Even if I was able to implement a way to count up to the Int64.MaxValue - which is required by the challenge - I would hit the size limit of the String, which is Int32.MaxValue. \$\endgroup\$
    – auhmaan
    Commented Nov 9, 2016 at 15:14
  • 1
    \$\begingroup\$ You are right. That's why I need to learn to read... \$\endgroup\$
    – auhmaan
    Commented Nov 10, 2016 at 17:47
1
\$\begingroup\$

Labyrinth, 41 29 23 14 bytes

?}):
 \ !
@"({

Try it online!

Takes the input number and moves it to the auxiliary stack and increments an implicit zero on the main stack. Repeatedly duplicates the top of the stack, outputs the number, moves a copy of the input number from the aux stack and decrements it. If that number is zero, the program exits. Otherwise it outputs a newline and continues the loop.

\$\endgroup\$
1
\$\begingroup\$

LibreLogo, 35 bytes

Code:

print set range 1 (int (input ")+1)

Input:

enter image description here

Output:

enter image description here

\$\endgroup\$
1
\$\begingroup\$

Taxi, 1,264 bytes

Line breaks are not required so here's the golfed version:

Go to Post Office: w 1 l, 1 r, 1 l.Pickup a passenger going to The Babelfishery.Go to The Babelfishery: s 1 l, 1 r.Pickup a passenger going to Sunny Skies Park.Go to Sunny Skies Park: n 1 l, 1 l, 1 r.[a]1 is waiting at Starchild Numerology.Go to Starchild Numerology: s 3 l.Pickup a passenger going to Addition Alley.Go to Go More: e 1 l.Go to Addition Alley: w 1 r, 3 r, 1 r.Pickup a passenger going to Cyclone.Go to Cyclone: n 1 l, 1 l.Pickup a passenger going to Cyclone.Pickup a passenger going to The Babelfishery.Go to The Babelfishery: s 1 l, 2 r, 1 r.Pickup a passenger going to Post Office." " is waiting at Writer's Depot.Go to Writer's Depot: n 1 l, 1 l, 2 l.Pickup a passenger going to Post Office.Go to Post Office: n 1 r, 2 r, 1 l.Go to Cyclone: s 1 r, 1 l, 2 r.Pickup a passenger going to Sunny Skies Park.Pickup a passenger going to Equal's Corner.Go to Sunny Skies Park: n 1 r.Pickup a passenger going to Cyclone.Go to Cyclone: n 1 l.Pickup a passenger going to Sunny Skies Park.Pickup a passenger going to Equal's Corner.Go to Sunny Skies Park: n 1 r.Pickup a passenger going to Addition Alley.Go to Equal's Corner: s.Switch to plan "b" if no one is waiting.Go to Taxi Garage: n 3 r, 1 r, 2 l, 2 r.[b]Go to Sunny Skies Park: n.Switch to plan "a".

And the formatted version for humans:

Go to Post Office: w 1 l, 1 r, 1 l.
Pickup a passenger going to The Babelfishery.
Go to The Babelfishery: s 1 l, 1 r.
Pickup a passenger going to Sunny Skies Park.
Go to Sunny Skies Park: n 1 l, 1 l, 1 r.
[a]
1 is waiting at Starchild Numerology.
Go to Starchild Numerology: s 3 l.
Pickup a passenger going to Addition Alley.
Go to Go More: e 1 l.
Go to Addition Alley: w 1 r, 3 r, 1 r.
Pickup a passenger going to Cyclone.
Go to Cyclone: n 1 l, 1 l.
Pickup a passenger going to Cyclone.
Pickup a passenger going to The Babelfishery.
Go to The Babelfishery: s 1 l, 2 r, 1 r.
Pickup a passenger going to Post Office.
" " is waiting at Writer's Depot.
Go to Writer's Depot: n 1 l, 1 l, 2 l.
Pickup a passenger going to Post Office.
Go to Post Office: n 1 r, 2 r, 1 l.
Go to Cyclone: s 1 r, 1 l, 2 r.
Pickup a passenger going to Sunny Skies Park.
Pickup a passenger going to Equal's Corner.
Go to Sunny Skies Park: n 1 r.
Pickup a passenger going to Cyclone.
Go to Cyclone: n 1 l.
Pickup a passenger going to Sunny Skies Park.
Pickup a passenger going to Equal's Corner.
Go to Sunny Skies Park: n 1 r.
Pickup a passenger going to Addition Alley.
Go to Equal's Corner: s.
Switch to plan "b" if no one is waiting.
Go to Taxi Garage: n 3 r, 1 r, 2 l, 2 r.
[b]
Go to Sunny Skies Park: n.
Switch to plan "a".

I can't find any documentation on integer limits, but my testing seems to show that Taxi can handle up to 64 bit signed integers but not un-signed. That means it can only count up to (2^63)-1.

\$\endgroup\$
1
\$\begingroup\$

Stax, 1 byte

m

Run and debug online!

Added for completeness. That's it. Stax does it in 1 byte.

\$\endgroup\$
1
\$\begingroup\$

Pepe, 30 25 bytes

That's an amazing score for Pepe!

And now, I've saved 5 bytes because of the "flags" update. Now, instead of duplicating the item, I can set a flag to not remove it.

Also, Pepe seems to beat few practical languages now.

REeEREErEEEEErreEEreeERee

Try it online

This challenge made me rethink the control flows in Pepe. It helped me realize that I've created them completely wrong, so I remade them. ¯\_(ツ)_/¯ Thanks!

Warning: If you don't give any input or it will be smaller than 0, your browser will die.

Don't know if the bonus applies, if int's in JS support these numbers, then yes, otherwise no. My PC is not strong enough to print this large number in HTML.

Ungolfed:

REeE
REE
  rEEEEE
  r reEE
  reeE
Ree

Explanation:

  • REeE - Input number to stack R
  • REE - Define label input
    • rEEEEE - Increment item in stack r
    • rEEEeE - Duplicate item in stack r
    • r reEE - Pop Get value from stack r and print popped item as number - Flag r prevents removal of the item
    • reeE - Output newline
  • Ree - Goto label input if selected items in both stacks are equal

Basically, loop until the certain value is reached.

\$\endgroup\$
1
\$\begingroup\$

Brain-Flak, 14 bytes

{(({})[()])}{}

Try it online!

simply pushes the top stack value -1 until it reaches 0. Then it pops the zero and implicitly prints the stack

\$\endgroup\$
1
\$\begingroup\$

MAWP 1.0, 30 bytes

%@_1A[1A~25WWM~]~[!1A]%[:48W;]

Output takes a little while for larger numbers.

Try it!

\$\endgroup\$
1
\$\begingroup\$

Flurry, 16 - 3.2 = 12.8 bytes

{}{<><<>()>[]}{}

Run example

$ ./flurry -inn -c "{}{<><<>()>[]}{}" 15
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
$ ./flurry -inn -c "{}{<><<>()>[]}{}" 1
1

Generates the range using the stack height. Since the task requires 1-based, each stack height should be incremented (produce 2 when stack height is 1, 3 when stack height is 2, etc.).

main = {} f {}   -- n f 1
                 -- Apply f n times to the starting value of 1
f = {<><<>()>[]} -- \x. push(x); return (succ height)
                 -- Implicitly push the argument and ignore it,
                 -- returning the value of height + 1
                 -- so that it can be pushed at the next iteration

Flurry uses Church numerals as the number representation, so it theoretically supports infinite-precision positive integers. But it will take a very long time to actually print the result.

\$\endgroup\$
1
\$\begingroup\$

Thunno 2, 1 byte

R

Attempt This Online!

Pretty simple.

\$\endgroup\$
1
\$\begingroup\$

Rockstar, 44 bytes

listen to N
X's 0
while N-X
build X up
say X

Try it here (Code will need to be pasted in)

\$\endgroup\$
1
\$\begingroup\$

Desmoslang Assembly, 8 Bytes

[1...IOT

Explanation: The ending bracket is automatically added, you can output lists, and [1...x] creates a list counting 1 through x.

\$\endgroup\$
1
\$\begingroup\$

(,) 352 243 Chars or \$243\log_{256}(3)\approx48.14\$ Bytes

(()(),()()()()()()())(,(((),(())(),,,(()()())()(),(())(()(),,,,(),,(()())))((()()),((()()),,,,(),,(()())()()())((),(,,,,,())))((),(())(),,,((()())),(())())((()()),((),(,,,,,())))),,,(,(()()(),((()))))(()()()),())(,,()((),(())()),,(),,((()())))

TIO

If we can take input in unary, 27 Chars or \$27\log_{256}(3)\approx\$5.35 Bytes:

(,,((),(())())(),,((()())))

TIO

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

C++, 91 bytes

Golfed:

#include<iostream>
int main(){int c;std::cin>>c;for(int x=1;x<=c;x++){std::cout<<x<<"\n";}}

Ungolfed:

#include<iostream>
int main(){
    int c;
    std::cin>>c;
    for(int x = 1; x <= c; x++){
        std::cout<<x<<"\n";
    }
}
\$\endgroup\$
9
  • \$\begingroup\$ No C++ expert, but I think that int must return something. \$\endgroup\$ Commented Apr 25, 2016 at 16:49
  • \$\begingroup\$ Actually, no. The 'return 0' is implied by almost all modern compilers. \$\endgroup\$ Commented Apr 25, 2016 at 17:04
  • \$\begingroup\$ does std::cin>>c work i though it would cause type cast error char* to int... \$\endgroup\$ Commented Apr 26, 2016 at 1:11
  • \$\begingroup\$ @MartinBarker That error only occurs if the user inputs something other than an int. \$\endgroup\$ Commented Apr 26, 2016 at 3:13
  • 1
    \$\begingroup\$ You can declare x together with c to spare the second use of int, no need for the braces around a single instruction after for, you can increment x when outputting it so not need to mention it again inside for. At least g++ 5.2.1 accepts this (of course, after the include): int main(){int c,x;std::cin>>c;for(x=1;x<=c;)std::cout<<x++<<"\n";}. \$\endgroup\$
    – manatwork
    Commented Apr 26, 2016 at 7:29
0
\$\begingroup\$

TI-Basic, 11 bytes

For(I,1,Ans:Disp I:End

I would do seq(I,I,1,Ans for 8 bytes but lists can't support 2^64 elements

\$\endgroup\$
3
  • \$\begingroup\$ Could you support 2^64-1 with seq(I,I,1,Ans? \$\endgroup\$ Commented Apr 26, 2016 at 8:17
  • \$\begingroup\$ @ΈρικΚωνσταντόπουλος Yes, as a single element, but the entire sequence would exceed the 999 element limit for a list, and exceed the calculator's memory. \$\endgroup\$
    – Timtech
    Commented Apr 26, 2016 at 18:41
  • \$\begingroup\$ Then keep your 11-keystroke solution. \$\endgroup\$ Commented Apr 26, 2016 at 18:42
0
\$\begingroup\$

Bash, 34 Bytes

for ((i=1;i<=$1;i++)); { echo $i;}

Split answer from GNU coreutils, this is pure bash.

\$\endgroup\$
9
  • 3
    \$\begingroup\$ for((;i++<$1;));{ echo $i;} - 27 bytes. But bash uses 64 bit signed integers, so this will only go as far as 2^31 - 1 \$\endgroup\$ Commented Apr 25, 2016 at 17:54
  • \$\begingroup\$ That's the limit for 32 bit integers, not 64. \$\endgroup\$ Commented Apr 26, 2016 at 5:31
  • \$\begingroup\$ @DigitalTrauma 64-bit integers meet the spec (2^64-1), 32-bit ints don't. It's fine, though. \$\endgroup\$ Commented Apr 26, 2016 at 8:19
  • 1
    \$\begingroup\$ The sign uses one of the 64 bits (not half of them!), so bash's maximum is 2^63-1 (empirically verified). \$\endgroup\$ Commented Apr 26, 2016 at 14:39
  • \$\begingroup\$ @CatsAreFluffy ha - of course I meant 2^63-1. 2^31 is an old force of habit I suppose. Still doesn't meet the spec IMO. \$\endgroup\$ Commented Apr 26, 2016 at 14:57
0
\$\begingroup\$

PGP, 28 Bytes

PHP Golf Processor (https://github.com/barkermn01/PGP-php-CodeGolf/) to run it php pgp.php file.pgp or php pgp.php '{code here}'

f(;$i!=$argv[1];)e ++$i." "; 
\$\endgroup\$
3
  • \$\begingroup\$ Can't you remove the space? e ++ \$\endgroup\$ Commented Apr 29, 2016 at 17:49
  • \$\begingroup\$ Not yet, your welcome to code it it in and send me a pull request :) \$\endgroup\$ Commented Apr 30, 2016 at 21:16
  • 1
    \$\begingroup\$ how about f(;$i++!=$argv[1];)e"$i ";? \$\endgroup\$
    – Titus
    Commented Jul 26, 2016 at 1:38
0
\$\begingroup\$

Molecule, 10 bytes

0{1+~}InL.

Explanation:

0{1+~}InL.
0          Push 0
 {1+~}     Create a code block
      In   Ask the amount of times to repeat
        L. Loop the code block n times and clean the stack.
\$\endgroup\$

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.