Friday, December 5, 2008

Plog Bost

Ohk.. last week of classes jst got over.. i scrwed sum stuff up reeli bad... but i guess im mostli ok
i hav forgotten wot sleep is.. my room has mountain dew nd energry drink cans evrywer.. evrything is like dumpd on the floor everywer... but imstillalive .. tobehonest im in a daze right now.. nt sure wot i am writing and why i am doing this...whoami???... in the past 48 hours.. i hav redesigned processor microcode, given the most anticlimatic 123 exam ever.. rote a hilarious business plan fr techcomm (expected revenue: 100 mil in 5 yrs w00t), ritten sum huuge ass 212 concurrency ml program wich did nt evn compile, riten a 'Mini Unix Shell' ..lol. ritten my last japanese essay and painfulli learnt the stack handling conventions for ps18240...
problem is that beyond 3am .. my body shifts to allnighter mode.. nd because of the large number of starbucks doubleshots wich abhinav askd me to buy fr him wich mysteriousli dissapeared frm my fridge...i reeli cant sleep.. so im going to blog!!! ...... lucky u! :P
ok wen i made this thing.. i had all these grand plans nd ambitions abt riting a post everyweek.. nd getting millions of readers on rss nd making a gazellion dollars through google ads nd changing the world. bigtime.. but i guess thts nt the case......uptill now
one of the things i wantd to do with this blog is try nd explain stuff i find kinda kool..nd see how ppl react. .......u see..... im reeli reeli bad at explaining stuff... but i wanna change tht.. also i find a bunch of reeli kool computer stuff reeli kool.. because of wich a bunch of very weird ppl consider me to be very weird.. so lemme change tht stuff nd kill two stones with one bird nd try to rite a geeky post.. heregoes..
RECURSION
Recursion is a reeli kool idea in computer science.. its pretty simple to understand but the implications of it.. are reeli kool and deep..
Recursion is essentially the art of solving problems by just rephrasing the problem in terms of itself..
It might seem like a very lazy way to go about doing things... but it can often be the best
First off we start of with a stupid math example
Suppose u wanna find the factorial of a number.. wich basically means u want the product of all the numbers starting from 1 that are less than n
so factorial of 2 is 1 x 2 = 2 and factorial of 7 is 1 x 2 x 3 x 4 x 5 x 6 x 7 = 5040
u can write a conventional program to do this which wud look sumthing like this

  Let y initially represent the number 1
  Let z initially be 1 but then cycle through the values [2,3,4,5,6...x]
    For every cycle of z
      Let y now represent the number that is the product of the old value of y with the value of z
  At the end of all the cycles, we know that the Factorial of x is the value of y


which in an actual code, looks like

def fac(x):
  y=1
  for z in range(1,x+1):
    y = y * z
  return y


This is nice cos we can see exactly what is doing.. it is multiplying y with every number between 1 to x to give us what we want

But its a lot of code for a pretty simple problem...
Can we do any better???
.......Turns out we can, if we try to be lazy (in cs, that can be a good thing)
Whats the factorial of 1?.. well its 1
Whats the factorial of 2?.. its the product of 2 and 1 = 2
Whats the factorial of 3?.. its the product of 3,2 and 1 = 6.. but wait a sec.. To calculated the factorial of 3 i had to find 3 x 2 x 1 wich is nothing but 3 x factorial of 2
Similarly for 4.. factorial of 4 is nothing but 4 x factorial of 3
Hey thats kinda nice.. with this in mind, I can make a cooler factorial function --

Factorial for a number x:
  If x is 1 then the Factorial of x is also 1
  Otherwise the Factorial of x is the product of x and the Factorial of (x-1)


in code
def fac(x):
  if x==1: return 1
  return x * fac(x-1)

Both convey exactly the same information, and for all good input give identical output.. yet the 2nd one is a lot easier to read and type in and reason about.
The 2nd one recognizes the fact that any instance of the problem can be decomposed down to a simpler version of that problem until we reach the end of the line - the base case = 1


Now for the cooler non-math example...
Have u played chess?? ... If yes, u probably realize the fact that its not exactly easy to figure out what your next move should be.. in fact, in many cases, u mite have played some arbitrary move with no specific reason for choosing it, just hoping that it works out..
Making a computer play random moves is also easy.. but making a chess-playing program is a pretty complicated thing to do.. This was researched a lot in many US unis many years before I decided to get born and some people even won an award for it...

Suppose you have function called 'getBestMove' which when given a chess board will tell you what is the best move the player playing next can make and do this by giving it a score :: a number indicating how awesome that move is
def getBestMove(chessBoard):
  does wotever it needs to do find best move
  print bestMove
  return sumNumberIndicatingHowAwsumThatMoveIs

It was easy uptill now.. but now that we need to replace the 2nd line with actual code, we r in big trouble..
How the hell can we figure out the best move for this player???
One way to think about it, is to think in our enemy's shoes..
In real life, the best way to fight competition can be
[[will finish riting this l8r]]



