Welcome to HBH! If you had an account on hellboundhacker.org you will need to reset your password using the Lost Password system before you will be able to login.

Timed 10: Why Four Numbers


ghost's Avatar
0 0

Timed 10 asks for the greatest common divisor of four integers. However, the GCD between any two of the given numbers is the GCD between all four. I can only assume this was unintentional because giving four numbers instead of two is merely a waste.

In order to force users to use more than their built in GCD library function (or the whole 5 lines, max, it takes to implement one) I would suggest having the GCD between the four numbers be different than the GCD amongst any two of the numbers. Thus, having the users think slightly beyond using predefined functions.


ynori7's Avatar
Future Emperor of Earth
0 0

Vty wrote: Timed 10 asks for the greatest common divisor of four integers. However, the GCD between any two of the given numbers is the GCD between all four. gcd(16, 24) = 8 gcd(16, 24, 36) = 4 gcd(16, 24, 36, 42) = 2

EDIT: Oh, I see you were referring to just the particular numbers given in the challenge, not in general. Well here are the numbers that were just generated by the challenge when I loaded it: 1660 6391 3984 8134 gcd(1660, 6391) = 83 gcd(1660, 8134) = 166 gcd(1660, 3984) = 332 gcd(8134, 6391) = 581


ghost's Avatar
0 0

Hmm, yes I see. Well I'm glad that's the case. I just tested it again and now after the third set I've seen, it was different for one set of numbers. It works as intended then - even though it could be a bit more random.

EDIT: I see you can simply pass more parameters to your built in GCD functions anyway. Shucks.


ynori7's Avatar
Future Emperor of Earth
0 0

Vty wrote: EDIT: I see you can simply pass more parameters to your built in GCD functions anyway. Shucks. That probably depends on the language. I wrote my own gcd function that accepts multiple parameters.


ghost's Avatar
0 0

Fair enough. I see a lot of the libraries for dealing with variable length numbers will do the same as well. Take BigInt in Perl for example.


ADIGA's Avatar
Member
0 0

is there a function in php for that!!! lol, did not know that!