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
nany way. - You can assume that
nwill always be a positive integer. - You can get
nin 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.
149 Answers 149
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.
-
1\$\begingroup\$ Python 2, to be exact :) \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2016年04月25日 12:20:13 +00:00Commented Apr 25, 2016 at 12:20
-
\$\begingroup\$ 33 bytes ->
for i in range(input()):print i+1\$\endgroup\$dieter– dieter2016年04月25日 12:24:19 +00:00Commented Apr 25, 2016 at 12:24 -
2\$\begingroup\$ 32 bytes ->
for i in range(input()):print-~i\$\endgroup\$orlp– orlp2016年04月25日 12:25:22 +00:00Commented Apr 25, 2016 at 12:25 -
1\$\begingroup\$ "Presumably works up to
2**64and beyond." - doubt it in Python 2, but it might withxrange(edit: evenxrangemight have issues, at least in 2.7.10) \$\endgroup\$Sp3000– Sp30002016年04月25日 12:34:07 +00:00Commented Apr 25, 2016 at 12:34 -
\$\begingroup\$ How does
-~work? Edit: I figured it out. Also, nice trick! \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2016年04月27日 08:26:53 +00:00Commented Apr 27, 2016 at 8:26
Zsh, 12 bytes
echo {1..1ドル}
This works because variables are expanded before the braces.
-
2\$\begingroup\$ I'm not sure you can count up to 2^64 (or even quite a bit less) ? \$\endgroup\$Olivier Dulac– Olivier Dulac2016年04月25日 15:50:47 +00:00Commented Apr 25, 2016 at 15:50
-
\$\begingroup\$ @OlivierDulac
2^64-1is fine now. \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2016年04月26日 08:17:48 +00:00Commented Apr 26, 2016 at 8:17 -
1\$\begingroup\$ zsh's maximum is
2^63 - 1\$\endgroup\$joeytwiddle– joeytwiddle2016年04月26日 14:49:57 +00:00Commented Apr 26, 2016 at 14:49
V, 11 Bytes
é1@añYpñdd
Since this contains nasty UTF-8 and unprintables, here is a reversible hexdump:
00000000: e931 4061 f159 7001 f164 64 [email protected]
V is an unfinished language I wrote, but this is working as of commit 19. This answer was a little more verbose than I'd like, but that's mostly because V has no knowledge of integers, only strings. So it's a decent answer! This will work up to 2^64, but it will probably take a very long time.
To make my explanation easier to read/write, I will work with this "Human readable form", which is actually how you would type this in vim.
<A-i>1@a<A-q>Yp<C-a><A-q>dd
Explanation:
'Implicit: register "a" == arg 1, and any generated text is printed.
<A-i>1 'Insert a single character: "1"
@a ' "a" times,
<A-q> <A-q> 'Repeat the following:
Yp<C-a> 'Duplicate the line, and increment it
dd 'Delete the last line, since we have one too many.
If loopholes are allowed, here's a shorter version that prints 1 to n, but also prints a 0 (8 bytes):
é0@añYp
And in readable form:
<A-i>1@a<A-q>Yp<C-a>
This is shorter because the <A-q> at the end is implicit, so we don't need it if we don't have to delete the last line.
-
\$\begingroup\$ It can take as long as it wants. Glad to see an answer to work with 2^64, especially with an unfinished language. +1 \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2016年04月25日 13:42:36 +00:00Commented Apr 25, 2016 at 13:42
-
\$\begingroup\$ I have changed the limit to 2^64-1 because standard loopholes are disallowed now, and I don't want to cut answers out too much. \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2016年04月26日 08:10:35 +00:00Commented Apr 26, 2016 at 8:10
JavaScript (ES6), (削除) 84 (削除ここまで) 80 bytes
x=>{for(n=[r=i=0];r!=x;)(n[i]=-~n[i++]%10)&&alert(r=[...n].reverse(i=0).join``)}
Input is a string. Outputs as alert. Change alert to console.log if you want to keep your sanity.
I tried a few different methods then went to the print to infinity question to see how the JS answer there did it and found that I was the one who answered it. *facepalm* This approach is actually shorter though, so it worked out fine.
Hoon, 13 bytes
(cury gulf 1)
++gulf returns a list containing the numbers from a to b. Returned a curried function with 1 for a.
Usage:
> %. 9
(cury gulf 1)
~[1 2 3 4 5 6 7 8 9]
-
1\$\begingroup\$ I read this as "curry golf" :P \$\endgroup\$Downgoat– Downgoat2016年04月27日 21:57:45 +00:00Commented Apr 27, 2016 at 21:57
JavaScript (ES6), 99 (削除) 103 (削除ここまで)
String increment using regexp, not limit except the string length
Edit 1 byte saved thx @user81655
x=>{for(a='';a!=x;console.log(a=(' '+a).replace(/.9*$/,x=>++x[0]+'0'.repeat(x.length-1)).trim()));}
Test
f=x=>{for(a='';a!=x;console.log(a=(' '+a).replace(/.9*$/,x=>++x[0]+'0'.repeat(x.length-1)).trim()));}
console.log=x=>o.push(x)
function test() {
var v = I.value
o=[]
if (/^\d+$/.test(v)) f(v)
else console.log('Invalid number' + v)
if(o.length > 30) o.splice(15,o.length-30,'','...','');
O.textContent=o.join`\n`
}
test()
<input id=I value=10000><button onclick='test()'>go</button>
(this test snippet will show just the first and last 15 lines of the output)
<pre id=O></pre>
-
\$\begingroup\$ Interesting approach. I think you can use
a=''at the start because the added space works as a0anyway. \$\endgroup\$user81655– user816552016年04月26日 14:46:08 +00:00Commented Apr 26, 2016 at 14:46 -
\$\begingroup\$ I think you can omit the last semicolon. \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2016年06月18日 09:25:51 +00:00Commented Jun 18, 2016 at 9:25
-
\$\begingroup\$ @EʀɪᴋᴛʜᴇGᴏʟғᴇʀ you can't, a for statement needs a body \$\endgroup\$edc65– edc652016年06月18日 09:54:33 +00:00Commented Jun 18, 2016 at 9:54
-
\$\begingroup\$ @edc65 Like when the last statement does not need the semicolon... \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2016年06月18日 09:55:49 +00:00Commented Jun 18, 2016 at 9:55
-
\$\begingroup\$ @EʀɪᴋᴛʜᴇGᴏʟғᴇʀ ??? (anyway, try it, it won't work) \$\endgroup\$edc65– edc652016年06月18日 10:01:44 +00:00Commented Jun 18, 2016 at 10:01
C++14, 142 bytes
#include<numeric>
#include<list>
using namespace std;[](auto n)->list<decltype(n)>{list<decltype(n)>t(n);iota(t.begin(),t.end(),1);return t;};
This declares an anonymous lambda function which can be captured and subsequently called. The function returns a std::list containing values of the same type as n. The unsigned long long data type can be used on 64-bit machines to support the full 64-bit unsigned integer range (calling it like f(18446744073709551615ULL)).
-
\$\begingroup\$ I think this is only valid in C++14, not C++11 \$\endgroup\$anatolyg– anatolyg2016年04月27日 14:51:21 +00:00Commented Apr 27, 2016 at 14:51
-
\$\begingroup\$ @anatolyg
std::iota,std::decltype,long longand lambda functions were all added in C++11. \$\endgroup\$user45941– user459412016年04月27日 18:34:28 +00:00Commented Apr 27, 2016 at 18:34 -
\$\begingroup\$ I mean, a lambda function with
auto-typed argument. Isn't it new in C++14? \$\endgroup\$anatolyg– anatolyg2016年04月27日 19:05:35 +00:00Commented Apr 27, 2016 at 19:05 -
\$\begingroup\$ @anatolyg Oh, you're right, I forgot that generic lambdas weren't added until C++14. Fixing it now, thanks! \$\endgroup\$user45941– user459412016年04月27日 19:06:47 +00:00Commented Apr 27, 2016 at 19:06
-
\$\begingroup\$ Do you need newline after
std;? \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2016年04月29日 17:43:49 +00:00Commented Apr 29, 2016 at 17:43
PowerShell, (削除) 32 (削除ここまで) 26 bytes
After reading the question thoroughly, I realized that my original answer does not support up to 2^64-1 since the range operator (..) in PS only supports 32bit integers.
Corrected answer:
(削除) for($x=0;$x-le$args[0];$x++){$x} (削除ここまで)
while($x++-ne$args[0]){$x}
Usage (save as count.ps1):
PS>count.ps1 8
1
2
3
4
5
6
7
8
Old method, supports only up to 2^32-1 taking input from the pipeline:
%{1..$_}
Since expressions are only allowed as the first element in the PowerShell pipeline, I have to wrap it in a foreach (%).
Turing Machine Simulator - 1366 Bytes (124 Lines)
0 * * r 0
0 _ , r 1
1 _ 1 r ,
, _ , l 2
2 * * l 2
2 , * l 3
3 _ * r 4
3 1 0 l 4
3 2 1 l 4
3 3 2 l 4
3 4 3 l 4
3 5 4 l 4
3 6 5 l 4
3 7 6 l 4
3 8 7 l 4
3 9 8 l 4
3 0 9 l 3
4 * * l 4
4 _ * r 5
5 0 _ r 5
5 , * * n
5 * * r 6
6 * * r 6
6 , * r 9
9 * * r 9
9 _ * l z
z * * l m
m * * l m
m , * r 7
7 * * r 7
7 , * * x
7 0 p r p
7 1 q r q
7 2 w r w
7 3 e r e
7 4 r r r
7 5 t r t
7 6 y r y
7 7 u r u
7 8 i r i
7 9 o r o
8 * * l 8
8 , * l m
p * * r p
p . * r P
p _ . r P
P * * r P
P _ 0 l 8
q * * r q
q . * r Q
q _ . r Q
Q * * r Q
Q _ 1 l 8
w * * r w
w . * r W
w _ . r W
W * * r W
W _ 2 l 8
e * * r e
e . * r E
e _ . r E
E * * r E
E _ 3 l 8
r * * r r
r . * r R
r _ . r R
R * * r R
R _ 4 l 8
t * * r t
t . * r T
t _ . r T
T * * r T
T _ 5 l 8
y * * r y
y . * r Y
y _ . r Y
Y * * r Y
Y _ 6 l 8
u * * r u
u . * r U
u _ . r U
U * * r U
U _ 7 l 8
i * * r i
i . * r I
i _ . r I
I * * r I
I _ 8 l 8
o * * r o
o . * r O
o _ . r O
O * * r O
O _ 9 l 8
x * * r x
x _ , l b
b . 1 l c
b 0 1 l c
b 1 2 l c
b 2 3 l c
b 3 4 l c
b 4 5 l c
b 5 6 l c
b 6 7 l c
b 7 8 l c
b 8 9 l c
b 9 0 l b
c * * l c
c _ * r v
v * * r v
v , * * 2
n * * r n
n _ * r halt
n , _ r n
n . _ r n
n p 0 r n
n q 1 r n
n w 2 r n
n e 3 r n
n r 4 r n
n t 5 r n
n y 6 r n
n u 7 r n
n i 8 r n
n o 9 r n
You can try it out here - link Just set the initial input to the upper limit.
Supports arbitrarily large integers
-
\$\begingroup\$ Where is the spec for this language? \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2016年07月19日 17:05:31 +00:00Commented Jul 19, 2016 at 17:05
-
\$\begingroup\$ @EʀɪᴋᴛʜᴇGᴏʟғᴇʀ It should be a the bottom of the page in the link \$\endgroup\$KoreanwGlasses– KoreanwGlasses2016年07月19日 17:06:51 +00:00Commented Jul 19, 2016 at 17:06
-
\$\begingroup\$ Not the syntax, the states, what they mean, etc. \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2016年07月19日 17:08:08 +00:00Commented Jul 19, 2016 at 17:08
-
\$\begingroup\$ @EʀɪᴋᴛʜᴇGᴏʟғᴇʀ Is this what you're looking for? en.wikipedia.org/wiki/Turing_machine#Informal_description \$\endgroup\$KoreanwGlasses– KoreanwGlasses2016年07月19日 17:16:09 +00:00Commented Jul 19, 2016 at 17:16
-
\$\begingroup\$ No, i wouldn't have asked if it was there. I don't mean the syntax, or how the states work, I mean what the states are. \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2016年07月19日 18:09:22 +00:00Commented Jul 19, 2016 at 18:09
JAISBaL, 15 bytes
c1I0 ̄K0DQc1+I0 ́
Verbose:
# \# enable verbose parsing #\
pushnum 1 \# push 1 onto the stack #\
store 0 \# store the top value of the stack into var0 #\
for \# start for loop #\
load 0 \# push the value in var0 onto the stack #\
duplicate \# duplicate the top value of the stack #\
popoutln \# pop the top value off a stack and print it with a new line #\
pushnum 1 \# push 1 onto the stack #\
add \# add the top two values of the stack #\
store 0 \# store the top value of the stack into var0 #\
end \# end current language construct #\
JAISBaL Noncompeting Answers These answers are noncompeting because they use the "range" instruction, which I added because of this challenge. I did not add them specifically to complete this challenge, rather this challenge brought the need for a range instruction to my attention.
Manual output, 4 bytes: (Manual output because the output at the end of a JAISBaL program can be considered debug information, although it is always enabled)
c1ØP
Verbose:
# \# enable verbose parsing #\
pushnum 1 \# push 1 onto the stack #\
rangein \# push an array containing all numbers in the range of the two numbers on the top of the stack, inclusivley #\
popout \# pop the top value of a stack and print it #\
Implicit Output, 3 bytes:
c1Ø
Same concept as the manual output answer, just without the print instruction.
Instruction codes and testing compatible with JAISBaL-0.0.6
-
\$\begingroup\$ +1 for interest. Remember to +1 on challenges that you're interested in, and fav the most challenging ones. \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2016年07月25日 05:17:12 +00:00Commented Jul 25, 2016 at 5:17
Python 3, 31 bytes
print(*range(1,int(input())+1))
Outputs the range of numbers space-separated. Uses * operator magic to explode the output of range into separate arguments to print, which separates its arguments with spaces by default.
><>, 10 bytes
lnao:l(?;:
Input should be on stack before execution. Can be done via command line by launching the program with the -v flag, I've yet to understand how/if this should be counted.
Explanation
At each iteration we print the length of the stack followed by a newline (lnao), then if the length of the stack has reached the input number we end the program (:l(?;), otherwise we duplicate the top of the stack (which will bethe input number) and continue.
T-SQL, 61 bytes
DECLARE @ INT=0L:SET @+=1PRINT @ IF @<(SELECT i FROM t)GOTO L
I used a different technique than Pete Arden's SQL answer. I took my input from column i of pre-existing table t, per our IO standards.
Formatted:
DECLARE @ INT=0
L:
SET @+=1
PRINT @
IF @<(SELECT i FROM t) GOTO L
-
\$\begingroup\$ Wow...this is so terse for SQL. \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2017年06月30日 16:42:03 +00:00Commented Jun 30, 2017 at 16:42
PHP, 26 bytes -20% = 20.8
<?=join(_,range(1,$argn));
run as pipe with -F.
or
while($i<$argn)echo++$i,_;
prints one trailing delimiter; run as pipe with -nR.
-
\$\begingroup\$ Please seprate this answer. We don't want polyglots in this challenge. \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2016年06月07日 16:40:06 +00:00Commented Jun 7, 2016 at 16:40
-
\$\begingroup\$ @Erik Kona is an open-source implementation of the proprietary k language - they're equivalent rather than separate \$\endgroup\$Simon Major– Simon Major2016年06月08日 09:20:12 +00:00Commented Jun 8, 2016 at 9:20
-
\$\begingroup\$ Doesn't "Kona" have less abilities than "K" then? \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2016年06月08日 09:47:03 +00:00Commented Jun 8, 2016 at 9:47
-
\$\begingroup\$ Presently, yeah, but it's aiming to be a full implementation of k. At which point it's the same thing as with Cython, Jython or IronPython - it's all a matter of semantics. \$\endgroup\$Simon Major– Simon Major2016年06月08日 19:27:41 +00:00Commented Jun 8, 2016 at 19:27
-
\$\begingroup\$ I prefer to be notified (and no,
@Erikis not a notification, use@EʀɪᴋᴛʜᴇGᴏʟғᴇʀinstead), not the last commenter. @SimonMajor \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2016年06月09日 06:41:20 +00:00Commented Jun 9, 2016 at 6:41
Excel VBA, (削除) 48 (削除ここまで) (削除) 47 (削除ここまで) (削除) 46 (削除ここまで) (削除) 22 (削除ここまで) 21 Bytes
Immediates Window Function
Anonymous VBE Immediates Windows Function that takes input of the expected type Variant\Integer and from cell [A1] outputs to the VBE immediates window
For I=1To[A1]:?I:Next
Old Subroutine Version
Code:
Sub F(N):For I=1To N:Cells(I, 1)=I:Next:End Sub
Usage:
Sub Test(): F 100: End Sub
Changes:
-24 Bytes for converting to Immediates Window Function
-1 Byte for condensing I=1 To to I=1To
-1 Byte thanks to Engineer Toast for Changing Cells(I,1) to Debug.?
-1 Byte for removing whitespace
Output to ActiveSheet, (削除) 30 (削除ここまで) 28 Bytes
Anonymous VBE immediate window function that takes input from range [A1] and outputs to the range [1:1]
[A1].Resize([A1],1)="=Row()"
-2 Bytes for removing A1 from Row(A1)
-
1\$\begingroup\$ You can save 5 bytes by switching from
Cells(I, 1)=ItoDebug.?I\$\endgroup\$Engineer Toast– Engineer Toast2017年03月29日 19:10:35 +00:00Commented Mar 29, 2017 at 19:10 -
1\$\begingroup\$ Also, this only works up to a certain point before VBA cuts off the significant digits. After that, iterating by 1 won't work because it'll truncate it and return the same value. \$\endgroup\$Engineer Toast– Engineer Toast2017年03月29日 19:32:09 +00:00Commented Mar 29, 2017 at 19:32
-
\$\begingroup\$ @EngineerToast I have corrected this, thanks for pointing it out :) \$\endgroup\$Taylor Raine– Taylor Raine2017年03月30日 02:57:00 +00:00Commented Mar 30, 2017 at 2:57
Stack Cats with -nl, 18 bytes
*(>]>{<:_-!:]}[*)>
Flags are not counted as bytes, but as a separate language as per this Meta consensus.
Flags:
-nto do integer I/O-lto implicitly mirror to the left; the actual code is<(*]{[:!-_:>}<[<)*(>]>{<:_-!:]}[*)>.
Adapted from this answer for printing out 1 to 10. I had to fall back to the <(...)*(...)> structure to handle the input correctly. (I once tried _(...)_(...)_ instead, but I realized it is incorrect for n=1.)
How it works:
[-1 n*]
< [*] [-1 n]
(..) Skip
* [1*] [-1 n]
(
>]> [1] [-1] [n] [*]
{ Remember 0
<: [1] [-1] [n 0*] [...]
_-! [1] [-1] [n n-1*] [...]
:] [1] [-1] [n-1] [... n*]
} Exit if top is 0
[ Remove 0 at the top
* Make the top positive
) Top = 1; exit
> Return to the stack of numbers
-
\$\begingroup\$
-nlis not "+4", and this isn't Stack Cats, but Stack Cats +O:-nl(you aren't forced to this specific header). \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2018年03月13日 10:00:53 +00:00Commented Mar 13, 2018 at 10:00 -
\$\begingroup\$ @EriktheOutgolfer I'm just following the answers by Martin Ender and Sp3000, and I haven't seen any other submission using that kind of header. \$\endgroup\$Bubbler– Bubbler2018年03月13日 23:12:14 +00:00Commented Mar 13, 2018 at 23:12
-
\$\begingroup\$ True, it's a new consensus, ~1 month old or something IIRC. You're not required to put that all in the header though, if it feels uncomfortable. \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2018年03月13日 23:20:07 +00:00Commented Mar 13, 2018 at 23:20
Integral, 8 Bytes
⌡◙▲さんかく⌡•▼e
Explanation
(space) Push 1
⌡◙▲さんかく⌡ "◙▲さんかく", standing for "duplicate, increment" when evaluated
• Swap third-to-top to the top
▼ Decrement
e Repeat that many times
-
\$\begingroup\$ Similar 8 bytes:
▼ ⌡◙▲さんかく⌡•e\$\endgroup\$2020年08月06日 11:32:58 +00:00Commented Aug 6, 2020 at 11:32
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.
QBIC, 6 bytes
:[a|?b
Start a FOR-loop ranging from 1 (default start of FOR-loops) to a, where a is read by : from the command line parameters. At every iteration, b (our FOR-loop counter) is printed (?).
AWK 18.4 (削除) 25 (削除ここまで) (削除) 23 bytes (削除ここまで)
Score includes 21 bytes of code, 2 bytes for option -M (added to support arbitrary precision) and -4.6 bonus.
{for(;j<1ドル;)print++j}
Note: The TIO link will halt after it fills its buffer, or after it runs for more than 60 seconds.
The following version shows how to count the last 10 integers that preceed the input to verify accuracy.
{for(j=1ドル-10;j<1ドル;)print++j}
-
2\$\begingroup\$ Not initialising with
j=0is ugly but ok here. :-) \$\endgroup\$rexkogitans– rexkogitans2016年04月25日 15:02:27 +00:00Commented Apr 25, 2016 at 15:02 -
\$\begingroup\$ should be "<1ドル" (you go from 0 to 1ドル-1, as you ++ before you print). You can also drop the {} after while, as you only have 1 command :
{for(;j<1ドル;)print++j}. But :1ドルis not valid in awk.. you're mixing shell's variable and awk variables. If you want 1,ドル you also need to add theawk "..."wrapping ... \$\endgroup\$Olivier Dulac– Olivier Dulac2016年04月25日 15:40:28 +00:00Commented Apr 25, 2016 at 15:40 -
\$\begingroup\$ @OlivierDulac I can't use <1ドル since j starts at 0, the first
++gets it up to 1, so I need the<=. I didn't think I would need theawk "..."part since this could simply be placed in a file and called however you like (essentially like compiling a file in other languages). E.g. awk -f FILE <<< 21657 \$\endgroup\$Robert Benson– Robert Benson2016年04月25日 17:27:23 +00:00Commented Apr 25, 2016 at 17:27 -
2\$\begingroup\$ @RobertBenson: If you edit (gain 2 bytes by taking out the curly braces around the printf, for example, and include a note showing the way to invoke it (like the one in your last comment), you'll gain 2 bytes + I would be able to revert my downvote to a vote. (right now it's locked "until it is edited") \$\endgroup\$Olivier Dulac– Olivier Dulac2016年04月26日 06:55:22 +00:00Commented Apr 26, 2016 at 6:55
-
1\$\begingroup\$ I don't see why you would need it to be <= to account for 0, as 0 is still less than the input. it seems to work for me: Try it online! \$\endgroup\$guest4308– guest43082024年12月23日 06:42:40 +00:00Commented Dec 23, 2024 at 6:42
AutoHotKey, 58 bytes
Golfed and ungolfed are the same.
Golfed:
Ungolfed:
c:=0
x:=0
InputBox, x
while c<x{
c:=c+1
tooltip %c%
}
-
1\$\begingroup\$ Are you sure you need:=0 and not just =0 \$\endgroup\$downrep_nation– downrep_nation2016年04月26日 06:49:37 +00:00Commented Apr 26, 2016 at 6:49
-
\$\begingroup\$ @downrep_nation Yes \$\endgroup\$Michelfrancis Bustillos– Michelfrancis Bustillos2016年04月27日 13:36:35 +00:00Commented Apr 27, 2016 at 13:36
-
1\$\begingroup\$ (sorry fo the late comment) but don't you need some form of
x:? \$\endgroup\$Conor O'Brien– Conor O'Brien2016年06月06日 19:09:48 +00:00Commented Jun 6, 2016 at 19:09
Bash, 17 bytes
eval echo {1..1ドル}
-
2\$\begingroup\$ I'm not sure you can count up to 2^64 (or even quite a bit less) ? \$\endgroup\$Olivier Dulac– Olivier Dulac2016年04月25日 15:50:31 +00:00Commented Apr 25, 2016 at 15:50
-
1\$\begingroup\$ Isn't this limited by the maximum length of command line which is unlikely to gain 2^64 times average length of numbers? \$\endgroup\$rexkogitans– rexkogitans2016年04月26日 20:58:34 +00:00Commented Apr 26, 2016 at 20:58
-
1\$\begingroup\$ @rexkogitans The
ARG_MAXconstant is a kernel limit for theexec()system call, butechois a Bash built-in, so noexec()is involved, and thus you can build the argument list to fill up available memory if you like. Unfortunately, this solution does precisely that. But given enough time and memory, it works up to the maximum number allowed in arithmetic expressions, which seems to be only 2^32-1 on OSX Yosemite (Bash 3.2) but should work up to the specified limit with newer versions. \$\endgroup\$tripleee– tripleee2016年04月27日 04:53:05 +00:00Commented Apr 27, 2016 at 4:53 -
\$\begingroup\$ @tripleee, yes it was exactly
ARG_MAXI was thinking of, but this solution only expands the string twice. So, no reason forARG_MAX. However, it loads the entire output into memory first (could become a problem with higher values). \$\endgroup\$rexkogitans– rexkogitans2016年04月27日 06:38:09 +00:00Commented Apr 27, 2016 at 6:38 -
\$\begingroup\$
eval "echo -e \"\n\"{1..1ドル}"to separate numbers with a newline. \$\endgroup\$Yeti– Yeti2016年05月21日 22:12:42 +00:00Commented May 21, 2016 at 22:12
J - 27 bytes
9!:37[0 _ _ _
(,~<:@{.)^:<:
Usage
(,~<:@{.)^:<: 20x
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Explanation
This avoids using the built-in i. to generate a range.
First, J will truncate output if it's too long, so we disable that by setting the values to infinity _
9!:37[0 _ _ _
Second, the input has to be given as an extended integer, which can be done by marking it with a suffix of x.
The actual function is only 13 bytes, the change in settings another 13 bytes, and the newline between them is a byte, so 13 + 1 + 13 = 27.
(,~<:@{.)^:<:
<: - Decrement the input
^: - Repeat the given verb that many times, nesting its calls
{. - Take the head of the input
<: - Decrement it
,~ - Prepend it to the input
Befunge, 21 bytes
&>: v
@^-1:_>,#a:#._
Counts down on the stack, then counts up. Compliance to the 2^64 rule may depend on implementation.
-
\$\begingroup\$ Rule is 2^64-1 because I was forced to deny standard loopholes. \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2016年04月26日 08:20:58 +00:00Commented Apr 26, 2016 at 8:20
PHP, 32 bytes
for(;$i!=$argv[1];)echo++$i." ";
(削除) 57 Bytes
$c=function($e){$i=0;while($i!=$e)echo ++$i." ";};$c(10);
(削除ここまで)
-
\$\begingroup\$ i just wish some would make a CG version of php just change reserved words into letters E.G
function = func,while = wfor = fforeach = fe\$\endgroup\$Martin Barker– Martin Barker2016年04月25日 14:30:14 +00:00Commented Apr 25, 2016 at 14:30 -
\$\begingroup\$ I want it starting at 1. \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2016年04月25日 16:06:13 +00:00Commented Apr 25, 2016 at 16:06
-
1\$\begingroup\$ You can trim your solution down to 32 bytes:
for(;$i!=$argv[1];)echo++$i." ";. \$\endgroup\$insertusernamehere– insertusernamehere2016年04月25日 21:55:56 +00:00Commented Apr 25, 2016 at 21:55 -
\$\begingroup\$ @insertusernamehere If your language does not have any way to support huge integers up to 2^64, the upper limit of that particular language must be supported instead \$\endgroup\$Martin Barker– Martin Barker2016年04月26日 01:05:27 +00:00Commented Apr 26, 2016 at 1:05
-
1\$\begingroup\$ If you increment inside the
for, then you can spare 1 character by replacing string concatenation with variable embedding. I think another character can be spared by replacing!=with<(though not sure, not read the entire requirement).for(;$i++<$argv[1];)echo"$i ";\$\endgroup\$manatwork– manatwork2016年04月26日 07:22:43 +00:00Commented Apr 26, 2016 at 7:22
Julia, 11 bytes
n->[1:n...]
This is an anonymous function that accepts an integer and returns an array from 1 to the input. This can handle large inputs just fine, it just requires passing n as a larger type, e.g. Int128 or BigInt.
-
\$\begingroup\$ You may be able to implement support for large integers without providing a different type (although there is no such thing in the rules, it's still a creative idea). \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2016年04月29日 17:34:56 +00:00Commented Apr 29, 2016 at 17:34
nany way." Does that mean we can assumento be saved in a variable? \$\endgroup\$nany way. You can save it in a variable, but it must not be hardcoded. \$\endgroup\$