Be a Supporter!

Guess the output

  • 349 Views
  • 7 Replies
New Topic Respond to this Topic
Pecos
Pecos
  • Member since: Dec. 29, 1999
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Guess the output 2001-10-05 16:04:33 Reply

Any language, any type of algorithm.. post it and guess at others.. I'll start:

Java:
for (int i=0;i<(new Date()).getMonth();i++) {
System.out.print(i/2);
}

liljim
liljim
  • Member since: Dec. 16, 1999
  • Offline.
Forum Stats
Staff
Level 28
Blank Slate
Response to Guess the output 2001-10-06 08:33:24 Reply

At 10/5/01 04:04 PM, UnclePecos wrote: Any language, any type of algorithm.. post it and guess at others.. I'll start:

Java:
for (int i=0;i<(new Date()).getMonth();i++) {
System.out.print(i/2);
}

Hmmm. At a guess, this would print something like:
0
0.5
1
... intervals of 0.5 up to
4.5

(assuming that the month is October).

At least, I think that's how it would work (with my complete lack of knowledge with Java).....

Pecos
Pecos
  • Member since: Dec. 29, 1999
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to Guess the output 2001-10-07 20:08:11 Reply

At 10/6/01 08:33 AM, liljim wrote: Hmmm. At a guess, this would print something like:
0
0.5
1
... intervals of 0.5 up to
4.5

(assuming that the month is October).

At least, I think that's how it would work (with my complete lack of knowledge with Java).....

Nope! Any other guesses?

LordAba
LordAba
  • Member since: Nov. 2, 2000
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to Guess the output 2001-10-07 23:06:08 Reply

At 10/7/01 08:08 PM, UnclePecos wrote:
At 10/6/01 08:33 AM, liljim wrote: Hmmm. At a guess, this would print something like:
0
0.5
1
... intervals of 0.5 up to
4.5

(assuming that the month is October).

At least, I think that's how it would work (with my complete lack of knowledge with Java).....
Nope! Any other guesses?

Either it wouldn't work, or it'll print out lilJim's answer, only all on one line.


What may man within him hide, though angel on the outward side.

BBS Signature
LordAba
LordAba
  • Member since: Nov. 2, 2000
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to Guess the output 2001-10-07 23:22:34 Reply

What does this function do in C++?

static int comp(const void *a, const void *b)
{
return strcmp(*(char **)a, *(char **)b);
}


What may man within him hide, though angel on the outward side.

BBS Signature
Pecos
Pecos
  • Member since: Dec. 29, 1999
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to Guess the output 2001-10-08 11:36:20 Reply

At 10/7/01 11:06 PM, Lord_Aba wrote: Either it wouldn't work, or it'll print out lilJim's answer, only all on one line.

Wrong!

Yes, it would print it out all on one line, but the numbers would be different. First of all, division ignores the remainder and only returns integers. So the output would be 001122.. and so on.

and Date.getMonth() would return the current month number - 1, or 9.

Pecos
Pecos
  • Member since: Dec. 29, 1999
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to Guess the output 2001-10-08 11:44:39 Reply

At 10/7/01 11:22 PM, Lord_Aba wrote: What does this function do in C++?

static int comp(const void *a, const void *b)
{
return strcmp(*(char **)a, *(char **)b);
}

Pointers to a and b are casted to char pointers and compaired as to which one is smaller or comes first in alphabetical order. But I'm not so sure that an int is returned, perhaps it's a bool.

My C++ is a bit rusty, so maybe I'm a little off... I don't know why void is used in the parameters being passed in either... o_O

RancidScammerDude
RancidScammerDude
  • Member since: Jul. 27, 2001
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to Guess the output 2001-10-21 01:13:49 Reply

Hmm, I cant teach html in BBS with out it messin up..