# Life of student

• ## Blog Stats

• 16,533 hits
• ## Email Subscription

Join 10 other followers

## learn Programming with syllabus

Posted by pankaj4u4m on April 17, 2011

I recently got a useful link which is syllabus of programming camp at IIIT-A. It is very useful for the beginners as well as for self learnt good programmers (because they know only the topics which are covered my the problems solved by them). There are some good references too which are nice. Here it is.

Programming Syllabus

Posted in Uncategorized | 1 Comment »

## Some useful unseen functions and constants in C/C++

Posted by pankaj4u4m on October 23, 2010

I was searching for such articles long time. During googling I found some of the functions and constants available in C/C++.
1>Constants:
* __LINE__ : integer contains line number
* __FILE__ : string contains name of file
* __DATE__, __TIME__ : you can understand by name
* __func__, __FUNCTION__ : name of function in inside which it is used
* __PRETY_FUNCTION__ : name + signature of function in C++, same as above two in C
* __STDC__ : variable defined when compiling in C
* __cplusplus : variable defined when compiling in C++
mathematics:-
* M_E : The base of natural logarithms.
* M_LOG2E : The logarithm to base 2 of M_E.
* M_LOG10E : The logarithm to base 10 of M_E.
* M_LN2 : The natural logarithm of 2.
* M_LN10 : The natural logarithm of 10.
* M_PI : Pi, the ratio of a circle’s circumference to its diameter.
* M_PI_2 : Pi divided by two.
* M_PI_4 : Pi divided by four.
* M_1_PI : The reciprocal of pi (1/pi)
* M_2_PI : Two times the reciprocal of pi.
* M_2_SQRTPI : Two times the reciprocal of the square root of pi.
* M_SQRT2 : The square root of two.
* M_SQRT1_2 : The reciprocal of the square root of two (also the square root of 1/2).
function I will post later If you can please contribute

## Auto mount drives in linux

Posted by pankaj4u4m on November 28, 2009

I was just searching for how to enable the mounting the drives at start up because I didn’t find authorization menu in Fedora 12.

I found one solution and it is working for my system

open terminal and do following commands:

[codegambler@localhost /]\$ su

```[root@localhost /]#vi /etc/selinux/config'

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#       enforcing - SELinux security policy is enforced.
#       permissive - SELinux prints warnings instead of enforcing.
#       disabled - No SELinux policy is loaded.
SELINUX=permissive
# SELINUXTYPE= can take one of these two values:
#       targeted - Targeted processes are protected,
#       mls - Multi Level Security protection.
SELINUXTYPE=targeted

change the hi-lighted line as given;

[root@localhost /]# vi /etc/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local

it is for my system

Now whenever you will restart your system you no need to mount again:
Happy fedora :)

```

Posted in Fedora, Linux | 1 Comment »

## wow what the powerful editor is this VIM

Posted by pankaj4u4m on November 11, 2009

vim is a powerful editor in linux operation system and i found some of very usefull tips in vim from net.
1>if you want to add some of line while opening some specific file then you can do by adding following lines in you .vimrc file
first of all create a .vimrc file like:
[codegambler@localhost ~]\$ vi ~/.vimrc

another use of autocmd is set default setting for filetype like

autocmd FileType html setlocal shiftwidth=2 tabstop=2
autocmd FileType python setlocal expandtab shiftwidth=4 softtabstop=4

also by using

autocmd FileType cpp source ~/.vim/cpp.vim

autocmd FileType py source ~/.vim/py.vim

one usefull command to indent lines in c/c++ file(one of the prefered setting )

autocmd FileType cpp setlocal expandtab shiftwidth=4 softtabstop=4 cindent number

you can make a file

#include
#include
int main()
{
}
code. when you will create any c/cpp file this default code will automatically insert
2> using calculator inside your vim
if you want to do some basic calculation like +,-,*,% then this will automatically do for you

inoremap <C-B> <C-O>yiW<End>=<C-R>=<C-R>0<CR>

next time when you will type
2+2

now press ctrl+b …. and it will replace it with ..

2+2=4

what a amazing feature is;

3> like most editor you want to undo your some of code to previous version. you can do it by using command

: earlier 10

this will take you back to before 10 modification

:earlier 10s

this will take you 10s back into your code

:later 5 will forward the undo code

what a nice command
be happy and free to code you program in vim 🙂

i found these tips in this site ajay somani’s blog. which i found useful to me.
some other tips also whic are not in that site are here

1> encrypt you file inside vi
[codegambler@localhost ~]\$ vi -x myufile

now you enter your pass* . now whenever you will open your file it will decrypt the content and whenever you close it it will again encrypt and save it..

if you know any good tips which can help to learn vim better please add it here… you are always welcome
HAPPY CODING 🙂

