You are not logged in.
http://codegolf.com/ <-- info.
The rules are simple;
· As few chars as possible
· No need to use strict, warnings etc
· Just like codegolf - use perl, python or ruby to solve the problem
· The winner gets to choose the next problem
Starting simple:
Write a program that prints "I love archlinux" 5 times with line numbering. Desired output:
1 I love archlinux
2 I love archlinux
3 I love archlinux
4 I love archlinux
5 I love archlinux
Offline
Great idea!
My Perl entry:
for($n=1;$n<6;$n++){print"$n I love archlinux\n"}
Last edited by Ashren (2010-02-13 11:35:23)
Offline
Boring python version
for i in range(1,6):print i,"I love archlinux"
/edit
I have no perl fu whatsoever but ...
while(++$i<6){print"$i I love archlinux\n"}
can also do that with a for, but thats unfortunately not shorter
if php is allowed to:
while(++$i<6)echo"$i I love archlinux\n";
and a ruby entry :-)
p *(1..5).map{|x|"#{x} I love Archlinux"}
Last edited by raf_kig (2010-02-13 12:33:55)
Offline
if we play like CodeGolf, than we can use PHP to ? coz i aint know perl, python or ruby
<html>
<body>
<?php
for($i=1; $i<=5; $i++)
echo $i . " I love archlinux<br>";
?>
</body>
</html>
if we cant in php, delete my post.
Offline
while($i++<5){print"$i I love archlinux\n"}
When and how do you guys think we should declare the winner?
Offline
Bad x86 asm allowed?
section .data
love db ' I love archlinux',10
len equ $-love
section .text
global _start
_start:
sub esp, 1
mov BYTE [esp], 31h
.for
mov BYTE ah, [esp]
cmp ah, 35h
jg .exit
mov eax, 4
mov ebx, 1
mov ecx, esp
mov edx, 1
int 80h
mov eax, 4
mov ebx, 1
mov ecx, love
mov edx, len
int 80h
mov ah, [esp]
inc ah
mov [esp], ah
jmp .for
.exit:
mov eax, 1
mov ebx, 0
int 80h
Offline
I know zsh isn't allowed, but this beats you all:
for i ({1..5}) echo $i I love archlinux
edit: fixed number
Last edited by JohannesSM64 (2010-02-13 18:01:11)
Offline
5> [io:format("~w ~w~n", [X,Y]) || X <- [1,2,3,4,5], Y <- ['i love archlinux']].
1 'i love archlinux'
2 'i love archlinux'
3 'i love archlinux'
4 'i love archlinux'
5 'i love archlinux'
[ok,ok,ok,ok,ok]
6>
Bit of erlang.
longer but more correct:
10> lists:foreach(fun(X) -> io:format("~w I love arch linux~n",[X]) end, lists:seq(1,5)).
1 I love arch linux
2 I love arch linux
3 I love arch linux
4 I love arch linux
5 I love arch linux
ok
Last edited by Tillotson (2010-02-13 12:59:48)
Offline
Perl:
map{print"$_ I love archlinux\n"}(1..5)
also
print"$_ I love archlinux\n"foreach(1..5)
Btw, there's a space in "Arch Linux", but I wasn't going to make my submission longer just for that.
*edit*
shaved a space off the second one
*edit2*
even better:
print"$_ I love archlinux\n"for(1..5)
Last edited by Xyne (2010-02-13 13:00:17)
My Arch Linux Stuff • Forum Etiquette • Community Ethos - Arch is not for everyone
Offline
i knew xyne would show up and show us some real perl fu :-)
Offline
I didn't see a rule about using arguments so I am going to assume that does are perfectly fine to use. ;-)
To call the program just type: make 1 2 3 4 5
Makefile:
%:
@echo $@" I love archlinux"
It is supposed to be a tab character before @echo but it is a bit hard to see on the forum.
<edit>
This is how it looks if I don't use arguments:
Makefile:
%:
@echo $@" I love Archlinux"
all:1 2 3 4 5
</edit>
Last edited by PJ (2010-02-13 13:44:25)
Offline
Always the functional solution like @xyne will win.
Last edited by n0dix (2010-02-13 13:52:57)
Offline
A version in C:
main(){int x=0;for(;x++<5;)printf("%d i love archlinux\n",x);}
There are a couple of warnings but other than that it seems to work. I don't think it is possible to make a smaller C version.
Offline
Short Python3 version:
[print(i+1,"I love Arch Linux") for i in range(5)]
Unfortunately it doesn't work with python2 because you can't write non-expression statements in a list comprehension.
Edit: Oops, darn. Thought the list comprehension would save me keystrokes but turns out the obvious way was shorter. Which I guess is a compliment to Python.
Last edited by Trent (2010-02-13 15:31:31)
Offline
yes I love Arch Linux | head -n 5 | cat -n
Offline
gogogo procyon! bash beats 'em all
never trust a toad...
::Grateful ArchDonor::
::Grateful Wikipedia Donor::
Offline
Ha! I have bested Xyne!
warn"$_ I love Arch Linux$/"for(1..5)
(Ok... with the space, it's the same length.)
Last edited by Trent (2010-02-13 15:45:00)
Offline
Well, I was wrong, it is clearly possible to write it smaller. I managed to remove 2 characters.
main(int i){if(i<6)printf("%d i love archlinux\n",i);main(i+1);}
<edit>
Seems like I miscalculated the characters, it is actually 2 charaters larger.
</edit>
<edit2>
I took ideas from both C-programs and I actually did managed to shrink it with 3 characters compared to the first one. (I haven't miscalculated this time)
Anyway, it looks something like this:
main(int i){for(;i<6;)printf("%d i love archlinux\n",i++);}
</edit2>
Last edited by PJ (2010-02-13 16:19:14)
Offline
At the website it says keystrokes, so characters like $ and the like should be interpreted as two strokes?
Offline
cat -
7 keystrokes. 5 for the code, 2 for typing ^d (EOF). Also 2 mouseclicks for copypasting the text from this page :lol:
my other ideas were putting the text in a file and doing `cat file`, or writing a simple shellscript that does something multiple times (like Proxycon's `yes | head` trick but better), but then the code for that script should also be counted. Anyway I think the above approach meets all requirements
< Daenyth> and he works prolifically
4 8 15 16 23 42
Offline
gogogo procyon! bash beats 'em all
Nope, my zsh version is still shorter
Offline
Can we please read the rules.
Offline
No one using bash's printf?
printf "%d I love archlinux\n" {1..5}
Offline
Can we please read the rules.
i think noone read's that :S
Offline
@JohannesSM64: Mine can be written shorter too:
yes I love archlinux|head -n5|cat -n
36 characters
And one for dc:
[ I love archlinux]1np2np3np4np5np
34 characters
Offline