Editor, Active player (297)
Joined: 3/8/2004
Posts: 7469
Location: Arzareth
andymac wrote:
On a semi related note, this is my feeble attempt at making the shortest compiled code:
Nice one, though incomplete. Here's one for Linux.
extern printf,exit
global main
main    sub esp,8192
        lea ebp,[esp+4000]
        mov ebx,0
        mov esi,1
        call o ;hope hard here that cx != 0
b       mov cx,1 ;test primality. Start by dividing with 2.
p       inc cx
        cmp cx,si
        jae c   ;do division tests up to n-1
        call i
        jne p   ;loop until primality confirmed false
r       mov cx,7
        call i  ;also divide by 7
        je c    ;don't output if it was a multiple of 7
        call o
c       inc si
        cmp si,1001
        jb b
        mov[ebp+ebx],byte 0 ; ensure the format string ends with '\0'.
        push ebp
        call printf
        jmp exit   
o       mov[ebp+ebx],dword"%1d "
        add ebx,4 ;swap order of add&mov because we're in a subcall (esp has -4 in it)
        mov[esp+ebx],esi
        ; Note: continues straight into "i".
        ; If the program crashes due to cx being zero
        ; at the program start, insert a "ret" here. 
i       mov dx,0
        mov ax,si
        div cx   
        or dx,dx
        ret
To run: $ nasm -f elf code.S (yasm works too) $ gcc -m32 code.o $ ./a.out EDIT: For those who think that using libc is cheating, here's a version that runs without any linked in libraries (no, nobody complained, I'm just saying). This also produces the e5520566aa3e1456e05d1f17d91ab9d4-hash output, i.e. no trailing space:
;global _start
; _start: ; -- these two lines are optional, but you can enable them for purity
        sub esp,4096
        mov edi,esp
        mov ebx,1
        mov eax,1
        mov[edi],byte"1"
b       mov si,ax
        mov cx,7 ;test modulo 7
        call i
        jz c
        lea cx,[si-1]
        call p ;test primality
        jne c
        mov[edi+ebx],byte" "
        inc bx
        mov cx,10 ;output in base10
        mov ax,si
        call d
c       lea ax,[si+1] ;next number
        cmp ax,1001
        jb b
        mov dx,bx
        mov bx,1
        mov ecx,esp
        mov ax,4 ;NR_write
        int 128 ;syscall
;        mov ax,1 ;NR_exit  -- enable these two lines if you want the program
;        int 128 ;syscall   -- to terminate _without_ a segmentation fault
d       call i
        or ax,ax
        jz e
        push dx
         call d
        pop dx
e       or dl,48
        mov[edi+ebx],dl
        inc bx ; note: continues straight into "i", however, a bare "ret" would suffice
i       mov dx,0
        div cx  ; ax=val/10, dx=val%10
        or dx,dx
r       ret
p       cmp cx,2
        jb r
        mov ax,si
        call i
        je r
        loop p
