blob: aae0f644828c323866fc1a25ca2181eb9377958f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
TASK #1 - 10001st Prime Number
Write a script to generate the 10001st prime number.
(Remember that 2 is the 1st prime number).
MY NOTES: Very easy, especially (tada) if you happen to have a prime
generating module that you've already used several times in these
challenges..
TASK #2 - Curious Fraction Tree
Consider the following Curious Fraction Tree:
[diagram in which the root is 1/1, and for each element N/D
it's right child is N+D/D, and it's left child is N/N+D]
You are given a N/D member of the tree created similar to the above sample.
Write a script to find out the parent and grandparent of the given member.
Example 1:
Input: $member = '3/5';
Output: parent = '3/2' and grandparent = '1/2'
Example 2:
Input: $member = '4/3';
Output: parent = '1/3' and grandparent = '1/2'
MY NOTES: hmm.. having determined the left and right child rules
above, I worked out that given a child N/D the parent rule is
"if D>N then (N, D-N) else (N-D, D)"
So very easy using that rule twice (and why not go all the way up to
the root while we're doing it).
|