## How to change MAC address in Linux

Posted by pankaj4u4m on October 10, 2009

How to change MAC address in Linux First find the physical MAC address of your machine by running the following command :

\$ ifconfig -a | grep HWaddr

Next, login as root in Linux and enter the following commands –

# ifconfig eth0 down

# ifconfig eth0 hw ether 00:80:48:BA:d1:30

# ifconfig eth0 up

NOTE:This change in MAC address is only temporary. Once you reboot your machine, the operating system reflects the physical MAC address burnt in your network card and not the MAC address you set.

## Polyglot:single program runs on multiple languages

Posted by pankaj4u4m on October 4, 2009

Before it i never heard the name polyglot!!!! I saw this on one of online event in IITM tech fest. Initially I faced difficulty but when I did one program rest were seems very easy to do. and I stood first in this competition. Polyglot is not a programming language but it is way of programming such that it runs on two or more compiler (different languages) simultaneously without making any change on it.   “A polyglot is a computer program or script written in a valid form of multiple programming languages, which performs the same operations or output independently of the programming language used to compile or interpret it.”

See it very interesting:
``` #include<stdio.h> #define print(x) main(){printf(x);} print("Pankaj\n") ```

it can runs in perl and C and prints Pankaj

There were saveral problems which I did successfully and here are these:

1>here are 3 cities A B and C. City A and B are connected with p roads. City B and C are connected with q roads. City C and A are connected with r roads. In how many different ways can one reach city C starting from city A? (0<p,q,r<10)

sample input:

1 1 1

samlpe output:

2

the code is:
``` #include<stdio.h>/* 0 and length<<2; """ 2 (*O/*_/ /# * ) 2>_\$\$;read -n2 p;read -n2 q;read -n1 r;((r=p*q+r));echo \$r;exit; /*0)unless \$p=getc();getc();\$q=getc();getc();\$r=getc();print\$p*\$q+\$r;__END__ """ p=raw_input() print int(p[0])*int(p[2])+int(p[4]) #*/ #define X p;q;r;main(){scanf("%d%d%d",&p,&q,&r);printf("%d",p*q+r);}x X=1; ```
it runs on BASH, PERL, PYTHON and C

2>Polyglot that takes as input a string of length n and prints the reverse of the string. (0<n<20)

sample input:

pankaj

sample output:

jaknap
Code:
``` #include<cstdio> #include<cstring> #include<algorithm>/* #,----------[>,----------]<[++++++++++.<]++++++++++. 0 and length <<2; """ 2 (*O/*_/ /# * ) 2>_\$\$;read n;echo \$n|rev;exit; /*0)unless \$p=<>;\$p=~s/\s+\$//;\$p = reverse \$p;print \$p;__END__ """ p=raw_input() p=p[::-1]; print p #*/ #define X int main(){char s[20];gets(s);std::reverse(s,s+strlen(s));puts(s);return 0;}int x X=1; ```
runs on BRAINFUCK,BASH,PERL,PYTHON and C++

3>Given an array of ten numbers a[i] 1<=i<=10 and a number n.
Write a minimum 3 language polyglot that outputs 0 if the number n is not
found in the array or outputs 1 if the number n is found in the array.

``` #include<stdio.h>/* 0 and length <<2; """ 2 (*O/*_/ /# * ) 2>_\$\$;i=0 while [ \$i -lt 11 ] do read p[\$i] ((i++)) done i=0 while [ \$i -lt 10 ] do if [ \${p[\$i]} -eq \${p[10]} ];then echo "1" exit fi ((i++)) done echo "0" exit /*0)unless \$p[0]=<>; for(\$i=1;\$i<11;\$i++){\$p[\$i]=<>;}for(\$i=0;\$i<10;\$i++){if(\$p[\$i]==\$p[10]){print "1";exit;}}print "0";__END__ """ def h(): p=[0,0,0,0,0,0,0,0,0,0,0] for i in range(0,11): p[i]=input(); i=i+1; for i in range(0,10): if p[i]==p[10]: return 1 return 0 print h() #*/ #define X i;p[15];main(){for(i=0;i<11;i++)scanf("%d",&p[i]);for(i=0;i<10;i++)if(p[i]==p[10]){printf("1");return;}printf("0");}x X=1; ```
BASH,PERL,PYTHON and C

4>Consider a two-pan balance, you are asked to weigh a piece of wood
known to have some integral weight between 1 gram and n grams (3<n<999).
If the weights can go in either pan, what is the minimum number of integral weights you need to weigh the wood.

sample input:

4

sample output:

2