To run: $ nasm -f elf code.S (yasm works too) $ gcc -m32 -nostdlib code.o (alternatively: ld -m elf_i386 -o a.out code.o) $ ./a.out Ps: If the limit had been only up to 255, not 1000, I would have used my favourite obscure IA32 opcode: AAM, instead of DIV.
Joined: 3/7/2006
Posts: 720
Location: UK
andymac wrote:
Is exactly the same.
Sort of. The second snippet explicitly outputs a newline by using 'print d', whereas the first uses sys.stdout.write, which provides no newline. Python automatically finishes off the line on exit though (you might be able to crash it to prevent it, interesting exercise for you, or possibly redirect streams blah blah blah). So the difference is only when the newline gets printed. Anyway I made a much more compact one. I got 83 in Python.
Voted NO for NO reason
Experienced player (623)
Joined: 11/30/2008
Posts: 650
Location: a little city in the middle of nowhere
I get really confused writing in NASM, I can never keep track of things, it doesn't help that the only control flow is a conditional GOTO.
I got 83 in Python.
WHAT!!!?? Qfox provided one which supposedly gave 85, but it was riddled with syntactical errors. Cutting fatal corners and such. HOW? did you use conditional sets or something?
Is exactly the same.
It seriously is. Starting a new python shell and running both programs gives the exact same output. This is including the header and the >>> afterwards. Basically opening a new python shell and running either program, then Ctrl+a, Ctrl+c, into a text file will produce the exact same file. MD5:72014911BE26119697EDB0D393EA9D60. There is no new line that is created for the print that is not when you use sys.stdout.write. This is what I've seen, maybe it's my version of python or something, but that's what I get. If I got a new line after the program terminated (like you said) I probably would've noticed. Either everybody else is wrong, or my python shell is changed/old version. I don't know. Also crashing python generally gives a little error notification. This would be considered output. Unrelated, My dad was looking up some environmental statistics/whatever, and one of the sources was a guy called Dr De'ath. He was (in this article) predicting the extinction of certain species of coral (how ironic). No joke, just thought it's a funny anecdote.
Measure once. Cut twice.
Joined: 3/7/2006
Posts: 720
Location: UK
My code does quite unsympathetic things with ordinary syntax, but it runs, believe me. I've also made a version that is a one liner, but it is 2 characters longer (I'm assuming 'newline' takes up one byte). It outputs a trailing space (and through Python's silly stream closing code, a newline at program exit)... the one-liner doesn't output a trailing space but it does immediately give a newline. It uses list comprehensions and that's about it really.
Voted NO for NO reason
Player (201)
Joined: 7/6/2004
Posts: 511
Warp wrote:
OmnipotentEntity wrote:
Because of general outcry, feeling bad about rejected otherwise functional code, and having read over the rules at codegolf.com regarding this, I'm removing the requirement to not have trailing whitespace.
I have to say that it feels a bit unfair. I put a rather decent amount of work into getting rid of that trailing whitespace in the minimum amount of code, and now it all goes to waste. Also, I made a post in another forum about this compo, and a couple of people made good submissions (eg. one python submission in 112 bytes), which I intended to forward to you. Now I'll have to go back and tell them that the rules have changed and that they will have to start over. I don't think they'll do it. If the specification was clear and unambiguous (md5-sum of the result and all), why does it have to be changed now? Because people don't want to go through the trouble of getting rid of that trailing whitespace in their code? What's next? Allow also "1" to be skipped because, you know, some mathematicians still think it *is* a prime number. And, you know, it makes the code easier when you don't have to take that value into account as a special case of the generic prime testing algorithm. Arbitrary rule changes in the middle of a compo are irritating.
I concur, it is bad to allow trailing spaces because it changes the challenge. But I do sympathize with languages where it is difficult to avoid not putting a newline at the end. I propose to ignore only newlines at end.
g,o,p,i=1e4,a[10001];main(x){for(;p?g=g/x*p+a[p]*i+2*!o: 53^(printf("%.4d",o+g/i),p=i,o=g%i);a[p--]=g%x)x=p*2-1;}
Banned User
Joined: 3/10/2004
Posts: 7698
Location: Finland
flagitious wrote:
I propose to ignore only newlines at end.
That would be a second rule change. Let's just settle with what we have now.
Player (201)
Joined: 7/6/2004
Posts: 511
not really
g,o,p,i=1e4,a[10001];main(x){for(;p?g=g/x*p+a[p]*i+2*!o: 53^(printf("%.4d",o+g/i),p=i,o=g%i);a[p--]=g%x)x=p*2-1;}
Player (36)
Joined: 9/11/2004
Posts: 2630
Eh, I'm more than willing to change the rules to make them more permissive if I feel I've made a mistake (which I do in this case,) but I'd be against changing the rules to make it less permissive. In other news, with the latest leader board update I should have all of the backlog taken care of. If I missed your entry it was probably just an oversight, please notify me.
Build a man a fire, warm him for a day, Set a man on fire, warm him for the rest of his life.
Active player (333)
Joined: 11/25/2004
Posts: 75
83 in Python is ridiculously small. Good job. Supposedly Python 3.0 will change the print statement so you can do stuff like this:
print(str, end='')
to avoid the ending space or newline. I haven't tested yet, though.
Currently working on: SNES Star Fox, Level 3 (100%, published) SNES Star Fox, Level 2 (33%, after Sector X) SNES Star Fox 2, Expert mode (100%, published)
Joined: 3/7/2006
Posts: 720
Location: UK
Yeah I've read some of the Python 3 stuff. I agree with most of it, especially print() I don't agree with replacing the % operator though...
Voted NO for NO reason
Skilled player (1652)
Joined: 11/15/2004
Posts: 2202
Location: Killjoy
Woot - Matlab whoops all ya'lls asses. MATLAB FOREVER.
Sage advice from a friend of Jim: So put your tinfoil hat back in the closet, open your eyes to the truth, and realize that the government is in fact causing austismal cancer with it's 9/11 fluoride vaccinations of your water supply.
Banned User
Joined: 3/10/2004
Posts: 7698
Location: Finland
DarkKobold wrote:
Woot - Matlab whoops all ya'lls asses. MATLAB FOREVER.
A math software where it's easy to write this type of mathematical filter? What a shock.
Experienced player (623)
Joined: 11/30/2008
Posts: 650
Location: a little city in the middle of nowhere
I'm just waiting for someone to use golfscript. win the "other" category hands down.
Measure once. Cut twice.
Player (68)
Joined: 3/11/2004
Posts: 1058
Location: Reykjaví­k, Ísland
andymac wrote:
I'm just waiting for someone to use golfscript. win the "other" category hands down.
One could also make their own programming language that has one special function - an empty file would do exactly what the solutions says. :) Get a score of 0 bytes. Mwahaha. Anyway, I want someone to code a solution in Befunge. That would be entertaining for sure. (edit: whoa, pauli just did at almost the exact same time I posted this)
Banned User
Joined: 3/10/2004
Posts: 7698
Location: Finland
I once tried befunge because the basic idea was exotic and interesting. However, I got soon tired of its limitations. Because of a limited, very strict stack (where you can't pop or swap values freely), and because of the lack of actual variables, I'm not even sure Befunge is Turing-complete (even assuming the fixed maximum size of the program wouldn't cause that already). IMO the basic idea behind Befunge is exciting, but they ruined it with a too restricting implementation. I once thought about making a "better Befunge" with, for example, variables, maybe arrays (or lists), popping any value in the stack to the top of the stack, floating point numbers and integer literals larger than 9.
Skilled player (1652)
Joined: 11/15/2004
Posts: 2202
Location: Killjoy
No love for LOLCODE? I can has wants to see this submission in LOLCODE. KTHNXBAI.
Sage advice from a friend of Jim: So put your tinfoil hat back in the closet, open your eyes to the truth, and realize that the government is in fact causing austismal cancer with it's 9/11 fluoride vaccinations of your water supply.
Experienced player (623)
Joined: 11/30/2008
Posts: 650
Location: a little city in the middle of nowhere
HAI
CAN HAS STDIO?
I HAS A CHEEZEBURGER
I HAS A LOLCATZ
IM IN YR LOOP
UP CHEEZEBURER!!1
LOL LOLCATZ R 2
IM IN YR LOOP
IZ CHEEZEBURGER LEFTOVER LOLCATZ LIEK 0 AND CHEEZEBURGER LEFTOVER 7 NOT LIEK 0?
YARLY
VISIBLE CHEEZEBURGER
GTFO
KTHX
UP LOLCATZ!!1
IZ CHEEZEBURGER LIEK LOLCATZ? GTFO. KTHX
KTHX
IZ CHEEZEBURGER LIEK 1000? GTFO. KTHX
KTHX
KTXHBYE
BTW, THIZ IZ LIEK NOT TEH SUBMISSIONS. TEH CODE HAZ NOT BIN COMPILED. MAYBE ERR0RZ. NOT SHORT. BAD AT TEH GOLFS. TEH EDITS: I'MMA HAZ BAD CODE. CHAGEZ TEH X'S AND TEH Y'S TO TEH CHEEZEBURGER AND TEH LOLCATZ. SYNTAXIMACAL ERR0RZ NO MORE! KTHXBAI.
Measure once. Cut twice.
Skilled player (1652)
Joined: 11/15/2004
Posts: 2202
Location: Killjoy
That was so awesome.
Sage advice from a friend of Jim: So put your tinfoil hat back in the closet, open your eyes to the truth, and realize that the government is in fact causing austismal cancer with it's 9/11 fluoride vaccinations of your water supply.
HHS
Active player (286)
Joined: 10/8/2006
Posts: 356
I don't think my entry got accepted, so I'll just post it here. It's in NASM and is 152 bytes long. db 191,0,2,"W¸1 «3À¹",0,"A;Èt",8,"P™÷ñJXx",18,"Iâð@=é",3,"rç°$ªZ´",9,"Í!ÃP™±",7,"÷ñJXxç3ÛP‹÷™±",10,"÷ñPŠÂ",12,"0ªX…ÀuðWOŠ",4,"†",5,"ˆ",4,"F;÷rô_° ªXë¾" The compiled DOS program, in hex, is 95 bytes: BF 00 02 57 B8 31 20 AB 33 C0 B9 1E 00 41 3B C8 74 08 50 99 F7 F1 4A 58 78 12 49 E2 F0 40 3D E9 03 72 E7 B0 24 AA 5A B4 09 CD 21 C3 50 99 B1 07 F7 F1 4A 58 78 E7 33 DB 50 8B F7 99 B1 0A F7 F1 50 8A C2 0C 30 AA 58 85 C0 75 F0 57 4F 8A 04 86 05 88 04 46 3B F7 72 F4 5F B0 20 AA 58 EB BE
Active player (333)
Joined: 11/25/2004
Posts: 75
As long as we're being esoteric, here's an entry for Whitespace:
   	
	
 	    
   	  
		 
   
    
			   			
	 		
	   
   	
   	 
		 
   	
    
			   	
				 		
	 		
   	
 
 			   	
	   		    	
			    
				  	
	   

 
 	

  		
   	     
	
      
				
 	
    
    
 
 			   	
	   		     
			   					 	  	
	  	
	 	

 
 

  	



It probably doesn't show well here, so here is a link to the file (260 bytes). Also, here is some pseudocode to explain it.
Currently working on: SNES Star Fox, Level 3 (100%, published) SNES Star Fox, Level 2 (33%, after Sector X) SNES Star Fox 2, Expert mode (100%, published)
Banned User
Joined: 3/10/2004
Posts: 7698
Location: Finland
HHS wrote:
It's in NASM
Ok, I think this confusion has gone long enough. "NASM" is not a programming language. NASM is an assembly language compiler, or in other words, an assembler. People keep talking about it as if it was a programming language. It's not. Saying "it's in NASM" is exactly as ridiculous as saying "it's in Visual Studio" or "it's in gcc". Those are not programming languages. They are compilers for a language. Equating the name of the compiler with the language is ridiculous. NASM is not the only compiler which can compile assembly. The correct way is: "It's in assembly. It compiles at least with NASM." The target platform should also be mentioned because assembly is rather platform-dependent.
Experienced player (623)
Joined: 11/30/2008
Posts: 650
Location: a little city in the middle of nowhere
The correct way is: "It's in assembly. It compiles at least with NASM."
He's right, NASM is just a compiler and the language is assembly. but we all know what you mean when you write "it's in NASM", and it's a lot shorter to write than "it's in assembly and compiles to NASM". BTW does anyone have a LOLCODE compiler/interpreter? I want to check if it works, the I'm going to submit it. For the LOLZ of course. Also for those who want to know, CHEEZEBURGER and LOLCATZ are variables, and have no actual meaning to the program.
Measure once. Cut twice.
Editor, Active player (297)
Joined: 3/8/2004
Posts: 7469
Location: Arzareth
HHS wrote:
I don't think my entry got accepted, so I'll just post it here. It's in NASM and is 152 bytes long. db 191,0,2,"W¸1 «3À¹",0,"A;Èt",8,"P™÷ñJXx",18,"Iâð@=é",3,"rç°$ªZ´",9,"Í!ÃP™±",7,"÷ñJXxç3ÛP‹÷™±",10,"÷ñPŠÂ",12,"0ªX…ÀuðWOŠ",4,"†",5,"ˆ",4,"F;÷rô_° ªXë¾" The compiled DOS program, in hex, is 95 bytes: BF 00 02 57 B8 31 20 AB 33 C0 B9 1E 00 41 3B C8 74 08 50 99 F7 F1 4A 58 78 12 49 E2 F0 40 3D E9 03 72 E7 B0 24 AA 5A B4 09 CD 21 C3 50 99 B1 07 F7 F1 4A 58 78 E7 33 DB 50 8B F7 99 B1 0A F7 F1 50 8A C2 0C 30 AA 58 85 C0 75 F0 57 4F 8A 04 86 05 88 04 46 3B F7 72 F4 5F B0 20 AA 58 EB BE
Feh, readibility would be nice. Also, what is the character encoding you are supposing? The exact byte values of your characters matter to a great deal I suppose and converting the characters into bytes, depends on the character encoding used. I can make an educated guess, but it would be better if it came from the horse's mouth.
Joined: 4/25/2004
Posts: 615
Location: The Netherlands
Damnit. I lose my internet for one weekend and Bisqwit whips out 15ish characters of my submission. wtf... :p
qfox.nl
Editor, Active player (297)
Joined: 3/8/2004
Posts: 7469
Location: Arzareth
qFox wrote:
Damnit. I lose my internet for one weekend and Bisqwit whips out 15ish characters of my submission. wtf... :p
It's not like you can't improve your submission without Internet connection… Well, unless you need to look for other algorithms or manual page lookups.