Thursday, September 25, 2008

Setting an example - "Hello World" , "99 bottles of beer" is here.

I've been terribly lazy , I've not posted anything o'er here in a long time and i badly want to write some crap :P , so.. here goes

"Hello World" , "99 bottles of beer" is here.

People who have been trained or have been training others in computer languages would definitely have come across this very famous sentence in the study material they use - the "Hello World" . A very simple sentence , but unmistakably the most popular example that is used to introduce people to a computer language.
As you read this... there might be several hundreds of budding programmers out there , typing this line and marking their foray into the world of programming. But how popular is this?

If the helloworld site is to be believed , there are 409 computer language versions ( actual code for all those is available on the site) of the most popular example program. Now , that is almost all the computer languages man has ever created.

A couple of them caught my attention :

1) the longest possible coding for a simple , single lined output

The RedCode Version (alias- the redneck version):

; Should work with any MARS >= ICWS-86
; with 128x64 gfx core
Start MOV 0,2455
MOV 0,2458
MOV 0,2459
MOV 0,2459
MOV 0,2459
MOV 0,2459
MOV 0,2459
MOV 0,2460
MOV 0,2465
MOV 0,2471
MOV 0,2471
MOV 0,2471
MOV 0,2479
MOV 0,2482
MOV 0,2484
MOV 0,2484
MOV 0,2484
MOV 0,2486
MOV 0,2486
MOV 0,2486
MOV 0,2486
MOV 0,2488
MOV 0,2493
MOV 0,2493
MOV 0,2493
MOV 0,2493
MOV 0,2497
MOV 0,2556
MOV 0,2559
MOV 0,2560
MOV 0,2565
MOV 0,2570
MOV 0,2575
MOV 0,2578
MOV 0,2585
MOV 0,2588
MOV 0,2589
MOV 0,2592
MOV 0,2593
MOV 0,2596
MOV 0,2597
MOV 0,2603
MOV 0,2605
MOV 0,2608
MOV 0,2667
MOV 0,2670
MOV 0,2671
MOV 0,2676
MOV 0,2681
MOV 0,2686
MOV 0,2689
MOV 0,2696
MOV 0,2699
MOV 0,2700
MOV 0,2703
MOV 0,2704
MOV 0,2707
MOV 0,2708
MOV 0,2714
MOV 0,2716
MOV 0,2719
MOV 0,2778
MOV 0,2778
MOV 0,2778
MOV 0,2778
MOV 0,2778
MOV 0,2779
MOV 0,2779
MOV 0,2779
MOV 0,2782
MOV 0,2787
MOV 0,2792
MOV 0,2795
MOV 0,2802
MOV 0,2805
MOV 0,2806
MOV 0,2809
MOV 0,2810
MOV 0,2810
MOV 0,2810
MOV 0,2810
MOV 0,2812
MOV 0,2818
MOV 0,2820
MOV 0,2823
MOV 0,2882
MOV 0,2885
MOV 0,2886
MOV 0,2891
MOV 0,2896
MOV 0,2901
MOV 0,2904
MOV 0,2911
MOV 0,2912
MOV 0,2913
MOV 0,2914
MOV 0,2917
MOV 0,2918
MOV 0,2919
MOV 0,2922
MOV 0,2928
MOV 0,2930
MOV 0,2933
MOV 0,2992
MOV 0,2995
MOV 0,2996
MOV 0,3001
MOV 0,3006
MOV 0,3011
MOV 0,3014
MOV 0,3021
MOV 0,3022
MOV 0,3023
MOV 0,3024
MOV 0,3027
MOV 0,3028
MOV 0,3030
MOV 0,3032
MOV 0,3038
MOV 0,3040
MOV 0,3103
MOV 0,3106
MOV 0,3107
MOV 0,3107
MOV 0,3107
MOV 0,3107
MOV 0,3107
MOV 0,3108
MOV 0,3108
MOV 0,3108
MOV 0,3108
MOV 0,3108
MOV 0,3109
MOV 0,3109
MOV 0,3109
MOV 0,3109
MOV 0,3109
MOV 0,3111
MOV 0,3111
MOV 0,3111
MOV 0,3120
MOV 0,3121
MOV 0,3124
MOV 0,3124
MOV 0,3124
MOV 0,3126
MOV 0,3129
MOV 0,3130
MOV 0,3130
MOV 0,3130
MOV 0,3130
MOV 0,3130
MOV 0,3131
MOV 0,3131
MOV 0,3131
MOV 0,3131
MOV 0,3135
JMP 0