code:
``` #include<stdio.h>/* 0 and length <<2; """ 2 (*O/*_/ /# * ) 2>_\$\$;read s;r=1;n=0;((s=s*2+1));while [ \$r -lt \$s ];do ((r*=3));((n++));done;echo \$n;exit; /*0)unless \$s=<>;\$r=1;\$n=0;while(\$r<\$s*2+1){\$r*=3;\$n+=1;}print\$n;__END__ """ s=input() r=1 n=0 while r<s*2+1: r*=3 n+=1 print n #*/ #define X s,r=1,n=0;main(){scanf("%d",&s);while(r<s*2+1){r*=3;n++;}printf("%d",n);}x X=1; ```
BASH,PERL,PYTHON and C

5>A quine is a program that produces its own source code as output.Polyglot quine program that takes as input a
integer n (0<n<10) and outputs its source code n times.

``` #include<stdio.h>/* #<?php \$b=file_get_contents(__FILE__);\$a=trim(fgets(STDIN));\$i=0;while(\$i<\$a){\$j=0;if(\$i==0)\$j=1;while(\$j<strlen(\$b))echo \$b[\$j++];\$i+=1;};return 0;?> 0 and length <<2; """ 2 (*O/*_/ /# * ) 2>_\$\$;read n;while [ \$n -gt 0 ];do cat \$0;((n--));done;exit; /*0)unless open FILE, __FILE__; \$a=<>; \$b=""; while(<FILE>){\$b=\$b.\$_;} while(\$a--){print \$b;} __END__ """ import sys f=open(sys.argv[0],"r") n=input() while(n>0): for i in f: print i, n=n-1 f.seek(0) #*/ #define X n;c;main(){FILE *f;f=fopen(__FILE__,"r");scanf("%d",&n);while(n--){while((c=getc(f))!=EOF)putchar(c);fseek(f,0,0);}}x X=1; ```
This one is very interesting it is in PHP,BASH,PERL,PYTHON and C (five language polyglot)

6>Polyglot program that will recognise its own
source code. The Program should output 1 if the input is its source code
itself and output 0 if the input is not its source code.

``` #include<stdio.h>/* 0 and length <<2; """ 2 open FILE,__FILE__;\$b=1;while(<FILE>){\$a=<STDIN>;if(\$_ ne \$a){\$b=0;}}print \$b;__END__ """ import sys def h(): f=open(sys.argv[0],"r") for i in f: x=raw_input(); if(cmp(i,x)==0): return 0; return 1; print h() #*/ #define X b;c;a=1;main(){FILE *f;f=fopen(__FILE__,"r");while((c=getc(f))!=EOF){b=getchar();if(c!=b)a=0;}printf("%d",a);}x X=1; ```
on PERL,PYTHON and C

Here is a duine program in 5 languates:C,brainf**k,perl,ruby and python

At last I enjoyed this event a lot and had learnt different languages just in two days!!!
NOTE:this post and attachments are only for my future reference
NOTE:FOR ALL PROGRAM input will be STDIN and output will be STDOUT

Posted in c++, polyglot, Programming | 3 Comments »

## solve prime1 problem in spoj and codechef

Posted by pankaj4u4m on August 27, 2009

If you will search in net by giving the name “prime1” you will see so many code which successfully solve this problem.Here is my submission for this problem in codechef
```void prime(int L,int U) { int d=U-L+1; bool flag[d]; memset(flag,true,sizeof (flag));//all true for (int i=L%2;i<d;i+=2){ flag[i]=false;}//every position of even number false for (int i=3;i<d;i+=2) { //if (flag[i]==true) continue;//given number is already set prime int mod=L%i; int t; if(mod>0)t=i-mod; else t=mod; if(L/i==1||L/i==0)t+=i; for(int j=t;j<d;j+=i){flag[j]=false;} }```

``` if (L<=1) flag[1-L]=false; if (L<=2) {printf("2\n");} for (int i=L%2?0:1;i<d;i+=2) if (flag[i]==true) printf("%d\n",L+i); ```

`}`
this function take the two number and print all the prime number betweem them.
EXPLANATION:
1.first set bol as true assuming that all number can be prime.
2.then set false for those which is divided by 2.
3.Now run for loop for all odd number and check if it is a prime if not proceed for next number else proceed for steps in for loop.
4.inside for loop leave first number because it is prime number and them set all other number which will divide by this prime number.
5.At last print all the prime number.:)

REFERENCES:
1.Sieve_of_Eratosthenes

Posted in Algorithm, c++, Programming | 2 Comments »

## Fedora camp in SASTRA

Posted by pankaj4u4m on August 23, 2009

This was first time happening in my college SASTRA that there was any fedora camp.

The camp was organized by me (Pankaj kumar), Nishanti, Anurag Jain, Sanjeev Gopinath,and J.Dwarak.The response was very good and all became happy when we distributed fedora 11 dvds and stickers.

