Kibbee.ca
icon
Perfect answer
The question on Ask Slashdot: what kind of computer software and devices do you recommend for an 18 month old who is interested in looking at computer and TV screens.What follows is the perfect answer.

Please reconsider (Score:4, Insightful) by ascari (1400977) on Friday September 03, @07:48PM (#33471214) The best toy for a kid that age is a good sized cardboard box. Nothing else comes close when it comes to stimulating their imagination, curiosity and social development. If you for some reason are opposed to cardboard boxes: How about some real world open ended interactive toys like blocks, teddybears, a tricycle, a pail and a shovel, some toy cars or a... gasp... big red ball?
icon
you're doing it wrong (again)
Just finished reading this article on the CBC about how they created a rule (and promptly got rid of the rule) in a kids soccer league, such that any team that got ahead by more than 5 points would be declared the loser. No, I didn't mistype that. The team who was winning would be declared the loser because they were winning by too much. That's not the mercy rule. That's the opposite of the mercy rule. It's the bizarro mercy rule. I don't know where people come up with this stuff. Being a geek, and not very good at a lot of team sports, I've been on the losing end of sports quite a bit. But I don't think that something like this would have been much fun either. If the other team is ahead by so much, they might resort to playing keep-away, which is probably much worse than being actually beaten by a larger margin. Or they could let the other team score a goal. But how much satisfaction could you get from scoring when the other team lets you score. Time for some reductio ad absurdum and shoot some own goals. Great way to win the playoffs.
icon
You're doing it wrong
I saw this article about motorized doping in cycling, and I was quite surprised at the whole thing. As someone who bikes a lot, I don't see much use for something like this. For professionals trying to cheat, I don't see it working, because it makes quite a distinct noise. For older people or people who are trying to get into shape, I can see some advantage. However, even in these situations I think there's too much tendancy to rely on the motor. Even when I'm riding, I find I really have to keep focused and watch my speed, or I'll start slowing down. It's also quite amazing how having another cyclist beside you or up in front can really help to give you that motivation to just push a little harder. So anybody who is really interested in cycling should just tough it out for a bit. you'll get in shape much faster and enjoy the sport that much more. I guess anything thats gets more people out of cars and on to bikes can't be all that bad though.
icon
Blogging from mobile phone
I got an HTC Maple form Wind mobile. I've been thinking about switching providers for quite a while, and with all the new providers coming I was able to find a good deal that will save me quite a bit on my phone bills. Which is how I justified getting this phone. Typing on this phone is pretty sweet but still not good enogh for me to post a multi-paragraph blog from my phone. So that's it for now. Just waiting for big bang to come on now.
icon
Project Euler: Problem 11

What is the greatest product of four adjacent numbers in any direction (up, down, left, right, or diagonally) in the 20×20 grid?

[Full Question]



try:
    #open the file and read in the data
    #at the end, rowCount and colCount
    #will contain the number of rows and columns
    gridValues = []
    rowCount = 0
    
    data = open("Problem_00011.data.txt")
    line = data.readline()
   
    while line:
        values = line.split()
        colCount = 0
        #add a new row to the grid
        gridValues.append([])
        
        for value in values:
            #append the value to the current row
            gridValues[rowCount].append(int(value))
            colCount += 1
            
        rowCount += 1
        line = data.readline()
finally:
    data.close()
    
maxProduct = 0
#Number of adjacent values to check
numAdjacents = 4

i = 0
j = 0

while i < rowCount:
    
    j = 0
    while j < colCount:
        product = 0
        
        #check vertical product
        if i <= rowCount - numAdjacents:
            product = 1
            k = 0
            productFactors = [] 
            while k < numAdjacents:
                product *= gridValues[i + k][j]
                productFactors.append(gridValues[i + k][j])
                k += 1
        
            if product > maxProduct:
                maxProduct = product
                maxProductInfo = "The max product is found at %d,%d with the numbers %s in the vertical down direction." % (i,j,productFactors)
        
        #check horizontal product
        if j <= colCount - numAdjacents:
            product = 1
            k = 0
            productFactors = [] 
            while k < numAdjacents:
                product *= gridValues[i][j+k] 
                productFactors.append(gridValues[i][j+k])
                k += 1
        
            if product > maxProduct:
                maxProduct = product
                maxProductInfo = "The max product is found at %d,%d with the numbers %s in the horizontal right direction." % (i,j,productFactors)
        
        #check down-right diagonal
        if i <= rowCount - numAdjacents and j <= colCount - numAdjacents:
            product = 1
            k = 0
            productFactors = [] 
            while k < numAdjacents:
                product *= gridValues[i+k][j+k] 
                productFactors.append(gridValues[i+k][j+k])
                k += 1
        
            if product > maxProduct:
                maxProduct = product
                maxProductInfo = "The max product is found at %d,%d with the numbers %s in the down right diagonal direction." % (i,j,productFactors)
        
        #check down-left diagonal
        if i <= rowCount - numAdjacents and j >= numAdjacents - 1:
            product = 1
            k = 0
            productFactors = [] 
            while k < numAdjacents:
                product *= gridValues[i+k][j-k] 
                productFactors.append(gridValues[i+k][j-k])
                k += 1
        
            if product > maxProduct:
                maxProduct = product
                maxProductInfo = "The max product is found at %d,%d with the numbers %s in the down left diagonal direction." % (i,j,productFactors) 
                
        j += 1
    i += 1


print "The largest product of %d adjacent numbers is %d" % (numAdjacents,maxProduct)
print maxProductInfo

[Download Code]

[Download Data File]

I did a lot of extra stuff in this code to ensure that it solved the more general problem. Mainly that it could read any grid of numbers regardless of the size, assuming the format was the the same, and also allow to find the sum of any number of adjacent numbers within the grid. I think that in the end, this actually made the code a little shorter, and made the code a little easier to read in some ways. Also worth pointing out that you don't need to check all directions, just vertical going down from the current position, horizontal going right, diagonal going down to the right, and diagonal going down to the left. The other products you can calculate, such as vertical going up, and already covered but the 4 necessary ones once you have checked all the values. I also added extra code to record where the value was found, and in which direction, as well as the values being evaluated to find the product.