Player (36)
Joined: 9/11/2004
Posts: 2623
andymac wrote:
it still works and it's shorter, so why not? EDIT: i'm an idiot:
EDIT: Clarification, output is expected to STDOUT, not to a file.
I sent you a PM about it. If you're still curious just ask.
Build a man a fire, warm him for a day, Set a man on fire, warm him for the rest of his life.
Experienced player (618)
Joined: 11/30/2008
Posts: 650
Location: a little city in the middle of nowhere
Just didn't see your pm. Alright, well, I'll just enter the 'other' section. Isn't python supposed to be the easiest programing language to write? it's caused me so much grief, I must be really bad at programming: faildogs.com
Measure once. Cut twice.
Joined: 4/25/2004
Posts: 615
Location: The Netherlands
Bisqwit wrote:
qFox wrote:
The best PHP I can come up with in an hour or so is <strike>92</strike> 91 bytes, <strike>89</strike> 88 if you allow <? ?> :p
I got 134, under the condition that it must run warning-free even with E_ALL error reporting level and short tags disabled. For the record, I also did Ruby in 79 and Python in 93... (Though the Ruby one has trailing space and the Python one has extra delimiters.)
Mine is pretty warning free, I think. Short tags are (obviously) required for the shorter version :p I still believe something can be gained in combining the check for both given conditions, but I can't come up with one. But since it's pretty short and I already KISSed, I doubt PHP will reach beyond the ... 70'ish boundary. Part of that is because PHP vars take up at least two variables (not counting defines, but they take longer to set up and, obviously, can't be redefined, so are pointless as a replacement for vars ;p).
qfox.nl
Joined: 4/25/2004
Posts: 615
Location: The Netherlands
andymac: yeah and um, you can drop your code to 85 characters, easy. That's just me, without knowing _any_ python at all.
qfox.nl
Experienced player (618)
Joined: 11/30/2008
Posts: 650
Location: a little city in the middle of nowhere
EDIT: I saw your post before you deleted it, also it takes about 20 mins to learn python. Qfox, you've got some valid points. Executing the keyword print generates a new line every time, so it doesn't fit with requirements if you use print more than once. Also, (OmnipotentEntity got me with this one), you can't use print, you must use sys.stdout.write, because if you use print, a new line is generated after the program executes which is considered trailing whitespace. Your first one actually runs, but all the numbers are in a giant column, they are the right numbers though. The second one gets a div0 error, but correcting you:
print 1
for x in range(1001):
  for y in range(2,x):
    if x%7!=0 and x%y==0:
      print str(x)+' '
you still get a giant column of numbers, and many of the numbers repeat themselves, but to give you credit, they are the right numbers, and you do know nothing about python. the last one give syntatical errors, you need that new line, you can't just have one giant line of code. Believe me,it seems sensible to try any of the alternatives that you provided, but I am about as knowledgeable at python as you are (I learned all the python i know yesterday) . I have tried most of these things, and they need extra code to make them work, if you were to ask me my opinion, I would say ytterbiums solution is the absolute fastest one there is. A 'sets' approach may be more efficient. on a semi unrelated note, I was going for the "other" category and decided to use NASM because it looked interesting. (it compiles into machine code). Anyways I started off with a nice easy print the first 1000 numbers on screen. It compiled to only 30 bytes and when run produces a window that will not close, makes an indefinitely occuring beeping noise, and displays random characters in the command prompt. Now where the hell did I go wrong to produce such an abomination.
ƻ뤀ϨḁĀᚋĀ঴⇍ูĀ䲴⇍
that's the code. name it anything.com. use at your own risk
Measure once. Cut twice.
Player (67)
Joined: 3/11/2004
Posts: 1058
Location: Reykjaví­k, Ísland
I submitted my solution in java. It will be the biggest one yet. Therefore, I win! ;)
Joined: 4/25/2004
Posts: 615
Location: The Netherlands
andymac> maybe this will help... (was gonna post this anyways ;p) [12:39:36] <Didgeridoodle> I need to contact one of those code golf pythoners from the forum [12:40:25] <Didgeridoodle> tell them a secret :> [12:40:47] <Shinryuu> secret... what kind of secret? [12:41:34] <Didgeridoodle> if they do this: [12:41:43] <Didgeridoodle> print("hello world"), [12:41:49] <Didgeridoodle> with that comma afterwards, yes [12:41:59] <Didgeridoodle> then print will not print a newline
qfox.nl
Player (36)
Joined: 9/11/2004
Posts: 2623
qFox wrote:
andymac> maybe this will help... (was gonna post this anyways ;p) [12:39:36] <Didgeridoodle> I need to contact one of those code golf pythoners from the forum [12:40:25] <Didgeridoodle> tell them a secret :> [12:40:47] <Shinryuu> secret... what kind of secret? [12:41:34] <Didgeridoodle> if they do this: [12:41:43] <Didgeridoodle> print("hello world"), [12:41:49] <Didgeridoodle> with that comma afterwards, yes [12:41:59] <Didgeridoodle> then print will not print a newline
Actually, I know this behavior. To be honest, I was surprised when I found out if that is the last print statement in the program and no other function prints characters to the screen, then python will put in a line feed anyway when the program exits. JOY example:
print"hi",
print" hi"
print"hi",
print" hi",
outputs:
hi  hi
hi  hi

