Saturday, November 7, 2009

List Comprehension

I am enrolled in an Artificial Intelligence class this quarter which consumes about 20 hours per weekend every other weekend for the fortnightly programming assignment. (This is just how long it takes to complete the programming assignments, and doesn't include time spent preparing for the weekly quizzes, doing the required reading, completing the regular homework assignments, and studying for tests. Not that I'm complaining. I signed up for this, after all. :)) The programming part isn't usually too bad -- maybe eight hours of work -- but then I have to write a paper about the assignment. The writing usually takes quite a bit longer. Anyway, this is one of those weekends, but I'm taking a short break to talk about my current assignment and this sweet use of list comprehension I just whipped up.

We are studying constraint satisfaction problems and our latest assignment is to solve the game of Sudoku using some specific heuristics. We can use any programming language we choose, so I have used Python for all of the assignments so far. Python is so awesome that sometimes I feel like I'm cheating. For example, for this assignment, in order to implement one of the heuristics, I had to get a list of the coordinates for each block in the puzzle.

The "board" is basically a 2-dimensional array, where the top-left cell is at (0, 0) and the bottom-right cell is at (8, 8). Recall that the board is broken into 9 blocks of 9 cells each. The first block consists of the first 3 cells in each of the first 3 columns. What I was trying to get was a list of the coordinates for each cell in each of the blocks. The first block would look like this:

[(0, 0), (0, 1), (0, 2),
(1, 0), (1, 1), (1, 2),
(2, 0), (2, 1), (2, 2)]


The standard way to do this kind of thing, and the approach I would have taken if I were writing this in Java or C++, is to put together a couple of for loops and iteratively populate a big array. The whole thing might take 3-5 lines of code. But in Python, we can take advantage of some really cool features, like list comprehension, that can save the programmer a lot of time.

So here it is, the coordinates of each block in a Sudoku puzzle, in one line of Python:


>>> x = [[(i + a * 3, j + b * 3) for i in range(3) \
for j in range(3)] for a in range(3) \
for b in range(3)]
>>> x
[[(0, 0), (0, 1), (0, 2),
(1, 0), (1, 1), (1, 2),
(2, 0), (2, 1), (2, 2)],
[(0, 3), (0, 4), (0, 5),
(1, 3), (1, 4), (1, 5),
(2, 3), (2, 4), (2, 5)],
[(0, 6), (0, 7), (0, 8),
(1, 6), (1, 7), (1, 8),
(2, 6), (2, 7), (2, 8)],
[(3, 0), (3, 1), (3, 2),
(4, 0), (4, 1), (4, 2),
(5, 0), (5, 1), (5, 2)],
[(3, 3), (3, 4), (3, 5),
(4, 3), (4, 4), (4, 5),
(5, 3), (5, 4), (5, 5)],
[(3, 6), (3, 7), (3, 8),
(4, 6), (4, 7), (4, 8),
(5, 6), (5, 7), (5, 8)],
[(6, 0), (6, 1), (6, 2),
(7, 0), (7, 1), (7, 2),
(8, 0), (8, 1), (8, 2)],
[(6, 3), (6, 4), (6, 5),
(7, 3), (7, 4), (7, 5),
(8, 3), (8, 4), (8, 5)],
[(6, 6), (6, 7), (6, 8),
(7, 6), (7, 7), (7, 8),
(8, 6), (8, 7), (8, 8)]]
>>> len(x)
9
>>> x[0]
[(0, 0), (0, 1), (0, 2),
(1, 0), (1, 1), (1, 2),
(2, 0), (2, 1), (2, 2)]
>>> x[1]
[(0, 3), (0, 4), (0, 5),
(1, 3), (1, 4), (1, 5),
(2, 3), (2, 4), (2, 5)]
>>> x[8]
[(6, 6), (6, 7), (6, 8),
(7, 6), (7, 7), (7, 8),
(8, 6), (8, 7), (8, 8)]

Tuesday, October 27, 2009

Go Blazers!

This is SO EXCITING! We are watching the Blazers' first game of the season and LOVING it. Love this team. Rian even made a special sign.

Tuesday, September 29, 2009

Ethan loves toy cars and trains. More than anything else right now. He's been known to carry one around ALL DAY. I've even put him to bed and he'll still be hanging onto one.






This Thomas the Train bedtime shirt is Ethan's favorite shirt. He LOVES it! He even carried that around one day. (I got this thing for free from a clothing donation place where my mom has been volunteering. Bonus!!)







He wore it to bed the other night and I take it off to change him the next day. He started throwing the biggest fit. As soon as he's dressed he takes off for the bedroom and comes back out carrying the Thomas shirt. He's still wailing and saying "Dis? Dis? Choo-choo?" It was pretty sad so we changed his shirt. He immediately stopped crying, laughed (all the while saying "choo-choo") and lifted his shirt up so that he could kiss Thomas.

