hacker.org Forum Index
RegisterSearchFAQMemberlistUsergroupsLog in
Random Problem Challenge

 
Reply to topic    hacker.org Forum Index » Challenges View previous topic
View next topic
Random Problem Challenge
Author Message
kensie



Joined: 30 Jul 2008
Posts: 1

Post Random Problem Challenge Reply with quote
What should the format of the answer be? Just a number? also many numbers would throw an Exception which one will work?
Fri Feb 27, 2009 11:02 pm View user's profile Send private message
gfoot



Joined: 05 Sep 2007
Posts: 269
Location: Brighton, UK

Post Reply with quote
Just a number. I'm not a Java expert so I can't comment on how many numbers would throw an exception... but if the site is not accepting your answers, have you tried compiling the code and trying them out to make sure they really do throw exceptions?
Sat Feb 28, 2009 1:59 am View user's profile Send private message
sabretooth



Joined: 12 Jul 2009
Posts: 61

Post Reply with quote
I really don't understand this problem.

2147483647 is the max integer value in java - therefore this value and every possible value above this will cause an Exception. So why isnt it accepted? If you are looking for a 'specific' integer then the challenge should say so.

Any advice?

sabre
Tue Jul 21, 2009 8:31 pm View user's profile Send private message
gfoot



Joined: 05 Sep 2007
Posts: 269
Location: Brighton, UK

Post Reply with quote
It's asking specifically for a value for 'randomNumber', which is declared as an int, so your answer has to be a valid int. I don't think 2147483647 will cause an exception, so no, that's not the answer, and higher numbers are not valid ints, so they don't count as answers either.
Tue Jul 21, 2009 10:16 pm View user's profile Send private message
Theino



Joined: 15 Mar 2009
Posts: 8

Post Reply with quote
The answer is a valid int.

There is only one answer and thus only one valid int that would cause an exception.
Wed Jul 22, 2009 12:28 am View user's profile Send private message
sabretooth



Joined: 12 Jul 2009
Posts: 61

Post Reply with quote
Many thanks for the response Smile

sabre

edit - solved.

Thanks again Smile
Wed Jul 22, 2009 8:36 am View user's profile Send private message
General_Payne



Joined: 20 Jun 2011
Posts: 20

Post Struggling Reply with quote
Guessing there is some trick to this? Fairly sure i have run it for everything in the range -2147483647 to 2147483647 without an error

[Edit] -Scratch That. Was Being Retarded. Can't believe i spent over an hour on something so easy and obvious!!
Wed Dec 07, 2011 7:16 pm View user's profile Send private message
meis



Joined: 28 Aug 2012
Posts: 13
Location: Italy

Post Reply with quote
I've rewritten it in PHp to read it better (I'm more familiar with it).
So I have:
Code:
<?php
function bucketFromRandom($randomNumber) {
    $a = array();
   for ($i = 0; $i < 10; $i++)
      $a[$i] = $i * $randomNumber;
   $index = abs($randomNumber) % 10;
   return $a[$index];
}
echo bucketFromRandom(2147483648);
?>

Will it work in PHP too?
And what do I have to look for? I can't get it! But maybe i just don't understand what an exception is...
Sat Jun 01, 2013 3:16 pm View user's profile Send private message
Rat62



Joined: 23 Nov 2010
Posts: 17

Post Reply with quote
meis wrote:
I've rewritten it in PHp to read it better (I'm more familiar with it).
So I have:
Code:
<?php
...
?>

Will it work in PHP too?
...


Many challlenges on this site urge you to learn new things: Computer languages, cryptologic techniques, file formats.
This one is special to Java (and probably close relatives like C#). It won't work in PHP.
Wed Jun 05, 2013 2:30 pm View user's profile Send private message
Display posts from previous:    
Reply to topic    hacker.org Forum Index » Challenges All times are GMT
Page 1 of 1

 
Jump to: 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Design by Freestyle XL / Flowers Online.