Author |
Message |
Bak ?ls -s 0 in
![](images/avatars/404997118f1ce7de4ddd04696735dba8452b42d283d73.png)
Age:24 Gender:![Gender:Male Gender:Male](templates/subSilver/images/icon_minigender_male.gif) Joined: Jun 11 2004 Posts: 1826 Location: USA Offline
|
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Dr Brain Flip-flopping like a wind surfer
![](images/avatars/a2335e2a6dbdf0ede075c3c849fb2440483075badbafe.png)
Age:38 Gender:![Gender:Male Gender:Male](templates/subSilver/images/icon_minigender_male.gif) Joined: Dec 01 2002 Posts: 3502 Location: Hyperspace Offline
|
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Bak ?ls -s 0 in
![](images/avatars/404997118f1ce7de4ddd04696735dba8452b42d283d73.png)
Age:24 Gender:![Gender:Male Gender:Male](templates/subSilver/images/icon_minigender_male.gif) Joined: Jun 11 2004 Posts: 1826 Location: USA Offline
|
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Dr Brain Flip-flopping like a wind surfer
![](images/avatars/a2335e2a6dbdf0ede075c3c849fb2440483075badbafe.png)
Age:38 Gender:![Gender:Male Gender:Male](templates/subSilver/images/icon_minigender_male.gif) Joined: Dec 01 2002 Posts: 3502 Location: Hyperspace Offline
|
Posted: Wed Aug 05, 2009 1:27 pm Post subject: |
![Reply to topic](templates/subSilver/images/lang_english/reply_mini.gif) |
|
|
|
s
The brackets don't care about order, so 1["dr brain"] is the same as "dr brain"[1], so that whole expression is 'r'+1 or 's'. |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Bak ?ls -s 0 in
![](images/avatars/404997118f1ce7de4ddd04696735dba8452b42d283d73.png)
Age:24 Gender:![Gender:Male Gender:Male](templates/subSilver/images/icon_minigender_male.gif) Joined: Jun 11 2004 Posts: 1826 Location: USA Offline
|
Posted: Thu Aug 06, 2009 9:22 am Post subject: |
![Reply to topic](templates/subSilver/images/lang_english/reply_mini.gif) |
|
|
|
Challenge #3: Write a program that only prints "dr brain won #2" and has exit code 100 when the process terminates. Don't use any semicolons. |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Doc Flabby Server Help Squatter
![](images/avatars/83937e54210839e99d3dd9f7e45c078345acd78649eaa.png)
Joined: Feb 26 2006 Posts: 636 Offline
|
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Samapico No, these DO NOT look like penises, ok?
![](images/avatars/fe2cb2afc48e5b6adff2cbb0b8f4be4244e1d8a6eec26.png)
Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Thu Aug 06, 2009 10:22 am Post subject: |
![Reply to topic](templates/subSilver/images/lang_english/reply_mini.gif) |
|
|
|
That doesn't compile... return requires a ;
in VS anyway _________________ (Insert a bunch of dead links here) |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Samapico No, these DO NOT look like penises, ok?
![](images/avatars/fe2cb2afc48e5b6adff2cbb0b8f4be4244e1d8a6eec26.png)
Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Thu Aug 06, 2009 10:23 am Post subject: |
![Reply to topic](templates/subSilver/images/lang_english/reply_mini.gif) |
|
|
|
I'd do something like
if ( exit( printf("dr brain won #2")+85 ) )
{
}
But exit returns a void, so it doesn't compile either |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Dr Brain Flip-flopping like a wind surfer
![](images/avatars/a2335e2a6dbdf0ede075c3c849fb2440483075badbafe.png)
Age:38 Gender:![Gender:Male Gender:Male](templates/subSilver/images/icon_minigender_male.gif) Joined: Dec 01 2002 Posts: 3502 Location: Hyperspace Offline
|
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Samapico No, these DO NOT look like penises, ok?
![](images/avatars/fe2cb2afc48e5b6adff2cbb0b8f4be4244e1d8a6eec26.png)
Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Thu Aug 06, 2009 11:10 am Post subject: |
![Reply to topic](templates/subSilver/images/lang_english/reply_mini.gif) |
|
|
|
+ 100 - 16 ? lol |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Dr Brain Flip-flopping like a wind surfer
![](images/avatars/a2335e2a6dbdf0ede075c3c849fb2440483075badbafe.png)
Age:38 Gender:![Gender:Male Gender:Male](templates/subSilver/images/icon_minigender_male.gif) Joined: Dec 01 2002 Posts: 3502 Location: Hyperspace Offline
|
Posted: Thu Aug 06, 2009 11:44 am Post subject: |
![Reply to topic](templates/subSilver/images/lang_english/reply_mini.gif) |
|
|
|
I had to add a \n at the end because zsh freaks out if it's missing, so it was 16 instead of 15. |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Samapico No, these DO NOT look like penises, ok?
![](images/avatars/fe2cb2afc48e5b6adff2cbb0b8f4be4244e1d8a6eec26.png)
Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Thu Aug 06, 2009 11:59 am Post subject: |
![Reply to topic](templates/subSilver/images/lang_english/reply_mini.gif) |
|
|
|
...
My point was, + 84 would be simpler
Though I can see the why... but still |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Hakaku Server Help Squatter
![](images/avatars/9120dd93f5e5f7e24bdbaff18d563ad6451870d9316b9.png)
Joined: Apr 07 2006 Posts: 299 Location: Canada Offline
|
Posted: Thu Aug 06, 2009 2:44 pm Post subject: |
![Reply to topic](templates/subSilver/images/lang_english/reply_mini.gif) |
|
|
|
Samapico wrote: | I'd do something like
if ( exit( printf("dr brain won #2")+85 ) )
{
}
But exit returns a void, so it doesn't compile either |
Couldn't you just put this in a while loop instead? As in (not sure if the 1 should go before or after)...
while (exit( printf("dr brain won #2\n")+84 ), 1)
{
}
edit: + \n
Last edited by Hakaku on Thu Aug 06, 2009 2:55 pm, edited 1 time in total |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Dr Brain Flip-flopping like a wind surfer
![](images/avatars/a2335e2a6dbdf0ede075c3c849fb2440483075badbafe.png)
Age:38 Gender:![Gender:Male Gender:Male](templates/subSilver/images/icon_minigender_male.gif) Joined: Dec 01 2002 Posts: 3502 Location: Hyperspace Offline
|
Posted: Thu Aug 06, 2009 2:55 pm Post subject: |
![Reply to topic](templates/subSilver/images/lang_english/reply_mini.gif) |
|
|
|
Yes, the comma operator was the missing piece of the puzzle. I'd completely forgotten that it existed. Kudos for a more elegant solution. |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Initrd.gz Seasoned Helper
Joined: Sep 18 2008 Posts: 134 Location: Over there ---> Offline
|
Posted: Thu Aug 06, 2009 9:40 pm Post subject: |
![Reply to topic](templates/subSilver/images/lang_english/reply_mini.gif) |
|
|
|
Cuz just maybe we don't want to use semicolons in C ![biggrin.gif](images/smiles/biggrin.gif) |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Bak ?ls -s 0 in
![](images/avatars/404997118f1ce7de4ddd04696735dba8452b42d283d73.png)
Age:24 Gender:![Gender:Male Gender:Male](templates/subSilver/images/icon_minigender_male.gif) Joined: Jun 11 2004 Posts: 1826 Location: USA Offline
|
Posted: Thu Aug 06, 2009 11:21 pm Post subject: |
![Reply to topic](templates/subSilver/images/lang_english/reply_mini.gif) |
|
|
|
yeah comma operator was the trick, although pthread version was pretty original, i'll post next one in a little bit
if (printf("dr brain won #2"), exit(100), 0) {} |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Bak ?ls -s 0 in
![](images/avatars/404997118f1ce7de4ddd04696735dba8452b42d283d73.png)
Age:24 Gender:![Gender:Male Gender:Male](templates/subSilver/images/icon_minigender_male.gif) Joined: Jun 11 2004 Posts: 1826 Location: USA Offline
|
Posted: Thu Aug 06, 2009 11:38 pm Post subject: |
![Reply to topic](templates/subSilver/images/lang_english/reply_mini.gif) |
|
|
|
Challenge #4: What's the following code print and why:
#include <stdio.h>
int i(int i, int ii)
{
return ii == i;
}
int main()
{
int (*ii)(int, int) = i;
int i = 0;
if (i++ == ++i)
printf("%i", i + 1);
else
printf("%i", i);
if (ii(i++, ++i))
printf("%i", i + 1);
else
printf("%i", i);
if (ii(++i, i))
printf("%i", i + 1);
else
printf("%i", i);
return 0;
} |
|
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Samapico No, these DO NOT look like penises, ok?
![](images/avatars/fe2cb2afc48e5b6adff2cbb0b8f4be4244e1d8a6eec26.png)
Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Thu Aug 06, 2009 11:49 pm Post subject: |
![Reply to topic](templates/subSilver/images/lang_english/reply_mini.gif) |
|
|
|
Never seen that comma operator... well... except in a for statement...
So basically, the value returned by the whole expression is the result of the part after the last comma?
And holy shit, that's a lot of i's |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Samapico No, these DO NOT look like penises, ok?
![](images/avatars/fe2cb2afc48e5b6adff2cbb0b8f4be4244e1d8a6eec26.png)
Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Fri Aug 07, 2009 12:00 am Post subject: |
![Reply to topic](templates/subSilver/images/lang_english/reply_mini.gif) |
|
|
|
hmm... ii would be a pointer to the function...
i++ == ++i
would be false, and increments i twice...
> 2
you call ii with (2, 3), which returns false, i becomes 4
> 4
you call ii with ... I guess it depends in which order arguments are evaluated. ......... hmmmmm hold on a second. I think they're evaluated in reverse order... which means my past reasoning doesn't work.
The first if block is fine...
>2
the next one...
i = 2
second argument evaluated first, gives 3, then first argument, gives 3 also; i becomes 4 after
so... it returns true
> 5
now i = 4
you call ii with (5, 4) -> false
> 5
So...
output:
> 255 |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Bak ?ls -s 0 in
![](images/avatars/404997118f1ce7de4ddd04696735dba8452b42d283d73.png)
Age:24 Gender:![Gender:Male Gender:Male](templates/subSilver/images/icon_minigender_male.gif) Joined: Jun 11 2004 Posts: 1826 Location: USA Offline
|
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Samapico No, these DO NOT look like penises, ok?
![](images/avatars/fe2cb2afc48e5b6adff2cbb0b8f4be4244e1d8a6eec26.png)
Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Fri Aug 07, 2009 2:30 pm Post subject: |
![Reply to topic](templates/subSilver/images/lang_english/reply_mini.gif) |
|
|
|
So did I get it or not? ![tongue.gif](images/smiles/tongue.gif) |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Bak ?ls -s 0 in
![](images/avatars/404997118f1ce7de4ddd04696735dba8452b42d283d73.png)
Age:24 Gender:![Gender:Male Gender:Male](templates/subSilver/images/icon_minigender_male.gif) Joined: Jun 11 2004 Posts: 1826 Location: USA Offline
|
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
JoWie Server Help Squatter
Gender:![Gender:Male Gender:Male](templates/subSilver/images/icon_minigender_male.gif) Joined: Feb 25 2004 Posts: 215 Offline
|
Posted: Fri Aug 07, 2009 5:28 pm Post subject: |
![Reply to topic](templates/subSilver/images/lang_english/reply_mini.gif) |
|
|
|
void swap(int* a, int* b)
{
*a ^= (*b ^= (*a ^= *b));
}
|
assuming a != b
or (safe but lame version)
void swap(int* a, int* b)
{
#define lol ;
int temp = *a lol
*a = *b lol
*b = temp lol
}
|
|
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Bak ?ls -s 0 in
![](images/avatars/404997118f1ce7de4ddd04696735dba8452b42d283d73.png)
Age:24 Gender:![Gender:Male Gender:Male](templates/subSilver/images/icon_minigender_male.gif) Joined: Jun 11 2004 Posts: 1826 Location: USA Offline
|
Posted: Fri Aug 07, 2009 6:41 pm Post subject: |
![Reply to topic](templates/subSilver/images/lang_english/reply_mini.gif) |
|
|
|
can you do it without assuming a != b?
lol@lame version too |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Doc Flabby Server Help Squatter
![](images/avatars/83937e54210839e99d3dd9f7e45c078345acd78649eaa.png)
Joined: Feb 26 2006 Posts: 636 Offline
|
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
|