Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Wednesday, December 21, 2011

Randomness_001

Coins...Fer a Change...!! :)


Was feeling 'lost'...and then decided to pay ettention to my thoughts....

I was thinking randomly...a lot about random numbers... 
(Hmmmm....i've not yet stopped...nor will I ever...hahaha!)

You can't imagine the MAGICAL things that lurk behind a seemingly RANDOM Universe....!

As one of my thoughts encouraged me to do, I took out a coin...& flipped it...
(yeah...Cricket -match coin-TOSS! :P )...

And as it turns out...fer a few tosses, it appeared to be biased towards HEADS or TAILS...
[Out of 10 chances...7 will be heads, or even 8 or 9 will be tails...!]

But then, I imagined....
WHAT if...what if I extend this tossing OVER & OVER & OVER egain....& egain..!?!?

In the short-term...we may feel the Universe/God is biased...but over a Loooong term...there is JUSTICE..n EQUALITY (of Probability..)..?? :P

So armed with this thought...and tonnes of emptiness....i sat blinking before my monitor....waiting....fer the magic to happen...

And happen it did...!!

Before long, between my work....I had whipped up a couple of lines to show me graphically the results of 1,000 coin tosses...to help me 'see'...

And the results...are (t)here fer YOU to see...! :)
  • n(heads)  = 504 
  • n(tails)    = 496
{ Click on the picture below !} 












    Moral: EVEN a state of ORDER has CHAOS & Randomness underneath...! :) 
    It is just amazing HOW a seemingly random set of events...can aggregate and 'appear' to be 'orderly' to our Mind/Brain...! 


    Is it not pa..? :)


    Phew..! :)

    Love & Best Wishes,
    The boy in "rags"

    Tuesday, March 8, 2011

    Thanks to Mommy :)

    A cup of Tea,an idea,and...voila! :)

    Yesterday…as I was getting ready to go home early, I got stuck up with some office-work, & ended up having to wait for almost an hour for a bus in which I could jostle & finally reach home…

    Not surprisingly, mom was peeved at me for not being home “on-time” ;she waits fer me everyday, just to have a tea with me...!
    {My Pappa does not drink tea or coffee. And that leaves only me fer her company…!}

    But soon, seeing how tired I was, her anger melted & turned to affection, and before I knew it, I was sitting before the TV with a steaming cup-o’tea, dunking & savouring bread slices, regardless of the fact that it was almost dinner time for the rest of the world.. :)

    And then, I had dinner with Pappa & Mommy, but during dinner, there was talk about the world, & various countries, etc. And Mommy became especially curious to know if we could easily get every country’s name, along with its capital-city. 
    {
    She seemed impressed at first when I told her the place where my dear friend Siva Prasanna is currently staying, called Dar Es Salaam, is the capital of Tanzania in Africa. She then suspiciously asked if I knew all the countries & capitals of the world, or if I was just bluffing. Hahaha. Nobody seems to believe me-moron..? :(
    }

    That’s it...! :-)

    The unexpected cup of tea, and my Mommy’s curiosity had their effect…!

    I quickly ran into my room, to my lappie…& came up with a 2-line (yes ! Just 2 lines!!) code which created this magical image… J

    It has a list of 237 countries, their capital cities & their flags & even their shapes respectively...!

    {Click on it..., better save it & SCROLL & view with a program like Google's Picasa..!! J}


    Tried..??
    I know...the image doesn't even appear at its normal size right..? 
    Thanks a ton to a few of my friends fer pointing it right away to me-moron. 
    "Only your real friends tell you when your face is dirty.", as my one of my oft-quoted saying (a Sicilian proverb) goes.:-) 


    Here's the LINK fer the image to download & view properly..! :)

    The strange thing is, I took hardly 5 minutes to cleverly set up those 2 lines…but took an additional 20 minutes to get my CRAZY COLORs, FONTS, etc…! J


    Some interesting points to note:
    1. The font I wanted ( & managed to get!) is simply country number 138 J
    2. The map of Egypt (number 60) has a near perfect right angle…looks like a right-angled triangle… J
    3. The flag of Isle of Man (number 100) is so interesting, and unusual.

    This then, is THANKS to YOU Mommy...!! :-)

    Love & Best Wishes,

    The boy in 'rags'
    Planet Earth
    ----------------------------
    "The best academy-a mother's knee."
    :- James Russell Lowell
    ----------------------------

    Wednesday, January 12, 2011

    Search for Snakes...! :)

    Hi pa,


    Thanks to my friends Hemanth, Gundeep, Anand & Amit, me got to know recently that 2011, apart from being a prime, is also the sum of 11 consecutive primes..!


    Here's the problem formulation I managed to somehow type...which i have tried to make as generic as possible...
    (except for the operation being Summation...!! It could be Product, or anything you can think of ! Feel Free to play around, explore & note down any beautiful patterns u may stumble upon...! :) )


    Please click on the below picture to read the text better..it's just my silly analogies..but hope it's clear enough..?! :)












    I decided to scribble some code to do this...& I discussed with many of my dear friends like Pavan, Prasidhya, et al., about my intuition as to how to go about it...I am Always indebted to them, fer NEVER EVER getting irritated with me-moron, but always smilingly listening to what I had to say ( or scribble & doodle, as always..! :) )...!


    But somehow, i could never bring myself to actually write any piece of code---i was in that 'stuck' state...of utter emptiness, like always..! :)


    I would struggle to articulate & explain one approach to my dears, & my MIND would soon fill up with counter-arguments for it, & soo much noise that I soon decided to shut-up & stop disturbing them with my stupid blabberings, and instead, leave the problem...(to simmer...! :))...


    Post-Lunch....alone....and a hunch...!! ;) :)


    And one fine day...(not so fine...since i was all lonely fer lunch...!), I was walking back from lunch, looking up @ the lovely clouds floating in the azure skies....& ...YES..! :)


    i suddenly felt the ideas rushing into me...!! :)


    i hurried up to my floor...took a cup of Tea...& feverishly typed a baby Java program...(not meant to be a model of coding..no ways..but, instead, just a transliteration of what i 'heard/felt' ...should/can be done...to discover this LONG, coiled, camouflaged SNAKE...nestled in the infinite ROPE of Numbers...!!


    And except for an initial "ArrayIndexOfOutOfBoundsException" once, my baby program ran without any hassles...& showed me exactly what i wanted to see !  Phew !! :)


    Have decided to share the complete code fer YOU, if you are interested, so that you can improve/modify it & do your own experiments...! :)


    Please visit the below link to see the source-code (scantily/crazily documented...on the 'spur of the moment' :) )...u can hv a good laugh @ HOW it is JUST a plain translation of my childish idea...! :)
    http://pastie.org/private/9aeq40yg5d6deflhxddata


    Click on the below image to see a sample run... :)






    Hope you too begin 'seeing' some snakes & worms & patterns in numbers then...!


    Take care...and keep L(i/o)ving...!! :-O :)



    Lots of Love & Best wishes,













    The moron in 'rags'
    Planet Earth
    =============================
    One of my all-time inspiring quotes...(yet again..!!)
    Computers are useless; they can ONLY give you answers.
    :- Pablo Picasso
    (Hope the lit'l child below makes you smile..?? Courtesy  of dear Mr.Charles M. Schulz (Peanuts) :) My state was/is JUSST Like this...Hmmm...!!)












    =============================

    Sunday, October 17, 2010

    Silent Spectator..







    Well, was resting...watched the Dasara proceedings on TV...while having Mom-made stuff at home...

    Now, mommy got some leaves of the "bunny" tree--and the 4 of us @ home exchanged "GOLD"---that's how the leaves are supposed to be treated/referred

    It wud've been great fun if i was in my village...with tiny gals also draped in Sarees ( & if even younger & smaller...a towel of their farmer-papa's acting as one..! ;-) Aww... )...shyly coming over to exchange these leaves..! :)

    I fer one...was smiling HOW it took 6 exchanges among we 4...since it is 4-C-2...LOL..! :)
    [Mom did say---"HEY Mr..where are you LOST..?? What u worried bout..?? Huh..?" ]

    --------------

    Oh My! "Blind" Math against "Common-sense"..! :P

    Me went out n told Mom & she vehemently said it takes only 4 exchanges...
    Me explained to her animated-ly & then ran to my room & produced the following programmatically (fer my satisfaction..! ):

    {{Pappa, Mommy}, {Pappa, Sis}, {Pappa, meMoron}, 
    {Mommy, Sis}, {Mommy, meMoron}, {Sis, meMoron}}

    That is, I created a list of ALL 4 of us...& then generated ALL Permutations of exactly 2 elements, & removed "duplicates"...thanks to the power & compact-ness of Functional Programming...! :)

    Phew !! I am a bit dizzy & she got me doubting fer a moment..!

    Scepticism !! 

    And i gladly welcome it..! :)
    {That's why, I am sometimes able to convince my Mommy-dear about the futility & stupidity of some of the things we do...! She is quite  receptive...to scepticism...which is the burden (& SEED !) of Science..! :) }

    Lots of Love & ....nothing... :)
    The moron in rags














    ---------------------------------------------
    Fer a dose of smile & ...here's frem the genius of Jim Watterson's Garfield.. :) 
    Click on it & Smile...Pleeeeeze...??? Thank YOU..! Now, stay THAT way..! :)
    ---------------------------------------------


    Monday, April 19, 2010

    ALL the B(e)ST...!!! ;-)

    Hi pa!

    This weekend, my dear friend & mentor Manju Hanasi, who's another constant source of inspiration & ideas, shared an interesting problem with me.

    We thought we should share it with YOU too, so that we can get more & more interesting solutions for it.

    The problem, he said, is to come up with a very efficient & fast piece of code to determine if a given DATE is in BST(British Summer Time).

    Definition: For simplicity, we can assume that BST is a period between the LAST Sunday of March and the LAST Sunday of October.

    One very helpful thing: It's ok if the year is in the range say, 1900 till say, 2100.

    And the catch, is to do it without relying on any language-dependent API's or libraries 
    ( 
    E.g., we have utility classes/packages called TimeZone which takes care of handling such stuff in
    and so on... 
    )

    But what we need is to know if it is possible to write a simple function with the following kind of signature:

    boolean isInBST(Date date) ;

    or simpler...

    boolean isInBST(int day, int month, int year);

    The function has to be as fast & efficient as possible.

    So, WHAT are YOU Waiting for....??

    Please try n send in your versions of this function in ANY programming language of your choice...!!!
    Believe me...it'll be FUN..!! :)

    Do NOT be biased or daunted by ANYthing..ANY doubts...JUST Let GO...& Let me know..! :)

    It's ok even if you share your idea...pseudo-code...comments, suggestions, anything...! :)

    So...me WAITING...fer your answer(s)...k ??? :)

    Come ON..!!
    Jusst give it a try...!! :)

    It's truly a beautiful( & such a Different!) experience to ASK ( & be ASKED) Questions to WHICH the ASKER too does NOT know "the" ANSWER(s)..!! :)

    That, makes it into an exchange of IDEAs...rather than of Ignorance masking as Knowledge..! :)

    Hmmmmmm..! :)

    Take care then, & Keep L(i/o)ving...! :)

    Love & Cheers..!
    The boy in rags






    Planet E-art-h
    --------------------
    Computers are useless; they can only give you answers.
    Pablo Picasso
    --------------------