that's:
hi<space><space>hi<newline>
hi<space><space>hi<newline>

note the extra spaces that python just throws in there. and the trailing new line that it insists upon. :)
Build a man a fire, warm him for a day, Set a man on fire, warm him for the rest of his life.
Mitjitsu
He/Him
Banned User, Experienced player (532)
Joined: 4/24/2006
Posts: 2997
I might try this some time next week. Doing the challenge isn't hard, it's coming up with the most efficient possible code. Would it be defined by the least lines or characters?
Player (67)
Joined: 3/11/2004
Posts: 1058
Location: Reykjaví­k, Ísland
Mitjitsu wrote:
I might try this some time next week. Doing the challenge isn't hard, it's coming up with the most efficient possible code. Would it be defined by the least lines or characters?
The least characters minus (unnecessary) whitespace, obviously. If it was the least number of lines, you would just make your solution normally, then put everything on one line. And to me, making the program at all was enough of a headache, let alone making it small, thank you very much. :)
Banned User, Former player
Joined: 12/23/2004
Posts: 1850
The problem with including whitespace is that it introduces problems like "\r\n" v. "\n" and spacing.
Perma-banned
Banned User, Former player
Joined: 3/10/2004
Posts: 7698
Location: Finland
Blublu wrote:
The least characters minus whitespace, obviously.
IMO if whitespaces are required by the programming language, they should be included in the count. IOW, if you had something like (imaginary example in an imaginary language) "let a=5" then that would be 7 characters, not 6. If whitespaces were not counted, it would be a bit controversial. For example, if you have a whitespace inside a string, should it be counted or not? Better count them all. More unambiguous.
Player (51)
Joined: 10/6/2005
Posts: 138
Location: Oregon
Deleted by request. Not gorgeous, but I'm not very good at these kinds of things. That's 103 characters (in PHP). 100 if you use short tags.
Player (200)
Joined: 7/6/2004
Posts: 511
Hey, a tip for pythoners, it seems you can't use print, but you can output to stdout shortly using input()
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: 2623
Mitjitsu wrote:
I might try this some time next week. Doing the challenge isn't hard, it's coming up with the most efficient possible code. Would it be defined by the least lines or characters?
I count characters, whitespace does count as a character, if you are on a \r\n OS and your submission is more than one line long you might want to strip out that \r. It would be very unfair of me to strip whitespace out of the count because if someone wants to make a submission using whitespace then it's an autowin. :)
Build a man a fire, warm him for a day, Set a man on fire, warm him for the rest of his life.
Player (67)
Joined: 3/11/2004
Posts: 1058
Location: Reykjaví­k, Ísland
Warp wrote:
Blublu wrote:
The least characters minus whitespace, obviously.
IMO if whitespaces are required by the programming language, they should be included in the count. IOW, if you had something like (imaginary example in an imaginary language) "let a=5" then that would be 7 characters, not 6. If whitespaces were not counted, it would be a bit controversial. For example, if you have a whitespace inside a string, should it be counted or not? Better count them all. More unambiguous.
By whitespace, I meant all "spaces, tabs, etc you use to make the code more readable, but not required for the program to work correctly". I thought that was the definition of whitespace. That's why probably all submitters should submit the smallest program possible.
Joined: 8/27/2006
Posts: 883
Banned User, Former player
Joined: 3/10/2004
Posts: 7698
Location: Finland
Blublu wrote:
By whitespace, I meant all "stuff not required for the program to work correctly, including comments, etc".
Then the submitter should, rather obviously, remove any non-essential characters from his program before submitting. I don't think it should be up to OmnipotentEntity to try to guess what is mandatory and what isn't.
I thought that was the definition of whitespace.
Comments are "whitespace"? Never heard of that. "Whitespace" consists of, at least, the space, tab, newline and linefeed characters.
Player (67)
Joined: 3/11/2004
Posts: 1058
Location: Reykjaví­k, Ísland
Yes, I did not mean to imply that comments are whitespace. I have updated my post to reflect better what I was thinking at the time. Just condense your program into the smallest possible space before submitting. Problem solved. The end.
Player (36)
Joined: 9/11/2004
Posts: 2623
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'm working to restore the leaderboard from entries already received. I will strip trailing whitespace from any output before comparing it to the expected output from here on out. No need to resubmit at this time.
Build a man a fire, warm him for a day, Set a man on fire, warm him for the rest of his life.
Banned User, Former player
Joined: 3/10/2004
Posts: 7698
Location: Finland
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.
Player (67)
Joined: 3/11/2004
Posts: 1058
Location: Reykjaví­k, Ísland
If "1" can be skipped and trailing space is allowed, I can improve my solution to 147. (and everyone else could, too) I too feel that the rules were perfectly fine and no need to change them after people have headached over their code. (yes, I did use that word as a verb). I guess it doesn't matter what you do, you will always irritate someone.
Player (36)
Joined: 9/11/2004
Posts: 2623
The reason for the rule change is mostly because someone pointed out to me that the actual codegolf.com's rules function in that fashion (which is what I was initially aiming for anyway.)
http://codegolf.com/help wrote:
What are the rules for entering? You can upload any code that you believe will fulfill the requirements of the challenge. There are no requirements on how you format your code in terms of line length or number of lines. You can enter all challenges, and you can enter them using all of the available languages if you want to. There are a couple of restrictions that may affect you : * You can only submit an entry every 2 minutes. * You can only upload files which are equal to or smaller than 51,200 bytes in size. * You will be unable to import/require/include any modules or files in your solution. You have to write all the code yourself, and it has to be in the code file you upload. There are a couple of things about your code's execution that might be useful to know : * Execution of your code will stop after 4 seconds of wall time. Any code which is stopped in this manner will be deemed to have failed. * Trailing whitespace from your output and the reference output you are trying to match will be stripped when they are being compared.
If you are unsure about whether or not your output will match with the expected output I wrote a short perl script to pipe your output through before passing it through md5sum:
#!/usr/bin/perl
undef $/;
$_ = <>;
s/\s*$//;
print;
EDIT: silly bugs in short perl scripts. rewriting.
Build a man a fire, warm him for a day, Set a man on fire, warm him for the rest of his life.
Player (67)
Joined: 3/11/2004
Posts: 1058
Location: Reykjaví­k, Ísland
If you're too lazy to do that (or don't know how), you can also just pipe it directly into md5sum with the trailing space, and check whether it is: d781302d9d20f2a6a26166f5960694df which is what I got after I added the trailing space to my program.
Experienced player (618)
Joined: 11/30/2008
Posts: 650
Location: a little city in the middle of nowhere
I got Ytterbijum's code to see what you meant by the new line at the end, and there's a reason that I didn't notice it, because it doesn't exist! The output from this code:
import sys
w=sys.stdout.write
w('1')
for i in range(1001):
 if i%7!=0 and any([i%n==0 for n in range(2,i)]):w(' %d'%i)
