All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Algorithms
Golden Ratio Gradation (Posted on 2022-01-27) Difficulty: 3 of 5
Devise an algorithm for writing any positive base ten integer in base φ number system.
**** φ, called the Golden Ratio is a positive real number equal to (1+√5)/2

See The Solution Submitted by K Sengupta    
Rating: 5.0000 (1 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
soln | Comment 1 of 4
I am withdrawing my solution because I realize I 
don't know how to write numbers in a real base system
(as opposed to writing in an integer base system). E.g. what is the range of the digit in any decimal place.

Later: nope - my algorithm is correct. Here is my original post  verbatim:

Call alpha "a"

Algorithm to express integer N as a real number in base a: 
Call epsilon the maximum remainder allowed

Define i, the index of the number of decimal places to the left of the decimal place: i = 0,1,2,3...
and to the right of the decimal place: i=-1, -2, -3. e.g., 67.8 has 6 at i=1, 7 at i=0, and 8 at i=-1.  

Define D_i as the integer digit to be written at decimal place i

1) Calculate x, the log base a of N

x  = log_a N = log_10 N / log_10 a 
(this follows from taking the common log of both sides of N = x^a)

Define I as the integer part of x 
Initialize N_old = N

Loop with i go I, I-1, I-2, I-2 ...  until |N_old| <  epsilon
D_i = integer part of N_old / a^i
N_old <-- N_old - D(i) a^i
End of Loop

I discovered I actually had the answer right. I just got spooked

by the ones!


Added even later: I attempted to implement my algoritm in code, and ran into the same roundoff problems as discussed by Charlie and Larry. But I chose not to solve them because the algorithm itself is still correct. Implementing it is difficult, but that's now a computer limitation, not an algorithm problem. 

Edited on January 29, 2022, 2:05 am
  Posted by Steven Lord on 2022-01-27 09:46:31

Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (2)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information