After all this excitement I gave him a snack. I put a handful of goldfish crackers on the table and turned away to get his water. I come back to see him stuff all of them in his mouth. He didn't chew, just shoved them all in. He turns to look at me and immediately starts signing "more".

The boys and I have been going for walks a lot lately. We found this awesome path that is away from the road so Ethan can get out of the stroller and walk (try to run) with Rian and I. This is what happened during our walk on Sunday....

Ethan got out, Rian got in. Ethan then started pulling Rian in the stroller.....

Then changed his mind and found that pushing was much more efficient.
(He's a little nutty!)

Saturday, July 18, 2009

My Boat

I've never used craigslist to sell anything before, but I realized today that I need to get rid of my row boat. We are moving next weekend and we need to get rid of all this stuff. So I decided to put the boat on craigslist this week and if it wasn't gone in a week, I'd take it to the dump. It's been a good boat for me, but it's just not practical to live in an apartment with a boat (or so I hear).

So I took the ol' boat out of the garage, took a few pictures of it, and even found a couple pictures from years ago when I took it to the beach. I adjusted the photos to improve contrast, add a vignette, etc. I wrote a short little blurb about the boat and posted it all to craigslist.

The result? I received the first call 10 minutes after submitting the post. I ended up getting 8 calls (two after I took this screenshot) about the boat and having someone show up on my doorstep to haul it away in a truck. All of this happened within 45 minutes of making my first craigslist post.

Thanks, craigslist!

Thursday, July 9, 2009

Lunch



He came inside long enough to get his plate and then rushed back to his post.



When I grow up...

We have a couple guys building a Tuff Shed in our backyard right now. When they first started working Rian told me, "Hey mommy! I know it. I know what to be when I get big. A Tuff Shed guy! Yay! I know it." He's out there right now in his folding chair watching them work.




I just heard him yell, "Good job, guys!" Man, I love this kid.



Tuesday, June 16, 2009

8.2, baby!

I should be folding laundry. I have this awful habit of dumping clean, dry loads of laundry on our living room couch with every intention of folding it right away but doing something else instead. It sits there taking up our couch, sometimes for a couple days, until I realize that it won't fold itself or we run out of things to wear. Bah. I don't really mind doing laundry but today I'm staring at the mountain of it on the couch and feeling inspired to do this instead. Crazy....

Rian's sixth birthday was on the fourth. I can't believe we have a six year old! He's growing up so fast. He's such incredible, fun, caring boy. I love you, Rian!! 

Monday was my birthday. The boys and I spent a lazy day at home playing outside. We broke out the sidewalk chalk, ran in the sprinklers and played a ton of basketball. Eric came home from work early so that I could go for a run. I ran 8.2 miles and finished in an hour and twenty minutes! (Turned 28 so ran 8.2 miles.... maybe a little silly) It felt awesome. It's the farthest I've run since the half-marathon in October. (Ok, that's a little pathetic but I've been busy.... putting off laundry and stuff) I was totally expecting to be so sore the next day but it wasn't bad at all. 
 
Alright, I guess those clothes aren't going to fold themselves and if I don't do it before Ethan gets up from his nap I'm in trouble. 

Sunday, May 31, 2009

Hooray for us!

Today is our sixth anniversary! 


Eric, in honor of our special day I made something for you. (My first EVER!)
I love you so much.  





Happy Anniversary sweetie! 

Wednesday, April 29, 2009

Game 5

Blazers vs. Rockets. Game 5. Win or go home.

We got to the Rose Garden with plenty of time before they opened the doors. Lacey got her face painted as Rian and I picked out a Roy jersey for him. Ethan stayed home with Grandma.

As soon as they opened the doors, we headed down to the floor and watched some of the players warm up. When I got down to the floor, I found myself standing about 15 feet from Yao Ming. I was stunned. It turns out that he's pretty big. 7' 6". Go figure.

We watched him shoot for a while and then headed over to watch the Blazers warm up. Lacey and I got Martell Webster's attention a few times and got him to return our waves. Aldrige gave me five, and Blake signed one of those little Blazers signs that they hand out as you enter the arena. Rian sort of enjoyed the pre-game, but was mostly freaked out by the self-proclaimed Blazers Rally Monkey (a dude with a gorilla mask) that we happened to be standing next to.

I didn't really take any pictures during the game. I was too busy screaming my head off. The middle-aged man in front of me, on the other hand, was busy updating his facebook status on his iPhone during the game.

Game 6 is on Thursday!


Monday, April 13, 2009

Wanna Be a Baller

I had a basketball game on Friday. As I was warming up, Rian joined me on the court, as he does before and after all of my games. Usually he just rebounds for me and the other guys on the team, but lately he has been shooting more and more. When he shoots at a full-sized hoop, as we were on Friday, he shoots granny-style, holding the ball underhanded below his waist and scooping it up to the hoop in one motion. He just isn't strong enough to shoot overhanded at a hoop that high. Even when shooting underhanded, strength is the biggest problem. It is usually cause for celebration if the ball gets high enough to touch the net. He has never so much as hit the rim, much less made a shot. But he tries. Over and over and over.

So there we were on Friday. The game wouldn't start for about 15 minutes, and the gym wasn't very full yet. I was working on my touch around the basket (after missing about 5 shots from point-blank range last week... sigh) and Rian was hoisting granny shots up toward the rim. I was in between shots and happened to catch Rian lob another ball up toward the basket. Right away I could tell the trajectory of this shot was different than all of his others. It was going higher, faster. I turned and watched as it rose higher and higher toward the rim. The ball reached its apex just as it got above the rim, landing on the front of the rim. Time seemed to stand still as everyone watched, wondering if it would curl over the rim and into the basket, or fall back toward the floor and the wide-eyed boy that had thrown it so high. The whole thing took less than a second, but felt like it lasted much longer. The ball hesitated for a moment on the rim, then rolled forward and into the hoop.

Rian had made his first basket!

I let out an exclamation that got the attention of everyone in the gym, and made sure that everyone around knew the significance of what had just happened. Not only was this Rian's first basket, it came on a full-sized (10') hoop and with a full-sized ball. He was beaming as he received high-fives from my teammates and me, unsuccessfully trying not to smile.