and this code:
d='1'
for i in range(1001):
 if i%7!=0 and any([i%n==0 for n in range(2,i)]):d=d+' '+str(i)
print d
Is exactly the same. the MD5 is 72014911BE26119697EDB0D393EA9D60. On screen, both output this:
Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.

    ****************************************************************
    Personal firewall software may warn about the connection IDLE
    makes to its subprocess using this computer's internal loopback
    interface.  This connection is not visible on any external
    interface and no data is sent to or received from the Internet.
    ****************************************************************
    
IDLE 1.2.2      
>>> ================================ RESTART ================================
>>> 
1 4 6 8 9 10 12 ....... 995 996 998 999 1000
>>> 
The only way to rid yourself of the line at the end is to make sure that the program doesn't finish. On a semi related note, this is my feeble attempt at making the shortest compiled code:
segment.data
	x	dw	1	;reserves 16 bits mem for x
	g	db	"1 $" 	;g = '1 $'
	y	dw	2	;y = 2 (16 bits)
segment.text
	org	100h		;starts program
	mov	cx, [y]		;CX = y
	mov	bx, [x]		;BX = x
	mov	dx, g		;DX = g
	mov	ah, 9		;ah needs to be 9 for stdout
	int	21h		;dos service interupt(stdout)
whilex				;while x<1000: (label only)
	inc	bx		;x+=1
	mov	cx, 2		;y=2
whiley				;while y<x: (label)
		
	inc	cx		;y+=1

	cmp	bx, cx		;while y<x: compare x, y
	jnc	whiley		;goto whiley if cf=0

	cmp	bx, 1000	;while x<1000> 1000
	mov	ah,4CH		;ends program
	int	21h
It's not finished. This program outputs "1 ". Each line represents one opcode except for pseudo codes.
Measure once. Cut twice.