Friday, January 15, 2010

Introduction to various programming languages

Hey folks, I recently researched about various Programming Languages. Here I m going to discuss certain attributes of each language.

Basic

Year Introduced: 1964
Paradigm: Imperative, Procedural
Standardization: Yes, ANSI, ISO
Type Strength: Varies by dialect
Intended Use: Application, Education

C
Year Introduced: 1972
Paradigm: Imperative
Standardization: Yes, ANSI C89, ISO C90/C99
Type Strength: Weak
Intended Use: System


C++
Year Introduced: 1979
Paradigm: Imperative, Procedural, Object-oriented, Generic
Standardization: Yes, ISO
Type Strength: Strong
Intended Use: Application, System

C#
Year Introduced: 2000
Paradigm: Imperative, Object-oriented, Functional, Generic, Reflective
Standardization: Yes, ECMA, ISO
Type Strength: Strong
Intended Use: Application, Web

Haskell
Year Introduced: 1990
Paradigm: Functional, Generic, Lazy evaluation
Standardization: Yes, Haskell 98
Type Strength: Strong
Intended Use: Application

Java
Year Introduced: 1995
Paradigm: Imperative, Object-oriented, Generic, Reflective
Standardization: No
Type Strength: Strong
Intended Use: Application, Web

Perl
Year Introduced: 1987
Paradigm: Imperative, Procedural, Reflective, Functional, Object-oriented, Generic
Standardization: No
Type Strength: Weak
Intended Use: Application, Text processing, Scripting, Web

PHP
Year Introduced: 1995
Paradigm: Imperative, Procedural, Object-oriented, Reflective
Standardization: No
Type Strength: Weak
Intended Use: Web, Server-side

Python
Year Introduced: 1989
Paradigm: Imperative, Object-oriented, Functional, Aspect-oriented, Reflective
Standardization: No
Type Strength: Strong
Intended Use: Application, Scripting, Web


Scala
Year Introduced: 2003
Paradigm: Object-oriented, Functional, Generic, Lazy evaluation, Imperative
Standardization: No
Type Strength: Strong
Intended Use: Application, distributed computing

* * * * *

Wednesday, January 6, 2010

Why, what n how to Blog..


Why to Blog?

My Blogging habit commenced from January 2009 and I still love it a lot..!! I have a second blog running parallely. Here is its URL.
Blog is something that displays your thoughts to the outer world. Whatever is in your mind, you can deploy that on your blog, as its all yours. Many use blog for helping others, many use it for storing memoirs, many use them for technical discussions and many for fun and money. If you are addicted to writing.. blogging is your domain for sure.

What to Blog?
Its Important to know where your interest spans. A personal blog may contain all the happenings in your life and pictures to display them. A technical blog may contain certain useful information which you found out recently or which is the latest trend. A news blog may contain all recent updates about world, movies, sports, music etc. The thing that matters is your interest.
The second most important aspect of blogging is the content of your posts. The content must be precise, interesting and informative. For attracting more traffic to your blog you need to get a nice title to your posts. These titles get Googled frequently and increase the page rank of your post.

How to Blog?
There are many sites that offer you space to make your own blog. Some famous ones are Blogger, Wordpress, Tumblr, Procetours. I chose Blogger just because I was not having any idea about the others at that time!! I dont want to shift my blog now because then I will have to compromise with my page rank. Certain pre-built tools and gadgets are provided to the bloggers free from these sites. Javascripts may be used to build own tools.
Now, here are some tips from my side that can help bloggers in monitoring their blog and see who visits them.

Google Analytics: Its Google again :).. The analytics gives you a huge amount of information about the visitors of the blog viz the page they visit, amount of time they spend, the area from where they belong, the site from where they refer, how often they visit, even the operating system they use and the browser too..!! :p Visit Google Analytics, register yourself and your blog and enjoy tracing back your visitors. It will ask to add certain Javascrpit onto your home page and some other operations which can easily be done.

Feedjit: FeedJit is a cool tool. It displays the visitor on your blog in a real time basis. The visitors' location will be displayed on the blog itself at whichever corner you wish to place the tool. On clicking the real time display, it shows every visitor location, the sites from where they referred your blog and the keyword they typed in if they Googled your blog and also to which page did they exit. Go for it.. its free.. at least for now..!! :p

Google Feedburner: Recently added to Google. It allows you to generate feeds and sends them to each of your blog's subscriber. RSS feeds or ATOM, anyone can be chosen to begin with.

If you are interested in money making and have a decent regular traffic, you can add Google Adsense onto your blog. Google provides you with some advertisements of other companies which when clicked by a visitor lets you make money. The advertisements are mostly related to the content of your blog.

All these may help you in forming and maintaining your blog. If you have more information.. comments are surely invited..!!
HAPPY BLOGGING..

