You are not logged in.

#1 2010-02-13 09:42:51

dmz
Member
From: Sweden
Registered: 2008-08-27
Posts: 881
Website

The Golf Tournament!

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

#2 2010-02-13 11:23:56

Ashren
Member
From: Denmark
Registered: 2007-06-13
Posts: 1,229
Website

Re: The Golf Tournament!

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

#3 2010-02-13 11:29:29

raf_kig
Member
Registered: 2008-11-28
Posts: 143

Re: The Golf Tournament!

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

#4 2010-02-13 11:58:09

hBd
Member
From: Romania - Cluj Napoca
Registered: 2008-06-08
Posts: 241
Website

Re: The Golf Tournament!

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

Offline

#5 2010-02-13 12:16:39

dmz
Member
From: Sweden
Registered: 2008-08-27
Posts: 881
Website

Re: The Golf Tournament!

while($i++<5){print"$i I love archlinux\n"}

When and how do you guys think we should declare the winner?

Offline

#6 2010-02-13 12:18:17

Themaister
Member
From: Trondheim, Norway
Registered: 2008-07-21
Posts: 652
Website

Re: The Golf Tournament!

Bad x86 asm allowed? big_smile

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

#7 2010-02-13 12:21:02

JohannesSM64
Member
From: Norway
Registered: 2009-10-11
Posts: 623
Website

Re: The Golf Tournament!

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

#8 2010-02-13 12:27:39

Tillotson
Member
Registered: 2009-05-09
Posts: 23

Re: The Golf Tournament!

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

#9 2010-02-13 12:42:32

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: The Golf Tournament!

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

*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 StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#10 2010-02-13 12:45:25

raf_kig
Member
Registered: 2008-11-28
Posts: 143

Re: The Golf Tournament!

i knew xyne would show up and show us some real perl fu :-)

Offline

#11 2010-02-13 13:32:54

PJ
Member
From: Sweden
Registered: 2005-10-11
Posts: 602

Re: The Golf Tournament!

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

#12 2010-02-13 13:51:43

n0dix
Member
Registered: 2009-09-22
Posts: 956

Re: The Golf Tournament!

Always the functional solution like @xyne will win.

Last edited by n0dix (2010-02-13 13:52:57)

Offline

#13 2010-02-13 15:10:21

PJ
Member
From: Sweden
Registered: 2005-10-11
Posts: 602

Re: The Golf Tournament!

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

#14 2010-02-13 15:24:30

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 990

Re: The Golf Tournament!

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

#15 2010-02-13 15:32:54

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: The Golf Tournament!

yes I love Arch Linux | head -n 5 | cat -n

Offline

#16 2010-02-13 15:36:04

toad
Member
From: if only I knew
Registered: 2008-12-22
Posts: 1,775
Website

Re: The Golf Tournament!

gogogo procyon! bash beats 'em all smile


never trust a toad...
::Grateful ArchDonor::
::Grateful Wikipedia Donor::

Offline

#17 2010-02-13 15:44:27

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 990

Re: The Golf Tournament!

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

#18 2010-02-13 15:55:17

PJ
Member
From: Sweden
Registered: 2005-10-11
Posts: 602

Re: The Golf Tournament!

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

#19 2010-02-13 15:57:59

hatten
Arch Linux f@h Team Member
From: Sweden, Borlange
Registered: 2009-02-23
Posts: 736

Re: The Golf Tournament!

At the website it says keystrokes, so characters like $ and the like should be interpreted as two strokes?

Offline

#20 2010-02-13 16:15:14

Dieter@be
Forum Fellow
From: Belgium
Registered: 2006-11-05
Posts: 2,001
Website

Re: The Golf Tournament!

cat -

7 keystrokes. 5 for the code, 2 for typing ^d (EOF).  Also 2 mouseclicks for copypasting the text from this page lol: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 cool


< Daenyth> and he works prolifically
4 8 15 16 23 42

Offline

#21 2010-02-13 16:30:54

JohannesSM64
Member
From: Norway
Registered: 2009-10-11
Posts: 623
Website

Re: The Golf Tournament!

toad wrote:

gogogo procyon! bash beats 'em all smile

Nope, my zsh version is still shorter tongue

Offline

#22 2010-02-13 16:41:35

dmz
Member
From: Sweden
Registered: 2008-08-27
Posts: 881
Website

Re: The Golf Tournament!

sad
Can we please read the rules.

Offline

#23 2010-02-13 16:41:38

some-guy94
Member
Registered: 2009-08-15
Posts: 360

Re: The Golf Tournament!

No one using bash's printf?

printf "%d I love archlinux\n" {1..5}

Offline

#24 2010-02-13 17:34:52

hBd
Member
From: Romania - Cluj Napoca
Registered: 2008-06-08
Posts: 241
Website

Re: The Golf Tournament!

dmz wrote:

sad
Can we please read the rules.

i think noone read's that :S

Offline

#25 2010-02-13 17:35:32

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: The Golf Tournament!

@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

Board footer

Powered by FluxBB