Example.. suppose you had a computer that could only add or subtract 1 to any number and u wanted to make a system that could add any arbitrary numbers a and b
you could do sumthing like

def add(a,b):
if a=0:
return b # because 0+b is just b for any b
else:
return 1+( add(a-1, b) )

Saturday, September 27, 2008

God of War and a Delicious Orange

languages r soo kool
learning one opens your eyes up in so many ways
you begin to see connections between things which previously seemed seemingly random
for example, as i learn more of jap... all the characters in flame of recca seem to make more sense
its kinda blunt... but all their names point to their power of their Madōgu
for example, thers this evvil character called mokuren who possessed the elemental device for controlling trees...
... while learning the days of the week.. i came across thursdae i.e. 木曜日 (もくよび) i.e. mokuyobi.. and since that sounded kinda familiar.. i researched it up and learnt tht it literalli stood for wood day..
.... so moku literalli means wood... ohhh.. umm.. tht makes sense.. i guess a jap person watching the anime would hav noen mokuren's power instantly
similarly wednesday i.e. 水曜日 (すいよび) i.e. suiyobi meant water day.. which told me why mikagami tokiya's ICE sword was called ensui !

Consider the word tuesday in a couple of different languages:
EnglishTuesdayTyuz day
FrenchMardiMaar thee
HindiमंगलवारMangal vaara
Japanese火曜日 (かよび)Kaayobee

These seem like a very random set of words.
Yet…
  • Tuesday derives from Tyrsday.. which, not surprisingly, means Day of Tyr who was the Norse God of War
  • Mardi comes from the latin ‘dies Martis’ which meant Day of Mars, the Roman God of war, who, in his spare time, pretends to be a planet!!
  • मंगलवार means Day of Mangal.. which happens to be the Sanskrit word for the planet Mars.
  • 火曜日 means..ummm.. lets break the kanji down

    Kanji
    Meaning
    kaFire (which is RED!!)
    yoluminary; shining body
    biSun (whose movement defines a DAY)

    Ohkae so 火曜日 means day attributed to the celestial body which reminds us of fire.. i.e. is red…. Oh wait .. that’s Mars..
    So 火曜日 also means Mars’ Day.
Umm.. so when exactly did the Jap and Norse coordinate on international day-naming standards???
Apparently the whole 7-day week with names named of Gods was invented in Egypt/Mesopotamia and from there went on to Greece and india… and in the 8th century some Buddhist monk took it from India and brought it to Jap. (Oh kool!! An Indian connection!!)
And all those made me wonder what Recca (the main guy in Flame of Recca, who controls the 9 flame dragons) means.. Hmmm.. Recca … Ree Ka…. ohwaitiknowthatalreadi!!!
And Quentin Tarantino has a bad sense of humor. I thought starting the movie with a Klingon proverb was bad enough.. but no.. he goes on to name the dangerous female assassin and queen of the Japanese yakuza (underworld) – Oren ishii.
Ishii is one of the first jap words I learnt.. it means delicious
Oren.. I jst looked this up… It means Orange
WTF!! :@:@:@:@ He names the most dangerous woman in Tokyo- “Delicious Orange”!!
Grr.. still love his movies.. especially all the hattori hanzo scenes…



I would really like to recreate all three “Man from Okinawa” scenes..with me getting the sword in the end.. cos I think they r reeli kool..
Anyways.. I better start my 212 hw now.. so sayounara!!

Tuesday, September 9, 2008

konnichiwa world

Hullo..
feast your eyes on the most historic blog post in the world!
or atleast it will be, once it is properly sequeled out with more posts about stuff you might want to know, stuff I might want you to know, or stuff that is just soo random, that you never knew that you wanted to know but realised u did once u got to know it frm yours truly
ok enuf bs.. lets get bak to business
kougan anki.. i luv the name.. its a very kool weapon from my favourite anime that is sumthing like a rubik's cube.. it can be disintegrated and rebuilt to one of several different forms but this requires gr8 skill nd zen-ness... its more dangerous for the one wielding if it if they dont noe wot they r doing.. but given the right master who is willing to work with it rather than on it.. it can defeat weapons nd opponents far more terrifying nd dangerous than itself..
more about it later....
i was originalli trying to name this blog KungFoo.. which wud hav very effectively conveyed my fascination with warrior pandas and programming random stuff... but some1 had taken tht name
sum1 had also taken adi, adi9, adi92, aditya92, aditya.. nd every possible permutation that might interest me.. grrrrr.. tell me if u come up with a better name for my blog..
about me.. well.. i luv pissing ppl off.. forcing them to listen to my humourous humour.. programming halting-set oracles in my sleep, solving P=NP using 3rd grade algebra (N=1.. that was it!!!), creating virtual worlds nd being fascinated by nething thts japanese
so tht brings us to the end of the beginning.. hopefulli i will continue writing to this blog thereby making sure tht this is also not the beginning of the end of my blog
sayounara!!