* * * * *

Tuesday, December 15, 2009

Some more problems of SPOJ...

I recently breached into the top 1200 ranks in the world, but sad news is, soon I'll be thrown out too. The points keep on decreasing on a regular basis. Never mind this works as an incentive to work on more and more problems. :)
So, m writing this post for some more problems of SPOJ. The problems I m going to discuss are of an average level.

BISHOPS: Its an easy problem, if we try verbally. The answer is (2*n-2) i.e. equal to the number of diagonals. But the difficulty lies in the range of the inputs. N<=10^100..!! OMG!!.. :).. Try strings..

MINCOUNT: Actually what I did.. I tried it out for certain test cases and found that the answer is.. (n*(n+1)/2)/3.. i.e. the total number of coins in the triangle divided by 3. But why its so.. its still unanswered for me.. kindly post the explanation if you get one..!! :)

HUBULLU: Same mincount type problem here too.. seeing the discussion in the forum I got some hints that who so ever plays first wins.. So, it became a very very easy question for me to crack but why it happens is yet not understood by me..

TRICOUNT: Its another mathematics problem.. try it for sometime with all yours geometrical anlysis and at one time you will definitely come out with a solution that is much like (t*(t+2)*(2*t+1))/8.. where t is the level of triangle. Try it now yourself..!!

SAMER08F: Another age old problem of how many squares are there in a given bunch of squares?? Answer lies in the sum all squared numbers till the number of squares in each side of the grid i.e. if N=8 then answer= (1*1) + (2*2) + ... + (8*8).

Seeing my last three posts of SPOJ I think now its easy for any newbie to get started. So, no more discussing algorithms of SPOJ problems from my side. Keep practicing and who knows one day you beat [Trichromatic] XilinX..!! :p

* * * * *

Saturday, November 21, 2009

SPOJ: Some very easy problems

Its been a month since I have started coding in SPOJ. There are over 5000 problems present there. Its really gets very tough when one tries to get some easy problems from that lot. So, I dedicate this post to beginners. Go for the below mentioned problems.

Some very easy classical problems:

TEST- This is the first problem I solved in SPOJ. I recommend the same for you. It gives a brief introduction of the whole environment. What you need to do is to accept and print the input by the user until you come across 42. The easiest problem at SPOJ and a confidence booster to begin with..!! ;)

ADDREV- Take two numbers as input. Reverse both. Add the reversed number. Reverse again. Simple..!! The thing you need to keep in mind is that you have to provide the number of test cases first. While taking the inputs you can print the result too. You need not store them and print later.

FASHION- Quite big explanation of the problem (a bit interesting too ;) ). The only thing you need to keep in mind is that you have to sort the degree of hotness of men and women and then multiply and add them up. If you do not sort them, it will give a WA.

MIRRORED- Print "Mirrored pair" wherever you confront "bd" or "db" or "pq" or "qp", otherwise print "Ordinary pair". Don't forget to print "Ready" in the beginning. You do not have to take the test cases as input here. Just end the input when you confront two spaces. I got an AC at very first attempt..!! Hope the same for you.. :)

NSTEPS- Analize the graph properly. Whenever x and y co-ordinates are even the corresponding output is (x+y) for input (x=y) and (x=y-2). When they are odd the corresponding ouput is (x+y-1) for input (x=y) and (y=x-2). You can also do the problem with a different approach too. You can form a series for the numbers, and hence, generate the output.

OFORTUNE- Common.. don't get astonished by the enormous length of the question. Try tackling the problem. It just needs six inputs and a simple interest and compound interest formula implementation thats it.. Try it.. You will gain a hell lot of points..!!

Some very easy challenge problems:

SIZECON- The difficulty doesn't lie in the problem statement. The difficulty lies in the choice of programming language. I managed to do it in 96 characters. Best solution in c++ has 70 characters in it. Perl language wins with just 6 characters..!!

BFWRITE- I have already written a post about this problem. Try learning Brainf_ck language and solve this problem too. Here's the link to my post.

More easy problems are being searched. Kindly mention some in comments if you confront one.. Here's my SPOJ handle.. vaibhav_pandey.

* * * * *

Saturday, November 14, 2009

Getting started with Project Euler



Hello folks.. After getting started with SPOJ and TOPCODER, lets get started with another fine programming competition which is Project Euler.

The first question which originates is.. why Project Euler??

My answer.. why not?? If you are interested in programming.. make yourselves interested in mathematical shortcuts and logics for solving problems too. Project Euler is a site that provides you problems that bind you to explore some unexplored areas of mathematics. Now, lets get started..

Steps:
  • Get registered.
  • See the problems from problems tag. There are more than 260 problems at present.
  • Solving problems requires you either to build a source code that computes the asked value or to pick up pen and paper and start solving. My advice.. prefer the earlier one..!! :)
