Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Problem 1897. GJam 2014 China Rd A: Rational Number Tree

Created by Richard Zapor

This Challenge is derived from GJam 2014 China Rational Number Tree.

The Goal is to determine the tree node if given [P,Q] or provide the [P,Q] if given a node. This is the small Challenge with a Max of 16 Tree levels. The large Challenge is 64 Tree levels.

Consider an infinite complete binary tree where the root node is 1/1 and the left and right childs of node P/Q are P/(P+Q) and (P+Q)/Q, respectively.

The Tree looks like:

         1/1
    ______|______
    |           |
   1/2         2/1
 ___|___     ___|___
 |     |     |     |
1/3   3/2   2/3   3/1

The nodes are 1/1, 1/2, 2/1, 1/3, 3/2, 2/3, 3/1,...

Input: [N] or [P,Q] where N is an integer node or [P,Q] are terms of a Node

Output: [P,Q] or [N] depends on Input type

Examples:

[Input]  [Output]
  [2] [1 2]
  [1 2] [2]
  [5] [3 2]
  [3 2] [5]

Contest Performance: Best Delta Time of 14 minutes with 1193 out of 3058 completing in less than 3 hours.

Tags

Problem Group

Solution Statistics

10 correct solutions 1 incorrect solutions
Last solution submitted on Apr 27, 2014

Problem Comments