(Imagine having to program with this assembly language . Guaranteed to give any sane geek the creeps. )

And 2) The shortest code :

The APL version (alias - the K.I.S.S version. All hail the APL) :

'Hello, world!'

//thats it folks , as simple as that!!

However , there seems to be another example .. which is a bit advanced than the "hello world". Its called "99 bottles of beer".

It happens to be a song that kids sing .

WTF?.... why in the world didnt i know about that song?

What might be the reasons I missed the song?

These might have been the reactions when the proposition to include the song in our computer syllabus at school had come up.

"BEER SONG FOR KIDS ?? :O Kids shouldnt sing about beer , definitely not my kid.. that is blasphemy, thats anti-social , thats totally unacceptable behavior. " - my parents.

"blah blah blah blah .. BEER is evil. It makes you the satan's slave and also blah blah blah" - my neighbor.

"Singing/Coding the song makes you feel like you want to drink beer. This is a scientific conclusion" - NCERT / CBSE / TN State Board.

Anyway .. I doubt whether that song wouldnt have made it to our text books. Here is the lyrics :

"99 bottles of beer on the wall, 99 bottles of beer.
Take one down and pass it around, 98 bottles of beer on the wall.

98 bottles of beer on the wall, 98 bottles of beer.
Take one down and pass it around, 97 bottles of beer on the wall.

97 bottles of beer on the wall, 97 bottles of beer.
Take one down and pass it around, 96 bottles of beer on the wall.

.
.
.

1 bottle of beer on the wall, 1 bottle of beer.
Take one down and pass it around, no more bottles of beer on the wall.

No more bottles of beer on the wall, no more bottles of beer.
Go to the store and buy some more, 99 bottles of beer on the wall."

Now , why is this an advanced example? This example can be used to demonstrate the printing statement syntax, a loop control , a branching statement and the ill-effects of beer on your heads. Psychotic geeks-in-the-making can be identified if he/she makes the above output a continuous , infinite loop , virtually implying infinite beer .

Apparently , this example has more takers than the lame "Hello World". According to 99 bottles of beer dot net there are 1229 representations of the beer song in different languages and their variants.

My 4 line C program :P

main()
{
int i;
for (i=99;i>=2;printf("%d bottles of beer on the wall, %d bottles of beer.\n Take one down and pass it around,%d bottles of beer on the wall.\n",i,i,i-1),i--);
printf("1 bottle of beer on the wall, 1 bottle of beer.\n Take one down and pass it around,no more bottles of beer on the wall.\n");
printf("No more bottles of beer on the wall, no more bottles of beer.\n Go to the store and buy some more,99 bottles of beer on the wall.\n");
}

Got a better code for the problem above ? Post it on the comments.

When I went thro the lyrics.. I had two questions in my mind ..

1) Were the kids made to sing all the way from number 99 to 0 beer bottles? If the answer is "YES" , that answers my question " Why is that almost everyone in the West drink beer? "

2)What would be the RedCode version of this program ? :O :D (Am sure I'd go retarded if I tried coding the same in RedCode.)

Monday, June 23, 2008

project euler

Greetings !

I finally decided to put in more commitment to solve problems listed in project Euler. You can use almost any language to work out the problems or if you are the kind who believe computers are idiot boxes (which they are :P ) .. you can use a pen and paper approach to solve problems :)
I do know that answers to the problems already exist out there on the web and a simple google search would fetch you answers. I am more interested in alternate solutions to the one that i'd come up with because 1) i am a terribly lazy programmer and my memory and time utilization is terrible 2) there is always a better solution :D