Your profile consists of the number of problems you have solved. Your ranking is based on levels. If you have successfully solved 25 questions you qualify to the level 1 and so on and so forth. On solving a problem its thread gets unlocked and you can check solutions of others in the languages they preferred. Thus, you can compare your code with others.

Your profile gets dissolved if no activity happens in 90 days of time. This happens if you are 0, 1 or 2 level programmer. Level 3 and level 4 programmers are granted immortality, thus, here lies the advantage of being superior.. 8)
So, get started with Project Euler and hone your programming skills..

To see my profile, first register to the site and then type the URL: http://projecteuler.net/index.php?section=profile&profile=vaibhav_pandey

* * * * *

Thursday, November 5, 2009

My experience with BrainF_ck Programming Language

Hi folks.. Last few days I worked a bit on BrainF_ck language. A nice language that may be used for encoding sort of stuff. What we code in it.. it might happen that we ourselves forget about it, such is the level of complexity of the language!!
The brilliant factor about the language is that it is just made of eight symbols in total..!! Surprised.. so was I..!! :D

Whole of the language depends on just an array. Every manipulation has to be done in the array using a memory pointer, which moves through the memory blocks of the array. Now, getting over to the practical implementation of the language. The eight symbols are:

> = increases memory pointer, or moves the pointer to the right 1 block.
< = decreases memory pointer, or moves the pointer to the left 1 block.
+ = increases value stored at the block pointed to by the memory pointer
- = decreases value stored at the block pointed to by the memory pointer
[ = like c while(currentBlockValue != 0) loop.
] = if block currently pointed to's value is not zero, jump back to [
, = like c getchar(). input 1 character.
. = like c putchar(). print 1 character to the console.
I made my first program for SPOJ challenge problem BFWRITE. Before going through the code I would give you the link of an online compiler for BrainF_ck language. I prefer BrainF interpreter. So now, here's my code:
  1. ++++++++++
  2. [
  3. >+++++++>++++++++++>+++<<<-
  4. ]
  5. >+++++++++++++.
  6. ---.
  7. -.
  8. -----.
  9. >>++.
  10. <+++++.
  11. ++++++++++.
  12. >.
  13. <----------.
  14. +++++.
  15. ----------.
  16. +.
  17. .
  18. -.
  19. >.
  20. <---.
  21. ++++++++++++++++++++++.
  22. ------------------.
  23. ++++++++++++++.
  24. ----.
  25. --.
  26. --------.

Looks quite difficult to understand but I'll make it simpler for you.
  • First line assigns value 10 to a[0]
  • Second line begins a loop checking value of current block a[0].
  • Third line moves pointer ahead once(>) and assigns value 7 to a[1](++++++). The same line then again pushes pointer to a[2] and assigns value 10. 3 value is given to a[3]. The pointer returns back to a[0](<<<) and decrements the value to 9.
  • In the fourth line.. loop goes on until the value of a[0] exhausts.
  • Finally the values are.. a[0]=0, a[1]=70, a[2]=100, a[3]=30.
  • The sixth line decreases a[1] by 3 and makes its value equal to 67. '.' prints the value 'S', ASCII code of 67.
  • Likewise the further lines print the text:- 'P','O','J',' ','i','s',' ','i','n','d','e','e','d',' ','a','w','e','s','o','m','e'. Hence on our output comes as:- SPOJ is indeed awesome.
I further improved my code to 153 characters. Instead of making the array 70, 100, 30 in the beginning I made the array as 64, 32, 104, 112. Try it out yourself to optimize the code.

* * * * *

Friday, October 30, 2009

How to handle very large test cases in c++

Most of us come across some c++ problems where we are asked to get some simple calculations done. For example: we can get a problem of subtracting 1 from a 100 digit number. Now, subtracting one is not a big problem for us but the problem is '100 digit number'.

None of the datatype has capacity to store such a large number. Stop thinking about unsigned long long.. even it cant..!! So, here's a short solution to this cute problemo..

We can take the input as a string and process each of its elements as in elementary mathematics i.e. if last digit is'nt 0 then reduce it by 1(dont forget it to convert to int and then back to string).. if last digit is zero then make it nine and move back to the adjacent digit following the same procedure. Simple :)

Here's the source code..

#include
using namespace std;
int main()
{
int i,t=40;
string z;
cin>>z;
i=z.size()-1;
do
{
if(z[i]!='0')
{
z[i]=int(z[i])-1;
break;
}
z[i--]=57;

}while(i>=0);
Then print the string a.

The only problem comes when we give input as 10, 100, 1000, 10000 ... the answer comes out as 09, 099, 0999, 09999... instead of normal numbers such as.. 9, 99, 999, 9999... I have resolved this problem for myself.. I'll not upload the source.. try it out yourself..!! ;)

* * * * *