code logs -> 2007 -> Fri, 14 Dec 2007< code.20071213.log - code.20071215.log >
--- Log opened Fri Dec 14 00:00:48 2007
01:10 gnolam [lenin@85.8.5.ns-20483] has quit [Quit: Z?]
01:22 Chalcedon is now known as ChalcyAFK
01:58 Vornicus is now known as Darius
03:34 Forj [~Forj@116.93.128.ns-23287] has joined #code
03:34 mode/#code [+o Forj] by ChanServ
04:18 Chalcy [~Chalcedon@116.93.128.ns-23287] has joined #code
04:18 mode/#code [+o Chalcy] by ChanServ
04:18 ChalcyAFK [~Chalcedon@Nightstar-11713.ue.woosh.co.nz] has quit [Ping Timeout]
04:54 Forj [~Forj@116.93.128.ns-23287] has quit [Ping Timeout]
04:54 Chalcy [~Chalcedon@116.93.128.ns-23287] has quit [Ping Timeout]
06:00 EvilDarkLord [~jjlehto3@Nightstar-2194.vipunen.hut.fi] has quit [Ping Timeout]
06:00 EvilDarkLord [~jjlehto3@130.233.228.ns-13022] has joined #code
06:01 EvilDarkLord is now known as NSGuest-3401
06:32 Forj [~Forj@203.211.122.ns-2621] has joined #code
06:32 mode/#code [+o Forj] by ChanServ
06:59 NSGuest-3401 [~jjlehto3@130.233.228.ns-13022] has quit [Ping Timeout]
07:00 EvilDarkLord [~jjlehto3@Nightstar-2194.vipunen.hut.fi] has joined #code
07:01 EvilDarkLord is now known as NSGuest-3405
07:19 Chalcedon [~Chalcedon@Nightstar-1707.ue.woosh.co.nz] has joined #code
07:19 mode/#code [+o Chalcedon] by ChanServ
08:20 Darius is now known as Vornicus
09:16 Vornicus is now known as Vornicus-Latens
09:26 Chalcedon [~Chalcedon@Nightstar-1707.ue.woosh.co.nz] has quit [Quit: slep]
09:35 AnnoDomini [AnnoDomini@83.21.56.ns-26805] has quit [Ping Timeout]
09:38 You're now known as TheWatcher
09:41 AnnoDomini [AnnoDomini@Nightstar-29046.neoplus.adsl.tpnet.pl] has joined #Code
09:41 mode/#code [+o AnnoDomini] by ChanServ
09:42 Thaqui [~Thaqui@Nightstar-262.dialup.xtra.co.nz] has joined #code
09:42 mode/#code [+o Thaqui] by ChanServ
10:14 Forj [~Forj@203.211.122.ns-2621] has quit [Quit: Gone]
10:44 Thaqui [~Thaqui@Nightstar-262.dialup.xtra.co.nz] has left #code [Leaving]
10:54 * AnnoDomini hates it how WinXP sorts files the other way than Win98SE.
10:54
<@AnnoDomini>
Any way to make it put the newest at the TOP, retaining that the folders are on top too?
10:55
<@AnnoDomini>
'Cause it seems I have an option between newest on the bottom, folders at the top, or newest at the top, folders at the bottom.
10:55
<@AnnoDomini>
Neither is satisfactory.
11:14
< Kyrre>
Only in detailed view.
13:01
<@AnnoDomini>
No... that doesn't work.
13:09
< Kyrre>
Hmm.
13:09
< Kyrre>
No clue
14:35 Xiphias [Ameroth@82.68.15.ns-4527] has joined #code
14:43 gnolam [lenin@Nightstar-10613.8.5.253.static.se.wasadata.net] has joined #Code
14:43 mode/#code [+o gnolam] by ChanServ
14:56 Vornicus-Latens [~vorn@Admin.Nightstar.Net] has quit [Ping Timeout]
15:28 opqlogic [~opqlogic@202.152.240.ns-3494] has joined #Code
16:08 opqlogic [~opqlogic@202.152.240.ns-3494] has quit [Quit: ]
16:34 Xiphias [Ameroth@82.68.15.ns-4527] has quit [Quit: I was never gone]
17:05 You're now known as TheWatcher[afk]
17:47 Attilla [~The.Attil@194.72.70.ns-11849] has quit [Quit: <Insert Humorous and/or serious exit message here>]
18:18 gnolam [lenin@Nightstar-10613.8.5.253.static.se.wasadata.net] has quit [Quit: Fan Death.]
18:20 gnolam [lenin@Nightstar-10613.8.5.253.static.se.wasadata.net] has joined #Code
18:20 mode/#code [+o gnolam] by ChanServ
18:48 You're now known as TheWatcher
18:52 Chalcedon [~Chalcedon@203.211.122.ns-2621] has joined #code
18:52 mode/#code [+o Chalcedon] by ChanServ
20:08 Attilla [~The.Attil@194.72.70.ns-11849] has joined #code
20:13 Vornotron [~vorn@Admin.Nightstar.Net] has joined #code
20:22 Vornotron is now known as Vornicus
20:26
< C_tiger>
I have somehow broken IDLE
20:26
< Vornicus>
Heh. How so?
20:26
<@AnnoDomini>
Elucidate.
20:26
< C_tiger>
I tried running this piece of code... I'm assuming I screwed something up, it crashed.
20:27
< C_tiger>
Now when I restart, I get a "socket error
20:27
< C_tiger>
and I can't restart IDLE.
20:31
< Vornicus>
...oh, awesome.
20:31
< Vornicus>
That means there's a Python process still running.
20:31
< C_tiger>
Oh.
20:32
< Vornicus>
(and therefore is still sitting on a socket)
20:33
< C_tiger>
This is what happens when you try coding at 5 AM.
20:35
< C_tiger>
Now I get "IDLE can't start a subprocess"
20:35
< C_tiger>
and something about a connection firewall.
20:35
< C_tiger>
Let me just restart this stupid computer.
20:36 C_tiger [~c_wyz@Nightstar-5378.nycmny.east.verizon.net] has quit [Quit: And away she goes!]
21:00
<@gnolam>
That's one wicked boot time.
21:03 ilovefire [~santros_v@209.82.191.ns-11321] has joined #code
21:04
< Vornicus>
How do you use for without using xrange?
21:06
< ilovefire>
well, ummm... *checks his notes, all his made programs, and umm, it's not there. This is my fault. I probably forgot to note it.
21:07 * Vornicus hunts his own logs.
21:09
< Vornicus>
Also, take a guess.
21:10 C_tiger [~c_wyz@Nightstar-5378.nycmny.east.verizon.net] has joined #code
21:10
< ilovefire>
Well, umm, I guess it will start a loop based on a variable in... something?
21:11
< Vornicus>
Nothing so complicated.
21:11
< Vornicus>
You have a list. You need to take each item in that list in turn and process it.
21:11
< ilovefire>
Okay...
21:11
< Vornicus>
call said list, I don't know, my_list.
21:12
< ilovefire>
Allright.
21:12
< Vornicus>
try this:
21:12
< C_tiger>
Oh, microsoft corporation's windows XP, how do I love thee... let me count the ways. When you hang three times at startup before working inexplicably, my heart explodes in my chest in pure bliss.
21:12
< Vornicus>
my_list = [15,23,97000,2]
21:12
< Vornicus>
for k in my_list: print k
21:13
< ilovefire>
Ah, I see now. sort of.
21:13
< Vornicus>
(with appropriate indenting.)
21:13
< Vornicus>
now, how do you tell is_prime() to check against each item in known_primes?
21:13
< ilovefire>
for k in known_prime?
21:14
< Vornicus>
Hey, look
21:19
< Vornicus>
Now, rewrite is_prime to check against the values in known_primes instead of the values gotten from that xrange thing.
21:23 * ilovefire does so, tests it, and it seems to work!
21:24
< Vornicus>
Okay, paste that code.
21:24
< C_tiger>
and you didn't have to stay up to 5 AM to figure out why... (oh my head...)
21:24
< Vornicus>
poor C.
21:24
< ilovefire>
Right, op or voice please
21:25 mode/#code [+o ilovefire] by AnnoDomini
21:25 mode/#code [+oooooo Attilla C_tiger Kyrre NSGuest-3405 Pi-2 TheWatcher] by Vornicus
21:25 mode/#code [+o Vornicus] by Vornicus
21:27
<@ilovefire>
http://rafb.net/p/CDq3Xn72.html also, I forgot to erase import_math, so just ignore that.
21:27
<@Vornicus>
Actually we'll still need it.
21:27
<@Vornicus>
See, there's a problem here.
21:28
<@Vornicus>
We've made it so we check primes, but... in checking, say, 100, instead of checking only the 9 numbers from 2 to 10, we're checking the 25 primes from 2 to 10.
21:28
<@Vornicus>
25 primes from 2 to 100.
21:28
<@Vornicus>
But what we /really/ need to be checking is the 4 primes from 2 to 10.
21:29
<@C_tiger>
Idly, question: does it hurt that much to import an extra module?
21:29
<@Vornicus>
Generally no.
21:29
<@Vornicus>
I mean, okay, it /does/, but only at startup.
21:30
<@Vornicus>
And for large portions of the standard library - math included - it's like flipping a switch.
21:30
<@Vornicus>
Anyway.
21:31
<@McMartin>
Most user modules will be similar; there's only a major cost if there are expensive module setup operations, and there basically never are.
21:31
<@C_tiger>
That's what I thought.
21:31
<@ilovefire>
... And the easiest way to do that is to jsut figure those out myself, type it in in the known_primes list, and remove the code that adds numbers to the list, yes?
21:31
<@Vornicus>
ilf: nope.
21:31
<@C_tiger>
... no.
21:31
<@Vornicus>
We can do it much more nicely.
21:32
<@ilovefire>
Do tell.
21:32
<@Vornicus>
To prove this: put in a print statement in primes() where you print known_primes, right at the end; then run primes(100)
21:32
<@C_tiger>
Ilf: whenever you're tempted to think "hey I could just do X myself", also consider: the code has to work with n = 1000000. Do you really want to be typing in that many primes?
21:33
<@ilovefire>
... but, but vorn said we only need to check the primes from 2 to 10... or is that only for 100?
21:33
<@C_tiger>
That's only for 100
21:33
<@Vornicus>
That's only for 100.
21:34
<@Vornicus>
For 1000000 we need to check the primes from 2 to 1000.
21:34
<@C_tiger>
And for 100000000000000000000.... you get the picture...
21:34 * ilovefire nods.
21:34
<@C_tiger>
Ok, quick backtrack, why, for 100, do we only need to check the primes from 2 to 10?
21:35
<@ilovefire>
Because we only need to check numbers up to the square root of the number--after that they start to repeat, basically.
21:36
<@Vornicus>
Yep.
21:36
<@Vornicus>
Okay, so, what we need to do is just /not check/ primes that are higher than the square root of the number we're testing.
21:37
<@Vornicus>
now, the obvious way to do this is just to say if p > sqrt(n): pass
21:37
<@Vornicus>
(pass is another keyword; we use it to say "this block is empty")
21:37
<@Vornicus>
(I think in my entire career I've used it once)
21:38
<@McMartin>
()
21:38
<@McMartin>
(It shows up in almost every custom exception I write)
21:38
<@Vornicus>
But this still technically /checks/ each prime.
21:38
<@ilovefire>
Which is not as efficient as we can get it.
21:39
<@Vornicus>
What we want to do is /stop checking/ once we know we'll be repeating ourselves.
21:39 * ilovefire is slowly starting to realize that coding is all about how efficient you can get it without cutting corners.
21:39
<@C_tiger>
actually cutting corners is just fine.
21:39
<@C_tiger>
It's before the code stops working.
21:39
<@McMartin>
Just don't cut the corners that are part of the answer.
21:39
<@Vornicus>
It's actually not. We just don't want to spend 4 and a half hours - or even a minute - checking primes, when we can spend less time.
21:40
<@Vornicus>
So, before we know we can do this, we need to check something: remember when I had you print known_primes?
21:40
<@Vornicus>
What'd you get?
21:41
<@ilovefire>
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
21:41
<@C_tiger>
Coding is two-fold: first you up with a method to do something, then you tweak the method to make it run better (faster, more efficiently, produce better-quality answers) OR if tweaking can't help, you start over and try a NEW method to see if it work better.
21:42
<@C_tiger>
it'd
21:42
<@Vornicus>
okay. Looking at that list, at what point do you know you no longer need to check numbers?
21:43
<@Vornicus>
for, say, n = 100?
21:44
<@ilovefire>
after 7?
21:44
<@Vornicus>
Right.
21:44
<@Vornicus>
and 11 > sqrt(100), right?
21:45
<@ilovefire>
yes...
21:45
<@Vornicus>
So how do we tell the loop to, uh, stop looping when that happens?
21:47
<@ilovefire>
Hmm...
21:47
<@Vornicus>
(this should be in your notes)
21:48
<@ilovefire>
Break?
21:49
<@Vornicus>
Try it.
21:53 * ilovefire fiddles with different places to apply the if statement and the break.
21:54
<@ilovefire>
... BRB
21:54 ilovefire is now known as ilf_AFK
22:05 * AnnoDomini wonders why Firefox is so very slow at rendering images, but apparently hasn't any problems at rendering the same images within a HTML document.
22:09
<@C_tiger>
Because when it's rendering images, it has to know if it needs to "resize" them so they fit.
22:09
<@C_tiger>
There's a line in about:config that stops this behavior.
22:10 NSGuest-3405 is now known as EvilDarkLord
22:20
<@C_tiger>
Ok, I'm done.
22:20
<@C_tiger>
I know what's wrong with my code, but it's almost too much work to fix.
22:21
<@C_tiger>
I have learned a whole lot about python in the process, which is really why I did this in the first place.
22:24
<@EvilDarkLord>
What is this code you speak of?
22:24 ilf_AFK is now known as ilovefire
22:24
<@ilovefire>
Okay, lesse.
22:24 * ilovefire goes back to fiddling.
22:28
<@C_tiger>
I wrote a little python script to teach myself python. It's to try to calculate the best way to solve "given N otherwise identical coins, where *two* are a different weight, using a two-pan balance find the two coins and determine whether they're heavy or light in the minimum number of uses of the scale.
22:30
<@ilovefire>
hmm, I know I need to bring a break in here...
22:30
<@C_tiger>
Well, you don't HAVE to... but I think that's the solution Vorn wants you to go for.
22:32
<@C_tiger>
Here's another approach:
22:32
<@C_tiger>
Forget your program for a second.
22:32
<@C_tiger>
Pretend you're the function is_prime.
22:33
<@C_tiger>
You have a list of primes from 2 - 97 (that's the list you printed above.)
22:33 * ilovefire nods
22:33
<@C_tiger>
Now how would you figure out if 100 is prime?
22:33
<@C_tiger>
Remember you can only check one thing at a time.
22:33 * ilovefire nods...
22:33
<@C_tiger>
Just walk me through it.
22:34
<@ilovefire>
Well, first off figure out what the cut-off point is--at what point where the numbers start to repeat, which is also, forutantley, at the number in question's square root.
22:35
<@C_tiger>
Ok, so first you calculate the square root.
22:35
<@C_tiger>
So now you know three things: you know you need to figure out if 100 is prime, you know that the square root of 100 is 10, you know a list of primes from 2 - 97.
22:35
<@C_tiger>
Now what?
22:36
<@ilovefire>
now, you check each prime below 10 to see if 100 is evenly divisble by it.
22:36
<@C_tiger>
Ok... but you can't check all the primes at the same time.
22:37
<@ilovefire>
Right, so you check those primes one at a time.
22:37
<@C_tiger>
(Also, pretend the number we're checking is 97, not 100... )
22:39
<@C_tiger>
Ok, check the first number: 2, 97%2 = 1, 1 == 0 false.
22:39
<@C_tiger>
Now what?
22:41
<@ilovefire>
then we check the second, which is 3... 97 % 3 == 1, 1 == 0 false.
22:41
<@C_tiger>
ok...
22:41
<@C_tiger>
ok now suppose we're on the fifth number: 11.
22:42
<@ilovefire>
Well, we wouldn't need to check that, because it's above the square root of 97, which is 9.849
22:42
<@C_tiger>
Right what did you just do?
22:44
<@ilovefire>
Err... found the break-even point of the number 97, and broke off my mind's loop because there's no need to test past it.
22:44
<@Vornicus>
okay.
22:44
<@C_tiger>
Right, you compared the number you got with the square you got earlier.
22:45
<@C_tiger>
So now do this in code.
22:45
<@ilovefire>
Hmm.
22:46
<@C_tiger>
er, squareroot.
22:47
<@ilovefire>
int(math.sqrt(k)) = break_even | for b in known_primes: | if b > break_even:
22:47
<@ilovefire>
| Break
22:47
<@ilovefire>
I guess
22:47
<@C_tiger>
... good.
22:48
<@C_tiger>
you have to do break_even = int(math.sqrt(k))
22:48
<@ilovefire>
Ah.
22:48
<@ilovefire>
Well, almost had it right in one go.
22:48
<@C_tiger>
Now try it.
22:49
<@Vornicus>
don't need to int it.
22:49
<@C_tiger>
(it doesn't hurt.)
22:50
<@Vornicus>
(we needed to in the xrange one to get rid of that deprecation warning, but we don't here)
22:50
<@ilovefire>
Hmm, still dosen't work.
22:50
<@C_tiger>
Ok, pastie time.
22:50
<@Vornicus>
Yeah, show us what you're doing, then we can beat it with sticks.
22:51
<@C_tiger>
Also, don't think of = as "equals" think of it as the assignment operator. You assign the right hind side to the variables in the left hand side.
22:51 * ilovefire nods
22:51
<@C_tiger>
x = 2 doesn't mean x equals 2, it means you put 2 into x
22:51
<@ilovefire>
http://rafb.net/p/eozW6596.html
22:52
<@Vornicus>
How does it fail? looks okay to me.
22:52
<@C_tiger>
Man, beat me to the punch.
22:52
<@Vornicus>
oh, I see how it will fail.
22:52
<@ilovefire>
Oh?
22:52
<@Vornicus>
it will fail on the /second/ attempt, because known_primes is out there instead of inside.
22:53
<@ilovefire>
ah, so I need to stick known_primes on the inside of is_prime?
22:53
<@C_tiger>
Oh, right, you never told it to look at known_primes.
22:53
<@Vornicus>
You need to put known_primes in primes(), and you need to pass known_primes /to/ is_prime.
22:53
<@C_tiger>
Wait, we never did this before?
22:53
<@Vornicus>
We did this before. I don't know why it got changed.
22:54
<@C_tiger>
ANYHOW, you got the break part right.
22:54
<@Vornicus>
Yes.
22:55
<@ilovefire>
yay.
22:55
<@ilovefire>
Now to fix the other problem, because I honestly have no idea how I screwed that up.
22:55
<@C_tiger>
Why is known_primes declared outside?
22:56
<@ilovefire>
C: I honestly can not remember.
22:57
<@C_tiger>
Also, when you get this thing fully ironed out, cheer! I think this may be the last of prime numbers you see in a while.
22:57
<@C_tiger>
(Unless Vorn has one more trick up his sleeve (which wouldn't surprise me, now that I think about it.)
22:57 * ilovefire phews, saves the celebrations.
22:58 * ilovefire stranges, can't seem to remmeber how to pass known_primes to is_prime... hmm.
22:58
<@Vornicus>
Actually once you get it right, we have only one thing left to do, and that's trivial.
22:58
<@C_tiger>
It's as easy as you think it would be.
22:59
<@C_tiger>
(Python is surprisingly nice about this, as I have discovered.
22:59
<@C_tiger>
)
23:00
<@Vornicus>
(it doesn't require any thinking at all; it's just changing the function from testable to usable with other code, which is just removing any print statements, and making it return known_primes. Don't do this until you're sure it's right though)
23:02
<@Vornicus>
(also we might /use/ primes() to get sample data once in a while.)
23:03 * ilovefire eyes. "Global name 'known_primes' is not defined."
23:03
<@C_tiger>
are you passing it correctly?
23:03
<@C_tiger>
And spelling it correctly?
23:03
<@ilovefire>
C: as far as I'm aware, but BRB
23:03 ilovefire is now known as ilf_AFK
23:06
<@C_tiger>
Also make sure you have somewhere where you actually say what known_primes is (as in assign an empty list to it)
23:08
<@ilf_AFK>
C: I have, in primes()
23:08 ilf_AFK is now known as ilovefire
23:08
<@Vornicus>
Okay, and are you passing it to is_prime()?
23:09
<@C_tiger>
(both in the call and in the line where you define the function)
23:14
<@Vornicus>
also, pastie, if you haven't figured it out.
23:17
<@ilovefire>
http://rafb.net/p/iYCFFa46.html
23:17
<@C_tiger>
Um.
23:17
<@C_tiger>
so no passing.
23:17
<@Vornicus>
You haven't passed known_primes to is_prime
23:18
<@C_tiger>
or put it in the prototype.
23:20
<@ilovefire>
well, should I allready know the syntax for this?
23:20
<@C_tiger>
yes.
23:20
<@C_tiger>
You've done it before.
23:22
<@ilovefire>
Okay, between my parents bombarding me with questions and other vagaries of existance, I can't concentrate to figure it out.
23:23
<@C_tiger>
Ok, you are already passing something to is_prime
23:23
<@Vornicus>
Hell, not only did you do it before, you did it with /these very functions/
23:27
<@ilovefire>
Right, so...
23:30
<@Vornicus>
How do you make a function take multiple arguments?
23:30
<@ilovefire>
oh. Right.
23:30
<@C_tiger>
(like add, remember when we wrote add way back when?)
23:32
<@ilovefire>
... except if I make it is_prime(k, known_primes) it won't work, and umm... I guess if it, umm.
23:32
<@C_tiger>
When you call add, how do you do it?
23:32
<@Vornicus>
Why won't it work?
23:32
<@C_tiger>
My guess is either it's missing from the declaration or the call.
23:33 * Vornicus wanted ILF to figure that out.
23:34
<@C_tiger>
sorry.
23:34
<@C_tiger>
it seemed like you were confused.
23:34
<@C_tiger>
But then again, I got 2 hours of sleep last night.
23:34
<@Vornicus>
heh
23:34
<@Vornicus>
You really need to stop these all-night hacking sessions. :P
23:35 ilovefire [~santros_v@209.82.191.ns-11321] has quit [Ping Timeout]
23:35
<@C_tiger>
Hah, like my programing chops go beyond things that shuffle data around.
23:35
<@Vornicus>
piffle.
23:37 ilovefire [~santros_v@209.82.191.ns-11321] has joined #code
23:39 mode/#code [+o ilovefire] by C_tiger
23:53
<@Vornicus>
anyway, where were we?
23:54
<@ilovefire>
I have come to realize that, whenver my mother asks me a questions, it allways derails my current train of thought so much that I cannot reclaim it.
23:54
<@Vornicus>
Heh
23:54
<@ilovefire>
Otherwise I would probably have figured out my problem by now.
23:54
<@TheWatcher>
That isn't as unlikey as you might think
23:55
<@ilovefire>
http://rafb.net/p/ERButR38.html so, oh people with less easily distractable minds, where have I gone wrong?
23:55
<@Vornicus>
ilf: now you need to tell is_prime where it's supposed to be getting known_primes.
23:55
<@C_tiger>
Read it through really carefully.
23:56 You're now known as TheWatcher[T-2]
23:56
<@C_tiger>
Start with primes, now pretend you're the computer, tell me what's going on.
23:59
<@C_tiger>
(This exercise may seem annoying but it's really important.)
--- Log closed Sat Dec 15 00:00:09 2007
code logs -> 2007 -> Fri, 14 Dec 2007< code.20071213.log - code.20071215.log >