--- Log opened Thu Sep 23 00:00:49 2010 |
00:06 | | * Vornicus sneaks up on Kaura and balances a chili dog on his head. |
00:06 | | * EvilDarkLord pounce, nom. |
00:06 | < kaura> | AUGHMEINHEAD |
00:07 | < kaura> | Also, Vorn, would being able to do the opposite of generating a deck be out of my skill level? Say, user input to put cards into a list... |
00:08 | <@Vornicus> | So, what, you want to, idunno, have a person type in, uh, card names and it'll shuffle them or do other things like that? |
00:09 | < kaura> | Something like that. >_> |
00:09 | <@Vornicus> | So you could type in, say, a Magic deck. |
00:09 | | * kaura coughs |
00:10 | <@Vornicus> | --or even better, pull the decklist from a file. |
00:10 | | * kaura looks shiftyeyed |
00:11 | < kaura> | Well, that last bit probably isn't fully necessary. |
00:11 | <@Vornicus> | Kaura, would you like to know the first thing I ever did that took advantage of the full power of computers? |
00:11 | < kaura> | But I was mainly wondering as to the possible complexity of such a program. |
00:11 | < kaura> | Sure. |
00:13 | <@Vornicus> | I took an M:tG oracle text file and generated a nicely-formatted word document that had all that stuff in there. |
00:13 | < kaura> | Ah, so I'm in good company. >__> |
00:13 | <@Vornicus> | (this is before I learned to program, but I gave Excel, Word, and Wordpad a hell of a workout.) |
00:16 | <@Vornicus> | (but it did stuff like color the name of the card according to the color of the card -- which it discovered from the mana cost.) |
00:17 | <@Vornicus> | aaaaanyway, okay, so let's see. What do you want it to be able to do with the deck once you've got it loaded? |
00:17 | <@Vornicus> | Also I should check something... |
00:18 | <@Vornicus> | Are there any magic cards with a name that begins with a digit? |
00:18 | | * kaura ponders |
00:18 | < kaura> | No. |
00:18 | <@Vornicus> | Okay good, that makes my life easier. |
00:19 | < kaura> | Shuffle the deck and draw out the first seven cards of the rearranged deck on command, I'd say. ...and possibly to draw a card on command too. |
00:22 | < kaura> | So the program's basically in three parts, huh? First it generates a deck from an external text document, then it shuffles it, then it responds to user commands... |
00:22 | <@Vornicus> | All right, that sounds like a reasonable set of things. |
00:22 | <@Vornicus> | Exactly. |
00:23 | <@Vornicus> | SInce we know how to shuffle a deck, we'll work on that first bit too. |
00:23 | < kaura> | Right, that makes it seem very manageable then, soon as I figure out how to do the first. |
00:24 | <@Vornicus> | Before we actually do the first, we'll have to figure out what a deck list looks like. |
00:25 | <@Vornicus> | Clearly, it will have a bunch of lines in it, each one representing a card. We do it this way because there's spaces and stuff in the names, and "next line" is the most natural breaking point. |
00:27 | <@Vornicus> | (for reasons that you'll see in a moment) |
00:27 | <@Vornicus> | But on the other hand, we don't want to have to type, say, "Mountain" 15 times, if there's 15 mountains in the deck. |
00:27 | < kaura> | Right. That'd get tedious pretty fast. |
00:28 | <@Vornicus> | So we'll want our lines to look like "15 Mountain" |
00:30 | < kaura> | ...hm. Would the program be able to recognize it as two separate objects (# of instances and cardname), or do we need to add a comma to it? |
00:30 | <@Vornicus> | It will be able to recognize it as two separate things, yes -- because a number doesn't have any spaces in it, we'll split the line at the first space. |
00:31 | < kaura> | Ah. |
00:31 | <@Vornicus> | But anyway, build yourself a decklist, pastebin it. |
00:31 | <@Vornicus> | (that was a good question, by the way, and I'm glad you asked it) |
00:32 | < kaura> | (I'm learnin'~) |
00:36 | <@Vornicus> | Oh, and -- if you want to get a little more advanced, cards that only appear once in the deck can have no number at the start. |
00:37 | < kaura> | Ah, so it'll treat a null value as = 1, so long as the card's listed? |
00:37 | <@Vornicus> | We'll make that happen, yes. It's a couple extra lines of work though. Don't have to if you don't want to. |
00:39 | < kaura> | Hm. Not necessary, I think. |
00:39 | <@Vornicus> | ok |
00:42 | < kaura> | Ah, right, the decklist http://pastebin.starforge.co.uk/357 |
00:43 | | Attilla [Some.Dude@Nightstar-3009f80a.threembb.co.uk] has quit [[NS] Quit: ] |
00:43 | <@Vornicus> | All right, and save it as decklist.txt |
00:43 | <@Vornicus> | You want it to be in the same folder as the script we're about to make. |
00:44 | < kaura> | Right. |
00:45 | <@Vornicus> | Okay, now let's make a script! call it... hell I don't know what to call it, but save it with a .py on the end in the same folder. |
00:46 | < kaura> | Ahead of ye. Saved as MTGSimulator.py |
00:47 | <@Vornicus> | All right. So, in this file, let's make a function called load_deck; it will take a parameter called filename |
00:47 | < kaura> | So, def load_deck(filename) |
00:47 | <@Vornicus> | colon |
00:48 | < kaura> | Strange, I forget the colon in the chat, but I remember it in the actual file. >_>; |
00:48 | <@Vornicus> | Heh |
00:52 | <@Vornicus> | Okay, so, first thing we want to do is we want to load the file; there's a function called "open" that opens a file, given a name. Use that and place the file handle that you get into a variable called deckfile |
00:52 | < kaura> | Hm. Is it just a matter of implementing "return open(directory)"? |
00:52 | | Derakon[AFK] is now known as Derakon |
00:52 | <@Vornicus> | Not quite, we have several things to do here; this function will load the file and turn it into an actual list. |
00:52 | < kaura> | Ah. |
00:54 | <@Vornicus> | But we need to get the file opened first, so show me that line -- which will be in the function. Note that we're passing in a filename; don't give it the actual name of your deck list file yet. |
00:55 | <@Derakon> | It occurred to me just a couple minutes ago that Chroma would work much better as a singleplayer action-puzzle game than as a board game~ |
00:56 | <@Vornicus> | Godspeed~ |
00:56 | < kaura> | Think I'm missing something. Should it just be "open(deckfile)"? |
00:56 | <@Derakon> | Still with the hex grid, only now you have a limited amount of time to line up a route from a specified input hex to an output hex before the laser fires; if it can't find a path to that output then you lose. |
00:57 | <@Vornicus> | What'd we call the name of the file that is coming in. |
00:57 | <@Derakon> | As the game speeds up you have to field multiple simultaneous colors...you could have bonuses pop up that give you extra points etc. if lasers pass through them. |
00:59 | < kaura> | Wait, so it should be open(decklist.txt)? |
01:00 | <@Vornicus> | No. What did we call the filename that we're passing into the function. |
01:01 | <@Vornicus> | (because we don't want this thing to assume you only ever have one deck, we must make sure -- and we'll do this soon -- that we can give it different deck filenames.) |
01:01 | < kaura> | Oh, duh. That makes sense. the variable in open() has to be the same as the parameter entered, right? So it would be open(filename) in this case, as the definition was def load_deck(filename): |
01:03 | < kaura> | Then the next step... would be to define what filename is, right? |
01:03 | <@Vornicus> | Yes. But open returns a file handle which he then have to use later -- so we have to store it. Let's call it "deck_file" |
01:04 | <@Vornicus> | no- filename comes in from the outside, and we're working inside the function. Our next actual step will be to figure out how to iterate over the file; once we've got that we can put something after the function to call it and test it. |
01:05 | < kaura> | Ah. |
01:06 | <@Vornicus> | (while we do this, we'll be writing and then removing a lot of "see if this works" code -- so we can keep up with what we're doing.) |
01:08 | <@Vornicus> | Okay, so now what we have to do is iterate over the lines in the deckfile. Fortunately, files, when you iterate over them, give you one line at a time -- like iterating over lists gives you one item at a time. |
01:10 | <@Vornicus> | Usually I call the iteration variable for stuff like this "line" |
01:10 | < kaura> | Right. So something that reads "15 Mountain," inserts fifteen of the same items into a list, then does the same for every line until the end. |
01:10 | <@Vornicus> | Right, but we don't wanna get that far yet. |
01:10 | < kaura> | Ah, I jumped ahead. |
01:11 | <@Vornicus> | We /do/ want to see that we're iterating properly, and to do this we'll be printing each line. |
01:15 | < kaura> | So if we had print(line), it basically gives us the decklist, right? |
01:15 | <@Vornicus> | Well, it gives us that one line, when we've put it in the loop. |
01:15 | < kaura> | Ah, right. |
01:19 | <@Vornicus> | So once you've got that, put load_deck("decklist.txt") after the function. |
01:20 | | AnnoDomini [annodomini@Nightstar-15ed2696.adsl.tpnet.pl] has quit [[NS] Quit: leaving] |
01:20 | < kaura> | Eh... still blocked on how to iterate the lines. Lesse... |
01:21 | <@Vornicus> | This is actually something that I covered but you skipped beyond when actually doing stuff -- when I described the tools you need to create a deck of cards. |
01:21 | < kaura> | Ahh... whoops. |
01:22 | <@Vornicus> | (instead of using for loops, you used list comprehensions. But list comprehensions won't help you now. *insert maniacal laughter*) |
01:22 | < kaura> | "Nooooooooo" |
01:29 | < kaura> | Hrn. Is this right? |
01:29 | < kaura> | deck = () |
01:29 | < kaura> | for line in deck_file: |
01:29 | < kaura> | deck.append(line) |
01:29 | <@Vornicus> | No; for one thing, you can't change a tuple; for another, you just want to print each line, not add it to a list yet. |
01:30 | <@Vornicus> | We're building this code slowly so you can see what's going on at each step. |
01:31 | < kaura> | Hrn... |
01:35 | <@Vornicus> | (you are close, but you're getting ahead of yourself again) |
01:37 | < kaura> | Hrn. So just remove the first line of the above paste, and change deck.append to simply print(line)? |
01:37 | <@Vornicus> | yep. |
01:38 | < kaura> | Ah, yeah. I see what you mean by getting ahead of myself~ |
01:39 | < kaura> | ...weird. "name 'decklist' is not defined. |
01:40 | < kaura> | Oh, right, the quote marks. |
01:40 | < kaura> | ...so instead I get "no such file or directory." |
01:40 | <@Vornicus> | "decklist.txt" |
01:40 | <@Vornicus> | or whatever you called it? |
01:41 | < kaura> | Right. Added the quote marks and double-checked. They're in the same folder, but it's not reading it. |
01:41 | <@Vornicus> | okay, very strange. Working in IDLE? |
01:42 | < kaura> | Ye- oh. Found the problem. I thought I copypasted the program onto a separate folder, but the program's running off a copy of the original folder. So, duh. Need to fix that~ |
01:42 | <@Vornicus> | Well caught. |
01:43 | | Stalker [Z@26ECB6.A4B64C.298B52.D80DA0] has quit [Ping timeout: 121 seconds] |
01:44 | <@Vornicus> | Anyway, the program, as currently written, should pretty much just print the deck list. |
01:46 | < kaura> | Hah. Minor blooper. If it's written "for line in deck_file: print(deck_file)" it'll just print out the individual letters of the file name. Fixed it to "for line in open(deck_file):" |
01:47 | < kaura> | And, yep, Printed the decklist. ...though, with a blank line between each entry. |
01:47 | <@McMartin> | That's because each line ends with a line feed, basically. |
01:47 | <@Vornicus> | okay, that's not that awesome, but not surprising! |
01:48 | <@Vornicus> | Each line string ends with a "newline" character; print itself also inserts a newline. |
01:48 | < celticminstrel> | Oh, you're using Python 3. |
01:48 | < kaura> | 2.7 |
01:48 | < celticminstrel> | ... |
01:49 | <@Vornicus> | celmin: technically the () can be there in 2.7. |
01:49 | < celticminstrel> | Can they enclose the entire list of things to print, though? |
01:49 | | * Vornicus tries it. |
01:49 | < kaura> | ...hm... wonder if I can... |
01:50 | <@Vornicus> | ...mm, probably not a good idea to do it that way, actually. |
01:50 | <@Vornicus> | Kaura: what do you wonder? |
01:50 | < kaura> | Nope, sticking \n just gives raw text. >_> Thought so, but wanted to confirm. |
01:51 | <@Vornicus> | So, in order to proceed we now have two things we want to do: 1. clear the newline and possibly other spaces after the name of the card; 2. split the line into a number and a name. |
01:52 | < kaura> | Right. |
01:52 | <@Vornicus> | The first is a common enough thing -- and actually to be nice we should do it to the front too -- that it's a method on strings, called "strip" |
01:52 | <@Vornicus> | (same way append is a method on lists.) |
01:52 | <@Vornicus> | ANd the second is a common enough thing that it's also a method on strings, called "split" |
01:54 | < kaura> | So it would be... deck_file.strip('\n')? |
01:55 | < kaura> | (as it turns out, no) |
01:55 | | Vornotron [vorn@ServerAdministrator.Nightstar.Net] has joined #code |
01:56 | < Vornotron> | whee, power outage. |
01:57 | < kaura> | Oh dear. |
01:57 | < Vornotron> | ok where was I. |
01:57 | | Vornicus [vorn@ServerAdministrator.Nightstar.Net] has quit [Ping timeout: 121 seconds] |
01:57 | < kaura> | Methods "strip" and "split" |
01:57 | | gnolam [lenin@Nightstar-38637aa0.priv.bahnhof.se] has quit [[NS] Quit: Z?] |
01:58 | | Vornotron is now known as Vornicus |
01:59 | < kaura> | You mentioned append as a method, so I tried deck_file.strip... and, yeah, didn't do much, needless to say. >_> |
01:59 | < Vornicus> | Clearly not, as deck_file isn't a string! |
02:00 | < Vornicus> | line is though. |
02:00 | < kaura> | Oh, silly me. |
02:00 | < Vornicus> | Don't forget your parentheses to say you're calling the function though |
02:00 | < kaura> | Right. |
02:02 | < celticminstrel> | Just line.strip(). No parameter. |
02:02 | < Vornicus> | strip's easy to use; you don't need to tell it anything because its normal behavior gives you the thing you want. Anyway, changing that to print line.strip() will make it so there's no blank lines. |
02:04 | < kaura> | Oh, I see. line.strip() isn't a separate command. You're literally adding (.) the strip command to the print line. |
02:04 | < kaura> | Aaand success. |
02:04 | <@Derakon> | \o/ |
02:04 | < Vornicus> | Right; unlike shuffle or sort, strip doesn't mangle the thing, it gives you a fresh one. |
02:07 | < Vornicus> | The same is -- sort of -- true of split; the original string remains the same, but you get a list of strings out of it. |
02:10 | < kaura> | Ah, so it does. Though, it seems as if additional parameters have to be added so that it only splits the numbers from everything else, and not the individual words... |
02:10 | < Vornicus> | Right. |
02:10 | < celticminstrel> | .split(' ',1) |
02:10 | < Vornicus> | http://docs.python.org/library/stdtypes.html#str.split |
02:11 | < Vornicus> | I don't recommend celmin's for a simple reason. |
02:14 | < Vornicus> | Specifically: you might line up your names so they all start at the same character. |
02:14 | < Vornicus> | Which means there may be more than one space in there. |
02:15 | < celticminstrel> | True. |
02:15 | < celticminstrel> | But if you've stripped first, any leading spaces will be gone. |
02:15 | < Vornicus> | Right, but it's the /middle/ spaces that I'm worried about here. |
02:15 | < celticminstrel> | Though, that wouldn't account for multiple spaces separating the parts. |
02:15 | < Vornicus> | You want to eat both of them. |
02:15 | < Vornicus> | All of them. |
02:15 | < celticminstrel> | For that, you kind of need regex. |
02:15 | < Vornicus> | No You Do Not. |
02:16 | < kaura> | Ah, so what we're actually looking for is line.split(None,1) |
02:16 | < celticminstrel> | Well, okay. It's not strictly necessary. But it looks nicer. |
02:16 | < Vornicus> | kaura: you're apparently better at reading the documentation than celmin. |
02:16 | < celticminstrel> | ...unless that works. |
02:16 | < Vornicus> | :) |
02:16 | < kaura> | I can speed read decently. >_> |
02:18 | | * Vornicus is kinda a troll sometimes. |
02:18 | < Vornicus> | Anyway, so line.split(None, 1) -- what's that give you? |
02:19 | < Vornicus> | or, rather, what's it show you in the prints. |
02:19 | < kaura> | ['4', 'Hand of the Praetors'], etc |
02:19 | < Vornicus> | All right. So now it's giving us lists! |
02:20 | <@Derakon> | ...are you writing an MtG program? |
02:20 | | * kaura coughs |
02:20 | < kaura> | Yes |
02:20 | <@Derakon> | Carry on. :) |
02:20 | < Vornicus> | (it won't have many actual features, obviously, but it's a good time.) |
02:21 | < kaura> | (It's good practice, and it builds directly off of what I learned earlier. Kinda. >_>) |
02:22 | < Vornicus> | All right, so we're most of the way there in pulling data out. Now we want to extract the card count, and the card name, from that list. |
02:22 | <@Derakon> | Hey, if you can make programs you actually find interesting, all the better. |
02:22 | < Vornicus> | This shouldn't be too hard. But what you want to do is make sure that the card count gets extracted /as a number/ |
02:22 | | Stalker [Z@3A600C.A966FF.5BF32D.8E7ABA] has joined #code |
02:22 | < kaura> | line[0] and line[1] respectively, right? |
02:23 | < Vornicus> | Indeed, but watch that card count carefully! |
02:24 | < kaura> | So we need to make sure line[0] is expressed as an integer... |
02:24 | < Vornicus> | right. How did we do that in the guess-the-number game? |
02:26 | < kaura> | int(), right? |
02:26 | < Vornicus> | Right, so our count-extractor looks like... |
02:26 | < kaura> | So int(line[0]) |
02:27 | < Vornicus> | right. |
02:27 | < Vornicus> | now after those, say, exactly-but-for-names: print count, card |
02:32 | < Vornicus> | And what you get out should look familiar. |
02:32 | < kaura> | ...huh. print int(line[0], line[1] only garners me the count, not the cards. ...and puts a space between the 1 and 0 in the one double-digit number? O_o |
02:33 | | * kaura eyes his code. Okay, what'd I do this time? |
02:35 | < Vornicus> | Close Your Parentheses |
02:35 | < Vornicus> | Oh, oh, oh. |
02:36 | < Vornicus> | And, split and strip didn't change line; it created a new list, which you have to assign to something. |
02:36 | <@McMartin> | Erm |
02:36 | <@McMartin> | strip makes a new string, split makes a new list |
02:36 | <@McMartin> | This isn't Haskell; strings and lists are different things |
02:37 | < Vornicus> | I was playing fast and loose with vocabulary. |
02:38 | < Vornicus> | But he's applying both, I think, and the result will be a list. |
02:38 | < kaura> | Right, I am. |
02:39 | < kaura> | Oh, there we go. newline = line.strip().split(None,1) then print int(newline[0]), newline[1] |
02:39 | < Vornicus> | So assign your result of futzing with line to a variable, and then index /that/ |
02:40 | < Vornicus> | I would not call it newline; "entry" might work. |
02:40 | < kaura> | That'd be a better name for it, yeah. |
02:40 | < Vornicus> | Also while we're here, assign int(entry[0]) and entry[1] to variables. |
02:40 | < kaura> | Oh, good idea. |
02:41 | < kaura> | So count = int(entry[0]) and card = entry[1], making the print command "print count, card" |
02:42 | < Vornicus> | Yep. |
02:42 | < kaura> | Which, indeed, outputs something very similar to what we started with, except for all the stuff underneath and not shown. |
02:43 | < kaura> | Minus the brackets and '' and commas too. |
02:43 | < Vornicus> | All right, so let's get this party started. |
02:43 | < Vornicus> | Before the for loop, create a new, empty list. Call it, idunno, "deck" |
02:44 | < kaura> | Right, deck = [] |
02:45 | < Vornicus> | Okay, now inside our for loop, we're going to have to add things to deck a number of times equal to count |
02:45 | < Vornicus> | So here's a small puzzle for you: how do you do something 4 times? |
02:45 | < kaura> | object*integer? |
02:46 | < Vornicus> | Not... well, not quite. |
02:46 | <@Derakon> | As it happens, "[4] * 4" gives [4, 4, 4, 4], but this isn't where Vorn's going. |
02:47 | | Tarinaky [Tarinaky@Nightstar-f349ca6d.plus.com] has quit [Connection closed] |
02:47 | <@Derakon> | (Likewise, "'foo' * 4" gives "foofoofoofoo") |
02:47 | <@McMartin> | ... I just realized that thanks to lazy evaluation and immediate garbage collection, in Haskell iterating over, say, [1..1000000] stated as an in-expression list range literal will compile to something more like xrange. |
02:47 | | RichardBarrell [mycatverbs@Nightstar-3b2c2db2.bethere.co.uk] has quit [Ping timeout: 121 seconds] |
02:47 | < Vornicus> | (or more saliently: 'Hand of the PraetorsHand of the PraetorsHand of the PraetorsHand of the Praetors') |
02:48 | < kaura> | Ah, that would be a mild problem. |
02:48 | | Derakon is now known as Derakon[AFK] |
02:50 | < kaura> | Hrn. Getting called for dinner and I apparently have to clean up my room in preparation for a real estate assessment tomorrow. Short break, I think. |
02:50 | < Vornicus> | Ok. |
03:11 | | Orthia [orthianz@Nightstar-55a9e07f.xnet.co.nz] has joined #code |
03:22 | | Zed [Zed@Nightstar-556ea8b5.or.comcast.net] has quit [Ping timeout: 121 seconds] |
03:25 | | Thaqui [Thaqui@27B34E.D54D49.F53FA1.6A113C] has quit [Client closed the connection] |
03:36 | | Zed [Zed@Nightstar-556ea8b5.or.comcast.net] has joined #code |
03:54 | | Derakon[AFK] is now known as Derakon |
04:03 | < kaura> | Argh. Chores are like hydras. Once you've lobbed one off, more take their place. bbl. |
04:45 | | kaura [kaura@A2BA3E.5613D5.A7C357.372C7B] has quit [Ping timeout: 121 seconds] |
05:15 | | * Derakon kinda wants to start making a puzzle game, but feels like it'd be betraying Jetblade. ¬.¬ |
05:19 | < Orthia> | JETBLADE PUZZLE EDITION |
05:19 | <@Derakon> | Heh. |
05:20 | | * Derakon copies the engine bits out of Jetblade, comes up with 28 files not counting the quad tree. |
05:30 | <@McMartin> | Crate destruction puzzles a la the end of the infinite corridor in La Mulana. |
05:37 | <@Derakon> | Okay, there. |
05:37 | <@Derakon> | I now have a program that will run and display a black screen and a very impressive FPS count~ |
05:37 | | celticminstrel [celticminst@Nightstar-f8b608eb.cable.rogers.com] has quit [[NS] Quit: And lo! The computer falls into a deep sleep, to awake again some other day!] |
05:41 | < Vornicus> | Heh |
05:42 | <@Derakon> | (The important thing is that it's doing this by using a bunch of code from Jetblade) |
05:45 | | kaura [kaura@Nightstar-fd82400d.snfc21.sbcglobal.net] has joined #code |
05:49 | < Vornicus> | welcom back, kaura. |
05:50 | < kaura> | Thank you. |
05:51 | | * kaura kicks his laptop a few times |
05:51 | <@Derakon> | Hooray, now it draws an object too~ |
05:53 | <@Derakon> | Style question: given that every OpenGL function begins with "gl", is it bad that I do "import OpenGL.GL as GL" and then do "GL.glFoo", instead of doing "import * from OpenGL.GL" like I see in all the examples? |
05:53 | <@Derakon> | (I have a pathological hatred of "from foo import *") |
05:59 | <@McMartin> | Nothing wrong with that |
06:00 | <@Derakon> | Thanks for the validation~ |
06:03 | <@Derakon> | Now to figure out how to get my primitives drawing to work. |
06:06 | <@Derakon> | Any ideas? http://paste.ubuntu.com/498929/ |
06:06 | <@Derakon> | That's the top-level drawing logic for my main loop. |
06:15 | < Vornicus> | kaura: earlier we were working on trying to figure out how to do something some known number of times. |
06:20 | < kaura> | Ah, so we were. Sorry, trying to find a few pennies to prop this laptop up with. Think it'll be less crash-prone if I can get some air circulation going... |
06:21 | < Vornicus> | Air is good. |
06:22 | < Orthia> | Blocks of ice are better! |
06:22 | < Orthia> | If somewhat troublesome in the typing compartment. |
06:22 | < kaura> | Liquid nitrogen better yet! Pity that requires a bit of engineering skill that I do not possess. |
06:23 | < kaura> | Oh, and resources. |
06:23 | < kaura> | Say, the actual nitrogen. |
06:23 | < Vornicus> | Dry ice is cheap. |
06:25 | < kaura> | ...hmm. Need to hunt up some glue later. Laptop's still good for a few hours, I think. |
06:26 | < kaura> | Right. Reiterating the second index by the integer of the first... |
06:27 | < Vornicus> | "Do Something Some Number Of Times" |
06:32 | < Vornicus> | Here's a hint: it uses a thing we've already used today, and a thing we used Monday. |
06:33 | < kaura> | Well, I kind of figured it's a deck.append operation, with a list comprehension that tells it to make x cards y number of times. Getting my head to interpret that into code is giving me one of those blocks again, but I think I'm getting close. |
06:34 | < Vornicus> | List comprehensions won't help you much here. |
06:34 | < kaura> | Damn, wrong track then. |
06:34 | < Vornicus> | What'd we use last time? |
06:36 | < kaura> | A make_deck function- ...hmm. |
06:36 | < Vornicus> | Not that last time. |
06:36 | < Vornicus> | Last time I said "won't help you" |
06:37 | < kaura> | A for loop. |
06:38 | < Vornicus> | All right. So how do you execute the body of a loop, say, 4 times. |
06:39 | < kaura> | ...for card in line: list(count)? |
06:39 | | Derakon is now known as Derakon[AFK] |
06:39 | < Vornicus> | I'm looking to make an independent loop that all it does is run the body four times. |
06:40 | < Vornicus> | ...but before we get there: |
06:40 | < Vornicus> | How many times does a for loop run its body, when given a list? |
06:40 | < kaura> | Once? |
06:41 | < Vornicus> | A few more than that. Try: for k in ["a","b","c"]: print "running!" |
06:42 | < kaura> | Ah, silly me. Once per string. |
06:43 | < Vornicus> | Once per item. |
06:43 | < kaura> | Item. |
06:43 | < Vornicus> | Now, we have a function that creates a list with a certain number of items. |
06:45 | < Vornicus> | (it's not list; we have used it though.) |
06:46 | < kaura> | Oh, there we are. Took a bit of fiddling: "for count in card: print card" |
06:47 | < Vornicus> | Whaaaat |
06:47 | < kaura> | ...no, not at all. |
06:47 | < kaura> | I'm clearly getting closer. It didn't print out one letter at a time this time. >_> |
06:47 | < kaura> | (but the numbers are all wrooonngg) |
06:47 | < Vornicus> | Har. No. |
06:48 | < Vornicus> | Again: there is a function, and we have used it, that all it does is create a list with a certain number of items in it. |
06:51 | < Vornicus> | We have used it once before. I'm not going to tell you what it is though. |
06:54 | < kaura> | Yeah. >_< I need to take better notes. Pretty sure I can figure it out; just need some time to butt my head against this some more. |
06:54 | < Vornicus> | You have all the code you've written. It's in there. |
06:55 | < Vornicus> | (that you've written all of 30 lines of code at this point makes your job a lot easier. |
06:57 | < kaura> | GOT IT |
06:57 | < kaura> | for entry in range(count): print card |
06:58 | < Vornicus> | YAY |
06:58 | < Vornicus> | Also in this case, use something like "k" as your iteration variable, not "entry" |
06:58 | < Vornicus> | --also, each loop should have a different variable from the one it sits within. |
06:58 | < kaura> | Ah, I see. Fixed. |
06:59 | < Vornicus> | Okay. Now, instead of printing card, what do you actually want to do. |
07:00 | < kaura> | Append to deck, which is simple. I just replace the print command with deck.append(card) |
07:00 | < Vornicus> | All right. |
07:00 | < kaura> | Aaand yes. Prints out exactly as expected. |
07:01 | < kaura> | So next is randomizing, which is a matter of reusing code from last time. |
07:03 | < jerith> | Morning. |
07:03 | < kaura> | 'lo jerith |
07:04 | < Vornicus> | Right. Once that's all set up, then pastebin your code. |
07:05 | < Vornicus> | (remember: you want to do shuffling outside all the loops -- and after them. But inside the function.) |
07:12 | < kaura> | http://pastebin.starforge.co.uk/359 |
07:13 | < kaura> | It woorrrrkks~ |
07:13 | < jerith> | You don't need to open the deck file twice there. |
07:15 | < Vornicus> | Indeed; the first one can be removed. Or you can assign the result of the first one to a variable and use that in the for loop, but the first way's probably preferable. |
07:16 | < Vornicus> | While we're in there. "import random" should be at the top; you don't need to use a function within a function -- indeed, you're doing that wrong, the outer function should return the shuffled deck, not print it. |
07:18 | | kw-school-n is now known as kwsn |
07:20 | < kaura> | Erph... right, lesse... |
07:21 | < Vornicus> | (we can't do anything with what we've printed; only with what we've returned. |
07:23 | < kaura> | Think that's a bit better: http://pastebin.starforge.co.uk/361 |
07:24 | < kaura> | ..hrn, not quite. |
07:24 | < Vornicus> | Don't loop the deck to return it. |
07:24 | < Vornicus> | (return Ends The Function, no matter if the function otherwise appears to end at that point.) |
07:26 | < kaura> | ...hm. If I simply have it "return deck" after random.shuffle, it gives me it as a list, but not as lines. |
07:27 | < Vornicus> | That's true; a list is not made of lines but of items. |
07:28 | < kaura> | ...right, I think I was expecting it to give me the deck as lines of the individual card. But the code does specifically tell it to give it as a list. |
07:29 | < Vornicus> | If you want to print the loaded deck as lines, use the loop print: for card in load_deck("decklist.txt"): print card |
07:30 | < kaura> | Ahh, of course. |
07:30 | < kaura> | And so it does. |
07:31 | < kaura> | Right, I understand now. Need to get better at reading it by the order of operations. |
07:32 | < Vornicus> | But anyway. Now we have a thing that loads up our deck. Call that function and assign its result to a variable and we'll call it done for tonight. Tomorrow we'll write some functions that will perform operations on the deck. |
07:32 | < kaura> | Excellent. Thank you. |
07:35 | < Vornicus> | (and please, show me how you're calling and assigning, cuz you seem to have missed that step a couple times now.) |
07:35 | < kaura> | Yeah. >_> |
07:40 | | Ortiha [orthianz@Nightstar-d6ed1097.xnet.co.nz] has joined #code |
07:41 | | * Vornicus pokes kaura till it is shown |
07:42 | | Orthia [orthianz@Nightstar-55a9e07f.xnet.co.nz] has quit [Ping timeout: 121 seconds] |
07:43 | < kaura> | Ack, sorry, thought you meant for me to show it tomorrow. |
07:44 | < kaura> | Since everything defined in the function doesn't affect anything outside, and since we're working on operations on the deck tomorrow, I figured it'd be safe to define "deck = load_deck('decklist.txt')" |
07:44 | < Vornicus> | That's how it's done. |
07:44 | < kaura> | Ah, good. |
07:59 | < Alek> | xxx: I was taking the radiator off the cpu. slipped up and stabbed a hole in the motherboard with the screwdriver. |
07:59 | < Vornicus> | >_< |
07:59 | < Alek> | xxx: now the comp doesn't glitch, speed is up 30%, and it doesn't over heat. |
08:00 | < Alek> | yyy: you cleaned its chakras. |
08:00 | < kaura> | Custom air cooling system! |
08:00 | | * kaura eyes his laptop speculatively. |
08:01 | < Alek> | you gotta know where to stab. <_< |
08:03 | < kaura> | Presumably, anywhere where there isn't a circuit to damage. |
08:05 | | Vornicus is now known as Vornicus-Latens |
08:05 | < Alek> | pretty much. |
08:06 | < Alek> | although, if you're good enough at circuit design, you could possibly figure out a place WITH a circuit to stab. <_< |
08:08 | < kaura> | That... would be suboptimal. Presumably, even the non-vital functions are, at times, vital. |
08:09 | < Alek> | unless it was suboptimally designed in the first place. |
08:09 | < Vornicus-Latens> | There is the relatively famous case of the computer doing evolutionary design on analog circuits that placed something disconnected from everything else... but removing that disconnected device made the thing not work. |
08:09 | | * Alek shrugs. |
08:09 | < Alek> | Vorn: yeah, yeah, I can actually understand that. |
08:10 | < Alek> | strangely enough, it CAN happen. logically and scientifically explainable, too. |
08:10 | | Rhamphoryncus [rhamph@Nightstar-473f8685.abhsia.telus.net] has quit [Client exited] |
08:12 | < kaura> | A weird sort of timing system where if you "optimize" it by removing the vestigial circuit, things slowly go out of whack...? >_> |
08:21 | | Stalker [Z@3A600C.A966FF.5BF32D.8E7ABA] has quit [Ping timeout: 121 seconds] |
08:24 | < Alek> | kaura: that's one option, yes. |
08:25 | < Alek> | back in the old days when memory/storage was on a constantly spinning drum, one old-school hacker optimized programs by placing the lines of code so that by the time one finished executing, the next one was just coming up under the read head. |
08:26 | < Alek> | another option is the unconnected wiring or circuit forming a magnetic field that boosts that of the working circuits, or being affected by them and passing it on to the next circuit in line. |
08:28 | < kaura> | Yeah, I kinda figured that the definition of "connected" might be a bit restrictive. Clearly, if removing it shuts the whole thing down, it's "connected" in the sense that its presence has some physical effect, even if it isn't involved in the process. |
08:28 | | kwsn [kwsn@Nightstar-a0abd809.dyn.centurytel.net] has quit [Ping timeout: 121 seconds] |
08:33 | | Zed [Zed@Nightstar-556ea8b5.or.comcast.net] has quit [Connection reset by peer] |
08:35 | | Syloqs-AFH [Syloq@NetworkAdministrator.Nightstar.Net] has quit [Ping timeout: 121 seconds] |
08:39 | < jerith> | It was on an FPGA, as I recall. |
08:39 | < jerith> | The inductive linkage between the "real" circuit and the disconnected bits had timing effects. |
08:40 | < jerith> | The whole thing was balanced very finely. Programming a different FPGA with the same circuit didn't work. |
08:41 | < kaura> | Ah-hah. So my guess was on the money. |
08:42 | < jerith> | I'm describing the best guess of the researchers involved. |
08:42 | < jerith> | Any attempt to investigate resulted in non-workiness. |
08:43 | < kaura> | ...that would make confirming it tricky, yeah. |
08:43 | < jerith> | (Because Heisenberg.) |
08:44 | < kaura> | Ah, it was (theoretically) so finely balanced that attempts at observing it would disrupt the timing? |
08:44 | < jerith> | Pretty much. |
08:44 | | You're now known as TheWatcher |
08:44 | < jerith> | It should be noted that such weirdness was uncommon in those experiments, but not unique. |
08:45 | < jerith> | Evolutionary design cares about what's /there/, not what's /documented/. |
08:45 | < jerith> | Erm. Horrible term. |
08:46 | < Alek> | works for me. |
08:46 | | * kaura ponders. It should be possible to recreate the circuit but for a slight variance of the timing effect, right, so that when observed in some manner, the act of observing "fixes" it? |
08:46 | < jerith> | By "evolutionary design", I mean "using evolutionary processes to achieve a given outcome by tweaking the fitness conditions". |
08:46 | < jerith> | The problem is that the internal processes were unknown. |
08:46 | < Alek> | kaura: there's tons of those out there. |
08:47 | < kaura> | ...well, damn. |
08:47 | < jerith> | Using a standard model of electronics, it should never have worked. |
08:47 | < Alek> | all those glitches that disappear as soon as a tech looks for them. >_> |
08:47 | < jerith> | Therefore, it must have been relying on minor imperfections in the physical device. |
08:48 | < jerith> | http://en.wikipedia.org/wiki/Unusual_software_bug |
08:48 | < kaura> | Ah... and you'd need to actually know what all those minor flaws are. Without disrupting them and making it impossible for it to work again under the same conditions. ...ow. |
08:52 | < jerith> | Also, function name of the week: strfry() |
08:52 | < Alek> | <3 |
08:52 | < jerith> | (It's in the GNU libc. It shuffles the contents of a string.) |
08:53 | < jerith> | Also, I'm horribly late. Cheerio.\ |
08:53 | < kaura> | strfry['onion', 'garlic', 'bell pepper', 'chicken'] |
08:53 | < kaura> | Seeya jerith |
09:08 | | Anno[Laptop] [annodomini@Nightstar-1dbb6eaa.adsl.tpnet.pl] has joined #code |
09:32 | | ToxicFrog [ToxicFrog@ServerAdministrator.Nightstar.Net] has quit [Connection reset by peer] |
09:35 | | Thaqui [Thaqui@27B34E.D54D49.F53FA1.6A113C] has joined #code |
10:42 | | Zed [Zed@Nightstar-556ea8b5.or.comcast.net] has joined #code |
10:43 | | Syloqs_AFH [Syloq@NetworkAdministrator.Nightstar.Net] has joined #code |
10:44 | | Syloqs_AFH is now known as Syloqs-AFH |
12:19 | | * TheWatcher stabstabstabs php and it's crappy preg_ functions |
12:19 | <@TheWatcher> | -' |
14:14 | | gnolam [lenin@Nightstar-38637aa0.priv.bahnhof.se] has joined #code |
15:39 | | ToxicFrog [ToxicFrog@ServerAdministrator.Nightstar.Net] has joined #code |
15:39 | | mode/#code [+o ToxicFrog] by Reiver |
15:56 | | Tarinaky [Tarinaky@Nightstar-f349ca6d.plus.com] has joined #code |
16:07 | | Stalker [Z@3A600C.A966FF.5BF32D.8E7ABA] has joined #code |
16:58 | < gnolam> | http://www.kalzumeus.com/2010/09/22/security-lessons-learned-from-the-diaspora-l aunch/ |
17:00 | < Namegduf> | Reading the first point alone, I think the true lesson is "The Diaspora people do not know how to write secure code." |
17:03 | < Namegduf> | Oh, haha. That's their last point. |
17:04 | < Tarinaky> | "Whoops." |
17:06 | | Rhamphoryncus [rhamph@Nightstar-473f8685.abhsia.telus.net] has joined #code |
17:08 | < Tarinaky> | http://www.theregister.co.uk/2010/09/21/google_in_hunting_season/ << I like the idea of the Google mechanics turning up on Skis shouting "DONT WORRY IM HERE FROM THE INTERNETS!" |
17:14 | | Stalker [Z@3A600C.A966FF.5BF32D.8E7ABA] has quit [[NS] Quit: If the world didn't suck, we'd all fall off.] |
17:41 | | Alek [omegaboot@Nightstar-8f41d887.il.comcast.net] has quit [Ping timeout: 121 seconds] |
19:10 | | Stalker [Z@26ECB6.A4B64C.298B52.D80DA0] has joined #code |
19:22 | | Tarinaky [Tarinaky@Nightstar-f349ca6d.plus.com] has quit [Client closed the connection] |
19:56 | | * Vornicus-Latens gives Kaura an assignment in PM, then goes to work. |
20:23 | | Alek [omegaboot@Nightstar-8f41d887.il.comcast.net] has joined #code |
21:32 | < Anno[Laptop]> | I want to change all ^ in an expression to **. |
21:32 | < Anno[Laptop]> | $expression =~ s/\^/\*\*/; |
21:32 | < Anno[Laptop]> | Will this work? |
21:32 | < Anno[Laptop]> | (Perl.) |
21:34 | < jerith> | That should do it. |
21:34 | < jerith> | I don't think the escaping is mandatory in the replace string, but it doesn't hurt. |
22:37 | | Thaqui [Thaqui@27B34E.D54D49.F53FA1.6A113C] has quit [Connection closed] |
23:54 | | You're now known as TheWatcher[T-2] |
23:56 | | You're now known as TheWatcher[zZzZ] |
23:57 | | Tarinaky [Tarinaky@Nightstar-f349ca6d.plus.com] has joined #code |
--- Log closed Fri Sep 24 00:00:51 2010 |