For those who haven't heard of project Euler , visit : http://projecteuler.net/

If you have a passion for programming and dont know how to kill time , this is your way out of boredom ;)

Saturday, June 21, 2008

And i'm back!! .. i guess :P

Its been 2 months since i came here and lot has happened in in that time .. and i was thinking on what should i put the blame on , for my absence from blog-o-sphere.. and quite a few things popped up , starting with

1) the project finals

2) the final exams of my not-so-smooth engineering education

Phew ! finally.

3) manoranjan ka baap

I thought of adding another post on the blog-o-sphere during the series.. but then, i am lazy. So ..

4) Football season

I watch football once in a blue moon . Its not because i dont like to watch it.. its just that i am a miser and i wait for free telecast of the paid channels on TV .. hehehe.. and the SCV morons thought they could make me pay for watching good football.

5) wandering aimlessly in the city

The above sentence says it all.

6) getting totally hooked onto "mafia" the game

I have missed this game so much . I had played this at my good friend's place long ago and i had ever since wanted to play it and only recently did i revamp my ol' comp. She was a good gal , a sweetheart and she was with me for the past 7 and a half years.Nothing much could be done to her.. her peripherals were failing one by one. May her circuits rest in peace ;(

"In ever loving memory of my beloved PC"
(January 2001 - June 2008)
Intel Pentium III,800 Mhz,Intel 810e chipset
384 MB SDRAM , Ethernet/USB 2.0 compatible (add ons)

7) addiction to mmorpgs: mafiaboss and mafiarise ( too much of mafia in my life)

8) project euler

9) listening to Don Vito Corelone's Words of wisdom and his tie-up with MTV :P

I think that list is enough for starters.

Wednesday, April 9, 2008

How To pick A Worthy CS Research Topic In 10 Seconds !!

Computer Science is facing a major roadblock to further research. The problem is most evident with students, but afflicts many researchers as well: people simply have a tough time inventing research topics that sound sufficiently profound and exciting. Many PhD students waste needless years simply coming up with a thesis topic. And researchers often resort to reading documents from government grant agencies so they will know what to work on for the next proposal!

Good news for the CS community: the problem has at last been solved. The table below provides the answer.

Column 1                 Column 2                            Column 3

integrated               mobile                                 network
parallel                     functional                           preprocessor
virtual                      programmable                    compiler
interactive               distributed                          system
responsive               logical                                   interface
synchronized          digital                                    protocol
balanced                  concurrent                           architecture
virtual                     knowledge-based                 database
meta-level              multimedia                           algorithm
optimized                binary                                   toolkit
active                       object-oriented                   display
parameterized        secure                                   technology
conceptual               high-speed                           solution
scalable                    real-time                              language
dynamic                   functional                             agent
high-level                parallelizing                          theorem prover
collaborative           watermarking                      work cluster
type-safe                 proxy                                     cache

To generate a technical phrase, randomly choose one item from each column. For example, selecting synchronized from column 1, secure from column 2, and protocol from column 3 produces:

A synchronized secure protocol


Best of all, two phrases can be combined with simple connectives, making the result suitable for the most demanding use. Possible connectives include:

for
related to
derived from
applied to
embedded in

For example, one could generate a thesis title by selecting a second phrase and a connective:

A synchronized secure protocol for an interactive knowledge-based system

The technique described here for selecting a research topic is far superior to the method currently in use because it can be automated -- a computer program can be written to select a phrase at random whenever one is needed. Furthermore, thanks to an enchancement by Ian Stark at The University of Edinburgh in Scotland, it is possible to automate an additional step in the research process by performing an automated literature search. Try the system by first generating a random topic and then performing an automated literature search.

