I Think

god

Sometime back I read something along these lines…

“god cannot be omniscient and omnipotent at the same time, for if he is omniscient he knows how everything will pan out in the future, rendering him powerless over the future. ”

I just cant remember where I read this and I have been rattling my brain for the last couple of hours, trying to figure out where I read this. Help me god! 😀

Standard
I Think

Handshake

I never get the right handshake. Half the time I get the i-want-to-break-your-fingers handshake, they think they are being jolly good fellas by crushing my hand, it is supposed to be good natured, but fuck you assholes, it is painful. Its either that or a limp, lifeless handshake. Its your hand dammit, pump some blood into it, heres a tip – think there is a naked woman in the room, that should do it. There is nothing more annoying that trying to shake hands with a person who just offers his finger edges, wait a minute, there is, its the guy who leaves my outstretched hand hanging in midair while his pithecanthropus brain processes what to do with it.

Standard
I Think

Problem 18

My home pc has been getting a lot of makeover lately. First it was the os update, and yesterday I replaced my eight year old CRT monitor with a sleek 20″ led monitor. Also replaced the dusty keyboard with a new one. The pc looked so nice that I sat and did some coding for fun after a long time on this machine. Went to project euler and started solving the problems, in python. The first real test came in problem 18*

By starting at the top of the triangle below and
moving to adjacent numbers on the row below,
the maximum total from top to bottom is 23.

   3
  7 4
 2 4 6
8 5 9 3

That is, 3 + 7 + 4 + 9 = 23.

Find the maximum total from top to bottom of the triangle below:

              75
             95 64
            17 47 82
           18 35 87 10
          20 04 82 47 65
         19 01 23 75 03 34
        88 02 77 73 07 63 67
       99 65 04 28 06 16 70 92
      41 41 26 56 83 40 80 70 33
     41 48 72 33 47 32 37 16 94 29
    53 71 44 65 25 43 91 52 97 51 14
   70 11 33 28 77 73 17 78 39 68 17 57
  91 71 52 38 17 14 91 43 58 50 27 29 48
 63 66 04 68 89 53 67 30 73 16 69 87 40 31
04 62 98 27 23 09 70 98 73 93 38 53 60 04 23

The question also had a helpful tip warning against using brute force. After a few minutes of thought, the algorithm became clear. Given a point in the triangle (that is not on either end of the row), there are two ways of reaching it of which only one has the max sum, so I only need to maintain the maximum sum leading up to the point and discard the other. Here is the code.

#!/usr/bin/python
def problem18():
    a = [
        [75,],
        [95, 64,],
        [17, 47, 82,],
        [18, 35, 87, 10,],
        [20, 4, 82, 47, 65,],
        [19, 1, 23, 75, 3, 34,],
        [88, 2, 77, 73, 7, 63, 67,],
        [99, 65, 4, 28, 6, 16, 70, 92,],
        [41, 41, 26, 56, 83, 40, 80, 70, 33,],
        [41, 48, 72, 33, 47, 32, 37, 16, 94, 29,],
        [53, 71, 44, 65, 25, 43, 91, 52, 97, 51, 14,],
        [70, 11, 33, 28, 77, 73, 17, 78, 39, 68, 17, 57,],
        [91, 71, 52, 38, 17, 14, 91, 43, 58, 50, 27, 29, 48,],
        [63, 66, 4, 68, 89, 53, 67, 30, 73, 16, 69, 87, 40, 31,],
        [4, 62, 98, 27, 23, 9, 70, 98, 73, 93, 38, 53, 60, 4, 23,]
        ]

    def flatten(row1, row2):
        flat = []
        firstrowlen = len(row1)
        secondrowlen = len(row2)
        for i, val in enumerate(row2):
            if i == 0:
                flat.append(val + row1[0])
            elif i == secondrowlen - 1 :
                flat.append(val + row1[firstrowlen - 1])
            else:
                flat.append(max(val + row1[i-1], (val + row1[i])))
        return flat

    finalflat = []
    numrows = len(a)
    for rownum, row in enumerate(a):
        if rownum == 0:
            finalflat = row
        if rownum + 1 <= numrows-1:
            finalflat = flatten(finalflat, a[rownum + 1])

    print reduce(max, finalflat)

