On Sat, Apr 7, 2012 at 11:24 AM, Dave dave_and_da...@juno.com wrote:
@Ashgoel: Try this:
bool OnesZerosOnes(unsigned int n)
{
if( !(n 1) || !(n = n+1) ) return 0;
n |= n-1;
return !(n (n+1));
}
Here is how it works:
!(n 1) is true if the number has trailing zeros.
If
For 2nd,
Are you looking for this? /lib/modules/kernel_versionbuild/ ?
Or the kernel image? It can be found under /boot/. But that depends
upon the distribution, there is no symbolic link present for kernel
image as far as i know.
On Fri, Jul 29, 2011 at 9:45 AM, rajeev bharshetty
+1 Nikhil
On Thu, Jul 28, 2011 at 4:26 PM, Nikhil Jindal fundoon...@yahoo.co.in wrote:
Generate a random number from 1 to 100.
If it is less than or equal to x, return true, else return false.
This will ensure that ur returning true with x/100 probability.
Cheers
Nikhil Jindal
On Thu, Jul
I am not sure about the first question, but if you use sizeof(main()),
it gives the ans 4.
vishal@ubuntu:~/progs/c\ 09:12:57 PM $ cat alg.c
#includestdio.h
int main()
{
printf(%d\n,sizeof(main()));
return 0;
}
vishal@ubuntu:~/progs/c\ 09:13:00 PM $ gcc alg.c
vishal@ubuntu:~/progs/c\
@ rajeev,
vishal@ubuntu:~/progs/c\ 09:25:38 AM $ cat alg.c
#includestdio.h
int main()
{
int *p = (int *)0xff;
*p = 4;
return 0;
}
vishal@ubuntu:~/progs/c\ 09:25:42 AM $ gcc alg.c
vishal@ubuntu:~/progs/c\ 09:25:45 AM $ ./a.out
Segmentation fault
vishal@ubuntu:~/progs/c\
@ankur, i think 1,2 and 2,1 would be same as set theory.. CMMIW.
following is the code..
#include stdio.h
#include stdlib.h
void print_comb(int *a, int len)
{
int tlen = len;
int i, j, k;
for (i=0;i5;i++) {
for (j=i+1; j4;j++) {
anyway, the code i posted is buggy.. doesn't work for k=3.. don't use it :)
On Tue, Jul 26, 2011 at 1:02 PM, Vishal Thanki vishaltha...@gmail.com wrote:
@ankur, i think 1,2 and 2,1 would be same as set theory.. CMMIW.
following is the code..
#include stdio.h
#include stdlib.h
void
Here is the working code..
#include stdio.h
#include stdlib.h
int a[] = {1,2,3,4,5};
#define ARRLEN(a) (sizeof(a)/sizeof(a[0]))
void print_comb(int len)
{
int tlen = len;
int i, j, k;
int al = ARRLEN(a);
for (i = 0; i al; i++) {
for (j=i+len-1;
z = x + (-y)
:)
On Tue, Jul 12, 2011 at 10:58 AM, Sunny T sunny.1...@gmail.com wrote:
i would say.. implementing subtraction using division and modulus is more
costly and complicated. bit manipulation is the fastest among all
these techniques.
x=a-b = (a/b)*b + a%b
.here u are
google this question!!
On Fri, Jul 8, 2011 at 11:47 AM, priyanshu priyanshuro...@gmail.com wrote:
How to find the number users connected to the web??
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to
Off Topic:
Sorry for the diversion, but I was just wondering how easy it has
become to code in languages other than c. Here is the code i wrote for
the above mentioned problem in Python. It takes command line arg as
string. something like
vishal@ubuntu:~/progs/python\ 02:45:07 PM $ cat rev.py
space between words? Not sure how split functions helps.
BTW, Perl also is very strong language for string manipulations.
(Specially designed for efficient string operations)
On Thu, Jul 7, 2011 at 2:48 PM, Vishal Thanki vishaltha...@gmail.com wrote:
Off Topic:
Sorry for the diversion, but I
at 3:34 PM, Vishal Thanki vishaltha...@gmail.com wrote:
@Navneet, it works with multiple spaces between words.. And here is
the two line solution :)
import sys
print .join((sys.argv[1].split())[::-1])
On Thu, Jul 7, 2011 at 3:12 PM, Navneet Gupta navneetn...@gmail.com wrote:
@Vishal, can
#!/usr/bin/python
import sys
string=sys.argv[1]
string= .join((string.split())[::-1])
print string
How does this sound? :P
On Thu, Jul 7, 2011 at 3:43 PM, Vishal Thanki vishaltha...@gmail.com wrote:
yea, expression .join((sys.argv[1].split())[::-1]) will return the
string!!
On Thu, Jul 7
you are overwriting terminating null char!!
On Fri, Jul 8, 2011 at 10:23 AM, rShetty rajeevr...@gmail.com wrote:
#includestdio.h
#includestring.h
int main()
{
char str[]=This is rajeev\n;
char str1[10];
memset(str,'0',4);
printf(%s,str);
memcpy(str1,str,10);
printf(\n this is
then what is the correct approach
if i still want to use memcpy. Thoughts?
On Fri, Jul 8, 2011 at 10:51 AM, Vishal Thanki vishaltha...@gmail.com
wrote:
you are overwriting terminating null char!!
On Fri, Jul 8, 2011 at 10:23 AM, rShetty rajeevr...@gmail.com wrote:
#includestdio.h
If we only need to print the words in reverse order, strtok+recursion
can help. Following is the code (which also stores the string into
another string, not memory efficient though):
#include stdio.h
#include string.h
#include stdlib.h
char str[] = This is a new world;
char sstr[sizeof(str)];
Hi Gene,
I was thinking the same thing which you implemented in your first
snippet. But I tried it without using typedef. Following is my code:
#include stdio.h
#include malloc.h
int main()
{
int (*ptr)[4] ;
ptr = (int ((*)[4]))malloc(2*sizeof(int (*)[4]));
if (ptr) {
+1 @Sankalp
On Tue, Jul 5, 2011 at 5:02 PM, sankalp srivastava
richi.sankalp1...@gmail.com wrote:
A better place to put these types of questions would be www.stackoverflow.com
On Jul 4, 10:45 pm, amit kumar amitthecoo...@gmail.com wrote:
thanx guys...
On Mon, Jul 4, 2011 at 5:11 PM,
because \061 is considered as a single char in ur string..
On Mon, Jul 4, 2011 at 12:52 PM, Sangeeta sangeeta15...@gmail.com wrote:
#Iincludestdio.h
#includestring.h
main()
{
char str[]=S\061AB;
printf(\n%d,strlen(str));
}
output:4
why?
--
You received this message because you are
Don't allocate too much static memory in stack, it will cause
troubles. You are doing int[2000][2000], i.e. 2000*2000*4 bytes of
memory in stack. Use dynamic memory allocation for such large chunk. I
modified your code as below and it doesn't give seg fault.
#includestdio.h
#include malloc.h
Rujin is right, here is the code which compiles..
vishal@ubuntu:~/progs/c\ 11:04:37 AM $ cat alg.c
#includestdio.h
int maxdiff(int arr[]);
int main()
{
int p,arr[]={2,4,1,6,23,4};
p=maxdiff(arr);
printf(\n MAX Diff is \t %d,p);
return 0;
}
int maxdiff(int arr[])
{
this may be a reverse race, who comes last will win..
On Mon, Jun 27, 2011 at 6:22 PM, Dave dave_and_da...@juno.com wrote:
Force indain driver finishes second in race. Ferari was next to last.
Dave
On Jun 27, 2:18 am, Lavesh Rawat lavesh.ra...@gmail.com wrote:
*Statement Riddle - 27
this code will only print, it will not store the reverse string.
On Mon, Jun 27, 2011 at 9:53 PM, Kamakshii Aggarwal
kamakshi...@gmail.com wrote:
#include stdio.h
#include stdlib.h
void revers(char *s)
{
if(*s)
{
revers(++s);
s--;
and yes, s will be stored in stack everytime you call the function,
so its a temp variable..
string reverse is a simple logic, just iterate i through 1 to n/2 and
swap the i to n-i
On Mon, Jun 27, 2011 at 10:06 PM, Vishal Thanki vishaltha...@gmail.com wrote:
this code will only print
she got killed because of suffocation :P
On Fri, Jun 24, 2011 at 12:35 PM, Lavesh Rawat lavesh.ra...@gmail.com wrote:
sherlock puzzle Solution - 24 june
A wife and her husband were driving in their car on the highway. All of a
sudden, they ran out of gas. So the husband said to the wife,
Hey all,
I think I am missing something very basic in C, and which is troubling
me. Following code is not compiling for me, can anyone explain why?
vishal@ubuntu:~/progs/c\ 09:07:01 AM $ cat ternary.c
#include stdio.h
#include stdlib.h
int main(int argc, char *argv[])
{
int x =
*argv[])
{
int x = atoi(argv[1]);
int y = 10;
x = (x 10) ? y++: 10;
return x;
}
Wladimir Araujo Tavares
Federal University of Ceará
On Fri, Jun 24, 2011 at 12:40 AM, Vishal Thanki vishaltha...@gmail.com
wrote:
Hey all,
I think I am missing something
Okay, I found the problem i think,
(x 10) ? y++: x = 10 is evaluated as ((x 10) ? y++: x) = 10
which is wrong..
(x 10) ? y++: (x = 10) will work.
On Fri, Jun 24, 2011 at 9:22 AM, Vishal Thanki vishaltha...@gmail.com wrote:
yes, i understand that.. but is there any limitation in ternary
was he driving a bus or tram?
On Wed, Jun 22, 2011 at 12:36 PM, Yameni Dhankar yamenid...@gmail.com wrote:
was he driving an ambulance?
On Wed, Jun 22, 2011 at 12:33 PM, Lavesh Rawat lavesh.ra...@gmail.com
wrote:
A Riddle
A bus driver was heading down a street in Delhi. He went right past
memory leak and memory allocation check, make sure malloc return non-null.
On Wed, Jun 22, 2011 at 7:04 PM, Shachindra A C sachindr...@gmail.com wrote:
@balaji, the memory allocated from the heap using malloc needs to be
released before termination of the program. there should be two additional
btw, i didn't understand the reason/motive behind this question? was
it some kind of test??
On Sat, Jun 18, 2011 at 11:45 AM, Harshal hc4...@gmail.com wrote:
compiler error?? if the void is replaced by int, ans=155.
On Sat, Jun 18, 2011 at 11:33 AM, Balaji S balaji.ceg...@gmail.com wrote:
@ Harshal, you are absolutely right. Again, this kind of code is
highly discouraged when used in real life projects. And there is no
need to go into details of how to evaluate such expressions, which are
not complying to standards.
On Wed, Jun 15, 2011 at 10:49 AM, Harshal hc4...@gmail.com wrote:
In 1st program, 2nd printf requires one more argument. And basically
%a is used for printing a double value in hex. see man 3 printf.
On Sat, Jun 11, 2011 at 5:29 PM, nicks crazy.logic.k...@gmail.com wrote:
Hello friends..plz help me in understanding the following C Output
first one is --
Following declaration makes the x as a volatile pointer to an integer.
int *volatile x;
But what does following means?
int **volatile x;
~Vishal
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to
Usually it is a bad practice to increment the pointer. Rather, one
should use the indexing variable to dereference the pointer at some
index. One more bug in your code was, you are allocating the space for
only 3 ints for p and storing 4 ints. Here is the code with some
modification.
#include
http://www.yolinux.com/TUTORIALS/GDB-Commands.html
this may help
On Sat, Jun 4, 2011 at 11:57 PM, nitish goyal nitishgoy...@gmail.com wrote:
@ saurabh singh
thanks
On Sat, Jun 4, 2011 at 11:44 PM, saurabh singh saurabh.n...@gmail.com
wrote:
Do man gdb
On Sat, Jun 4, 2011 at 11:20 PM,
can use fork() also..
On Fri, Jun 3, 2011 at 11:57 AM, anand karthik
anandkarthik@gmail.com wrote:
(!printf(Hello))
On Jun 3, 2011 11:52 AM, Arpit Mittal mrmittalro...@gmail.com wrote:
Please help me in this question.
What's the condition so that the following code prints both
:~/progs/c\ 12:12:06 PM $ ./a.out
hello world
On Fri, Jun 3, 2011 at 12:09 PM, Naveen Kumar
naveenkumarve...@gmail.com wrote:
Hi Vishal,
Can you show us how it be done with fork?
On Fri, Jun 3, 2011 at 12:02 PM, Vishal Thanki vishaltha...@gmail.com
wrote:
can use fork() also..
On Fri, Jun
On Fri, Jun 3, 2011 at 12:12 PM, Vishal Thanki vishaltha...@gmail.com
wrote:
vishal@ubuntu:~/progs/c\ 12:11:53 PM $ cat fork.c
#include stdio.h
#include stdlib.h
int main()
{
if (fork()) {
printf(hello );
} else {
printf(world\n
on console tty's driver takes whole line and output it
at once.
On Fri, Jun 3, 2011 at 12:40 PM, Vishal Thanki
vishaltha...@gmail.com
wrote:
@sachindra, @naveen,
this was just a plain trick to execute if and else block. i
agree
with your concerns :)
2011/6/3 Vιиodh vinodh
you may want to read: http://c-faq.com/expr/seqpoints.html
On Wed, Jun 1, 2011 at 5:19 PM, himanshu kansal
himanshukansal...@gmail.com wrote:
a=++b*++b;
if b=3 initially, then a is coming out to be 25.why
--
You received this message because you are subscribed to the Google Groups
#include stdio.h
int main()
{
int a[8] = {1,0,1,1,0,0,1,1};
int b[8] = {1,0,1,1,0,0,1,1};
int c[9] = {0};
int size = sizeof(a)/sizeof(a[0]);
int i;
int carry = 0;
for (i = size-1; i = 0; i--) {
if (a[i] b[i]) {
will
evaluate to false.
I may be wrong... plz help.
On May 28, 9:15 pm, Vishal Thanki vishaltha...@gmail.com wrote:
here is the code..
#define bi (i)
#define bj (GRID_SIZE+j)
#define bk (int)((GRID_SIZE*2)+(glb_sqrt*(i/glb_sqrt)+(j/glb_sqrt)))
/*glb_sqrt should be the square root of grid_size (i.e
will always
evaluate to false.
same thing will happen for every value in the matrix because the
corresponding bit has been set earlier.
so how is ur verification function working???
On May 29, 3:35 pm, Vishal Thanki vishaltha...@gmail.com wrote:
yes, you are right. bitmap will be filled
during the loop when i==5 and j==4, the if condition will always
evaluate to false.
same thing will happen for every value in the matrix because the
corresponding bit has been set earlier.
so how is ur verification function working???
On May 29, 3:35 pm, Vishal Thanki vishaltha...@gmail.com
a 0.08f will make it compare to float. by default 0.08 is
considered as double.
On Sun, May 29, 2011 at 9:51 PM, Ankit Agarwal ankitgeniu...@gmail.com wrote:
#includestdio.h
int main(void)
{
float a=0.08;
if(a0.08)
printf(Hello\n);
else
printf(Hii\n);
you may want to check how the floats and doubles are stored into
memory using ieee notation.
i tried to print 0.08 and 0.08f in hex format and got the following result.
vishal@ubuntu:~/progs/c\ 10:03:56 AM $ cat fl.c
#include stdio.h
int main()
{
float f=0.08;
if (f 0.08f)
what about using a hash function?
On Mon, May 30, 2011 at 10:18 AM, ross jagadish1...@gmail.com wrote:
Given a matrix, you need to find the number of blocks in it.
A block has the same numbers.
EG:
1 1 3
1 2 3
2 2 4
has 4 blocks namely,
1 1
1
2
2 2
3
3
4
1 2 3
4 5 6
7 8 9
not sure what will be the
most efficient data structure to implement this in c/c++.
Vishal
On Mon, May 30, 2011 at 10:31 AM, ross jagadish1...@gmail.com wrote:
@vishal
Hi,
I do not get you.
Can you please elaborate a little more how you ll use hash?
On May 30, 8:50 am, Vishal Thanki
@anshu, i got you. my bad!!
On Mon, May 30, 2011 at 10:49 AM, anshu mishra
anshumishra6...@gmail.com wrote:
@vishal ur sol wil give wrong answer for this
1 1 2
1 3 1
2 3 4
answer should be 6 but ur sol wil give 4.
--
You received this message because you are subscribed to the Google
here is the code..
#define bi (i)
#define bj (GRID_SIZE+j)
#define bk (int)((GRID_SIZE*2)+(glb_sqrt*(i/glb_sqrt)+(j/glb_sqrt)))
/*glb_sqrt should be the square root of grid_size (i.e. 3 if its a 9x9
sudoku). */
/* #define bk (int)((GRID_SIZE*2)+(5*(i/5)+(j/5))) */
/*
* This function will
];
}
}
}
}
Need not to mention that marix[][] is the 2-D array to represent sudoku grid.
On Sat, May 28, 2011 at 9:45 PM, Vishal Thanki vishaltha...@gmail.com wrote:
here is the code..
#define bi (i)
#define bj (GRID_SIZE+j)
#define bk (int)((GRID_SIZE*2)+(glb_sqrt*(i/glb_sqrt)+(j/glb_sqrt
53 matches
Mail list logo