Verminox

December 29th, 2006, 07:22 AM

It's time for the next weekly challenge and jayemef has picked me to set it up so here goes...

I've made this challenge by putting together 2-3 small ideas that I got because I thought they would be very simple individually.

The Task:

1. Reducing a fraction

(a) Your input will be a floating number. You have to convert it into fraction form and reduce the fraction in the form Numerator/Denominator in its lowest reducable form.

eg. Input: 0.3 ; Output: 3/10

eg. Input 1.8 ; Output: 9/5

(b) Same as above, but instead of a floating number you will given a numerator and denominator as input which is not in reduced form, you have to reduce it.

eg. Input: 121 99 ; Output: 11/9

The two are basically the same thing, but (a) requires converting a float to a fraction.... but in that case you always have a power of 10 as the denominator so part (b) will take care of generalizing it for all pairs of numerator/denominator.

2. The Prime Test

Since the above seemed simple, I decided to extend it a bit. Once you find the reduced fraction for either part (a) from a float or for part (b) from a given pair of Numerator and Denominator...... you have to check if the sum of the numerator and denominator is a prime number or not.

eg. If your fraction in reduced form is 3/10, the sum is 3+10 = 13 which is prime, but if the fraction is 11/9, then 11+9=20 is not prime. You have to output the boolean result.

I don't know if any language has any function built in for either of these... but for those who dont.... try not to get the help of external libraries for isPrime() functions, etc.

Not sure what the criteria will be for the winner (definitely not lines of code).... but optimized code (for runtime) and fewer dependencies on external libraries will score more points.

Cheers.

I've made this challenge by putting together 2-3 small ideas that I got because I thought they would be very simple individually.

The Task:

1. Reducing a fraction

(a) Your input will be a floating number. You have to convert it into fraction form and reduce the fraction in the form Numerator/Denominator in its lowest reducable form.

eg. Input: 0.3 ; Output: 3/10

eg. Input 1.8 ; Output: 9/5

(b) Same as above, but instead of a floating number you will given a numerator and denominator as input which is not in reduced form, you have to reduce it.

eg. Input: 121 99 ; Output: 11/9

The two are basically the same thing, but (a) requires converting a float to a fraction.... but in that case you always have a power of 10 as the denominator so part (b) will take care of generalizing it for all pairs of numerator/denominator.

2. The Prime Test

Since the above seemed simple, I decided to extend it a bit. Once you find the reduced fraction for either part (a) from a float or for part (b) from a given pair of Numerator and Denominator...... you have to check if the sum of the numerator and denominator is a prime number or not.

eg. If your fraction in reduced form is 3/10, the sum is 3+10 = 13 which is prime, but if the fraction is 11/9, then 11+9=20 is not prime. You have to output the boolean result.

I don't know if any language has any function built in for either of these... but for those who dont.... try not to get the help of external libraries for isPrime() functions, etc.

Not sure what the criteria will be for the winner (definitely not lines of code).... but optimized code (for runtime) and fewer dependencies on external libraries will score more points.

Cheers.