So that's how Rian made his first shot.

Monday, March 23, 2009

Leprechaun Dash

I love running. LOVE it. And I'm so proud of my little boy who also gets excited about running. We both ran in races last Saturday. Rian ran in the Leprechaun Dash which is a one-mile race that his school participates in and I ran in the 5k after that. 


The Leprechaun Dash was super crowded and a little crazy. I was planning on running with Rian but he got really independent while stretching and wanted to run all by himself. Never again!! Scared me half to death because we couldn't find him right away after he crossed the finish line. He was with his teacher but I panicked not knowing where he was. It was a terrifying few minutes. 

Rian fell during the race. Poor guy. His puffy lip had dry blood on it and he had scrapes on his nose. At first I felt so awful and guilty for not being there when he fell but later he was telling us that he just got right back up and kept running. I'm so proud of him!  He was also excited because he passed some big kid during the race. Way to go Rian!  

My race was right after and I made it back to the starting line just in time. I thought I was starting towards the front of the pack but started towards the back. Yes, it was that crowded. A friend and I were planning on running together but I lost her. She ended up finishing 9th out of the women! Out of 244 women I'd say that's pretty good. Maybe it was a good thing we didn't run together....I wasn't even close but I did finish under 30 min. Yah! I'm so ready to do it again. 

Eric was so awesome and not only watched a slightly grumpy Ethan and then cared for Rian after his race but took some great pictures. Thank you sweetie! 


Runners from Rian's school















War wounds



Eeeek! I'm so proud!




Saturday, March 21, 2009

Shopping



I love my boys.



Thursday, March 19, 2009

Ethan


Ethan's walking! Ok, so this isn't new news but we haven't posted it yet so it's sort of new. He's been walking regularly for a little over a month now. He just stood up and walked across the room, gave my mom a hug, turned around, and came back. He hasn't stopped since. 






Ethan is obsessed with the dishwasher. He's big on seeing how much noise he can make by tossing dishes out or how loud I'll screech when he's chewing on the utensils. Yummy.
The other day he was "helping" me unload the dishwasher and the second I was done he was climbing in. He used all his strength and chucked the bottom drawer across the kitchen. He was so happy with himself and pretty dang cute. 









Wednesday, January 14, 2009

First Steps

Ethan is well on his way to becoming the fourth bipedal member of our family. Recently he has begun standing on his own without holding onto anything. Then last week, a few days before his 11-month birthday, he began taking one little step, which was always followed by immediately collapsing to the floor.

In any case, he is very excited and proud of himself for his new skill. The first time he stood on his own, we all started clapping and congratulating him. Since then, about every time he does it -- even if we aren't paying him any attention -- he begins beaming with a huge smile and making little exclamatory noises.

He thinks that he is pretty hot stuff.

My BFF

Rian and I were sitting on the couch yesterday talking, when I said something that made us both smile. I don't remember what it was, but it wasn't anything terribly special. The funny thing was how he responded.

"Daddy, you're my BFF!"

And then, only a second later, "That means you're my friend!"

I was shocked to hear this acronym come out of my 5-year-old's mouth. It's one of those acronyms that I missed out on because most of those Internet words hadn't evolved yet when I was a 14-year-old girl. I was so surprised to hear him say those three letters, I responded with three letters of my own:

"WTF?!"

Okay, so I didn't really say that, but I might as well have because that's what I was thinking.

(If you're lost, here are some definitions: BFF, WTF.)