The session was started at 11.00 am by Nishanti (the host of the event) who described the agenda for the event and the Dwarak started his seminar on OPEN SOURCE and LINUX. He told what OPENSOURCE is and connected it to the corporate world. After that I came and explained about FEDORA , Fedora subprojects, and then features of fedora. Anurag told the installation of fedora and demonstrated some software. Sanjeev took FEDORA ELECTRONIC LAB and he explained how one can design electronic board using fedora electronic lab. While he was explaining I designed basic AND gate in DIGITAL DESIGNER and simulate that. I felt very excited while doing that.Then  Sanjeev  explained C/C++ and JAVA coding which was complied by me. Anurag gave very important links to the audience which is very helpfull after first time fedora installation. At the end of Sanjeev’s session we demonstrated GNOME Desktop features and COMPIZ, audience were very excited to see these all. At the end we distributed fedora 11 DVDs and stickers and then we end the session at 1.30pm . At the end of session we had party for organizers 🙂 . The presentations can be downloaded from these links

Posted in Fedora, Linux, Uncategorized | 3 Comments »

## DVD rom not working in windows ???

Posted by pankaj4u4m on August 13, 2009

If your dvd rom is not detected in your windows system. Do following steps.

### Microsoft Windows Vista

1. Click Start
Collapse this imageExpand this image

, and then click All Programs.

2. Click Accessories, and then click Run.
3. Type regedit, and then click OK.
Collapse this imageExpand this image

If you are prompted for an administrator password or for a confirmation, type the password, or click Allow.

4. In the navigation pane, locate and then click the following registry subkey:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E965-E325-11CE-BFC1-08002BE10318}
5. In the right pane, click UpperFilters.Note You may also see an UpperFilters.bak registry entry. You do not have to remove that entry. Click UpperFilters only. If you do not see the UpperFilters registry entry, you still might have to remove the LowerFilters registry entry. To do this, go to step 8.
6. On the Edit menu, click Delete.
7. When you are prompted to confirm the deletion, click Yes.
8. In the right pane, click LowerFilters.Note If you do not see the LowerFilters registry entry, unfortunately this content cannot help you any further. Go to the “Next Steps” section for information about how you can find more solutions or more help on the Microsoft Web site.
9. On the Edit menu, click Delete.
10. When you are prompted to confirm the deletion, click Yes.
11. Exit Registry Editor.
12. Restart the computer.

### Microsoft Windows XP

1. Click Start, and then click Run.
2. In the Open box, type regedit, and then click OK.
3. In the navigation pane, locate and then click the following registry subkey:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E965-E325-11CE-BFC1-08002BE10318}
4. In the right pane, click UpperFilters.Note You may also see an UpperFilters.bak registry entry. You do not have to remove that entry. Click UpperFilters only. If you do not see the UpperFilters registry entry, you still might have to remove the LowerFilters registry entry. To do this, go to step 7.
5. On the Edit menu, click Delete.
6. When you are prompted to confirm the deletion, click Yes.
7. In the right pane, click LowerFilters.Note If you do not see the LowerFilters registry entry, unfortunately this content cannot help you any further. Go to the “Next Steps” section for information about how you can find more solutions or more help on the Microsoft Web site.
8. On the Edit menu, click Delete.
9. When you are prompted to confirm the deletion, click Yes.
10. Exit Registry Editor.
11. Restart the computer.

reference from: http://support.microsoft.com/default.aspx/kb/314060>

## swapping of two numbers in one line

Posted by pankaj4u4m on August 12, 2009

Today when i was programming I saw one interesting thing, swapping of two numbers in one line!!!!

Previously I know how to swap two numbers usins bitwise operator but this is simple using ordinary operation…:)

a=(b=(a=b+a,a-b),a-b);

here is using bitwise operator.

a^=b^=a^=b;

Explanation:

1.For first expression if we seperate the expression it will like this-

First a=a+b will evaluate thusand then if we subtract b from a now it will give the original value of a and is assigned to b. So now b contain the value of a. In next after assigning a to b again subtract b from a i.e this time it will give the original value of b and is assigned to a. So the result is a contain the valuse of b and b contain the value of a i.e swapped.

ex: a=3;b=2;

a=a+b =>a=5;

b=a-b =>5-2 =>b=3 (original value of a)

a=a-b =>5-3 =>a=2(original value of b)

2.  For second expression:

lets understand with an example. a=3 ,b=2;

if we convert it into binary form a=11,b=10;

so in first step a=a^b => 11(XOR)10 =>01(now value of a)

in next b=b^a => 10(XOR)01 => 11(now value of b and original value of a)

next a=a^b => 01(XOR)11 => 10 (now value of a original value of b)

so it is swapped. 🙂

Posted in Algorithm, c++, Programming | 8 Comments »