This article's original location : http://www.cs.purdue.edu/homes/dec/essay.topic.generator.html
Follow the above link for a JScript implementation.
The above mentioned page is maintained by his highness - Douglas E Comer :)

Tuesday, April 1, 2008

A psycho-analysis of spiders on crack.



Starts off in the lines of a standard wildlife documentary .. turns out to be more interesting than those ;)

Friday, March 21, 2008

For the utterly jobless (3) - Watch insane videos on YouTube

Hello !! Welcome to the third edition of "For the Utterly Jobless" . I hope that you've wasted your time reading the other 2 editions of FTUJ :D . This one features some unbelievably stupid clips from commercial movies which went down the drain ,enacted by a "leading artiste" of the South Indian Film industry. Such clips provide really good pass time for the utterly jobless souls.

*STATUATORY WARNING* Please donot try these at home .Parental guidance is highly recommended :P

Open heart surgery with mobile phones:

This clip shows the latest advancements in heart surgery , demonstrated by Vijaykanth (who will be referred to as Capt. from now on) . Capt. demonstrates that mobile phones can be used for more than just yakking with another person. See how the powerful light emitted from the phone's screen helps the quacks er.. doctors to perform the surgery.



The next clip shows paranormal physics , superbly demonstrated by Capt. The baddie points a pistol (fake) at our hero , who pays no heed to the baddie's threat and keeps walking , gets shot and no, it doesnt end with that.. amazingly, our Captain survives and the bullet ricochets back to the baddie ,killing him instantly. Our modest superhero Capt. then reveals his secret that saved him - a plate stolen from a nearby hotel, which he then flings away with style. Capt. thus makes a fool out of Stephanie Kwolek.



This amazing clip shows that even Bill Gates or any other geek at microsoft have no clue that the software named Windows Media Player has mutated. Our Supergeek/Superhero Capt. makes the best use of this mutation to type in commands and lo and behold - WiMP becomes an interactive software thus clearly showing that it has a mind of its own. Screw you Billy.



This next video shows Capt.'s electrifying performance as he beats the crap out of electricity. The baddie approaches menacingly towards Capt., brandishing two electrodes , which donot blow the fuse even when it's repeatedly shorted by the baddie. He then places the two ends on the cheap helmet which our Capt., is forcibly made to wear. And to everybody's surprise , instead of limping in his chair , Capt. starts reeling out his award-winning dialogue (shown in the subtitle).

Wicked Cool Java - The JScience API

JScience is a hardcore Math-Science library which provides a wide range of methods and datatypes related to Measurement (Converters , Quantities , Units) , Economics , Geography (Co-Ordinates) , Mathematics (Functions ,Numbers,Structures,Vector) and Physics.It provides data types to store numbers with a very high precision. Classes such as the LargeInteger can hold numbers of immutable sizes with arbitrary precision.

Though they may sound similar to the BigDecimal class provided in the java.lang.Number class , the org.jscience.mathematics.number.Number.LargeInteger has the following advantages:

* It is optimized for 64 bits architectures. But still runs significantly faster on 32 bits processors.
* Real-time compliance for improved performance and predictability (no garbage generated when executing in StackContext).
* Improved algorithms (e.g. Concurrent Karabutsa multiplication in O(nLog^3) instead of O(n^2).

Links :

API List -> http://jscience.org/api/index.html

Source Code -> http://jscience.org/jscience-4.3.1-src.zip

Download Library -> http://jscience.org/jscience-4.3.1-bin.zip

If you find it useful, say thanks to the Project Owner - Jean-Marie Dautelle

JScience is powered by the Javolution library (for real-time/fast performance, parallel computing etc.)

The library is open-source (BSD License). Everyone can participate by submitting new modules as long as those modules are integrated with existing modules.

I'd like to end this post with a video of a mechanical calculator for simple binary arithmetic operations :)