if __name__ =="__main__":
    problem18()

*That was because I chose python, using python almost feels like cheating, for example to compute 2 power 1000 was tricky in C, but in python it is as simple as 2**1000.

Standard
I Think

There and back again*

Me, esskay and pradeep(esskay’s cousin) went on a drive this past sunday, to Vedanthangal and then to Tanjavur. It was a great day to drive, the weather was just perfect. The sun lay nicely snuggled beneath a blanket of clouds for most part of the day, after all it was sunday for her too. There was a hint of drizzle that played around with whatever sunlight that made it past the clouds. The wind put up a valiant effort at balding us every time we lowered our windows. The sky kept on churning taffy clouds for our delight, which together with the green of the countryside and the blue above made for a nice windows-wallpapery spectacle. The evening was even better, at one point we had shapely violet-tinted clouds on our left, dark rain clouds on our right and a cloudless patch in front of us which burned orange under the last rays from the dying sun. Everybody knows the fun thing about clouds, keep looking at them and bam! out of nowhere a shape leaps out at you. I did the same, saw a fiery pomeranian chasing a hurrying dwarf, funny that. I had a feeling that nature was bending over backwards to please me, i know, sounds egotistical, i dont care, I thoroughly enjoyed it.

The trip was fun for another reason. I consider myself a farmer, i view the world in terms of safe decisions, low risks, erring on the side of caution, avoiding epic failures, etc, you get the point. Pradeep is at the other end, a hunter, living on the edge, prepared to take huge risks, going for epic wins, etc. At work I am surrounded by friends who are also farmers, birds of the same feather and all that. Over time I have gone through a bit of circlejerking with the same folks, reinforcing the same set of views, and as a consequence, I have shut down new lines of thought. Naturally I found listening to his perspective refreshingly new, despite not hearing anything new. It made me wonder how it would feel to be a hunter for a change. Of course, there is nothing right or wrong about being a farmer or a hunter, this is not about which is good and bad. And people are neither completely this or that, esskay, for example, is half here and half there, it is just an amorphous dichotomy. But talking to him sort of kindled my personal fantasy, about following the footsteps of Samwise Gamgee, setting out to see the elves, walking into mordor, coming back home to tell the tale and living out the remainder in the Shire. I am still in love with the Shire, not prepared for the journey, but some day, sooner or later, it is going to happen.

* I am reading LOTR again, this time all too slowly, savouring every word. 🙂

Standard
I Think

Anime

There are some things you dislike because you have seen the worst of them, and there are some things you dislike because you havent seen the best of them. Until last week anime was in the latter catergory. But then I sat through a couple of movies – Princess Mononoke and Spirited Away and well, I am sort of a anime fan now.
Princess Mononoke is what Avatar tried to be and failed. Unlike Avatar, the story had a number of stake holders, forest gods trying to protect the forest and yet not coming together to fight the humans who werent a monolithic force but a team of loose alliances waiting for the opportune moment to stab others in the back. And nature, the forest spirit, dint take any sides when threatened, but when things got out of control it went on a rampage destroying everything that walked across its path, everything. The movie had a predictable ‘all is well’ ending though, for once I was ok with such an ending for the journey towards it was fascinating enough to make up for it.
Spirited Away was more of a regular kidsy animation movie. It was about a eight-nine year old girl who gets trapped in a spirit world, falls in love with a river, frees him and her parents from the clutches of the witch and returns home. Very likable.
Both movies come from Studio Ghibli, who apparently are very good at anime. Have a couple more of their flicks queued up for the weekend My neighbour totoro and Howl’s moving castle.

Between I got my precious back today morning and I celebrated the reunion by doodling Chihiro, from Spirited Away and No-Face, the friendly spirit that keeps offering gold to her.

Standard