Andrew Cooke | Contents | Latest | RSS | Previous | Next

C[omp]ute

Welcome to my blog, which was once a mailing list of the same name and is still generated by mail. Please reply via the "comment" links.

Always interested in offers/projects/new ideas. Eclectic experience in fields like: numerical computing; Python web; Java enterprise; functional languages; GPGPU; SQL databases; etc. Based in Santiago, Chile; telecommute worldwide. CV; email.

Personal Projects

Choochoo Training Diary

Last 100 entries

Surprise Paradox; [Books] Good Author List; [Computing] Efficient queries with grouping in Postgres; [Computing] Automatic Wake (Linux); [Computing] AWS CDK Aspects in Go; [Bike] Adidas Gravel Shoes; [Computing, Horror] Biological Chips; [Books] Weird Lit Recs; [Covid] Extended SIR Models; [Art] York-based Printmaker; [Physics] Quantum Transitions are not Instantaneous; [Computing] AI and Drum Machines; [Computing] Probabilities, Stopping Times, Martingales; bpftrace Intro Article; [Computing] Starlab Systems - Linux Laptops; [Computing] Extended Berkeley Packet Filter; [Green] Mainspring Linear Generator; Better Approach; Rummikub Solver; Chilean Poetry; Felicitations - Empowerment Grant; [Bike] Fixing Spyre Brakes (That Need Constant Adjustment); [Computing, Music] Raspberry Pi Media (Audio) Streamer; [Computing] Amazing Hack To Embed DSL In Python; [Bike] Ruta Del Condor (El Alfalfal); [Bike] Estimating Power On Climbs; [Computing] Applying Azure B2C Authentication To Function Apps; [Bike] Gearing On The Back Of An Envelope; [Computing] Okular and Postscript in OpenSuse; There's a fix!; [Computing] Fail2Ban on OpenSuse Leap 15.3 (NFTables); [Cycling, Computing] Power Calculation and Brakes; [Hardware, Computing] Amazing Pockit Computer; Bullying; How I Am - 3 Years Post Accident, 8+ Years With MS; [USA Politics] In America's Uncivil War Republicans Are The Aggressors; [Programming] Selenium and Python; Better Walking Data; [Bike] How Fast Before Walking More Efficient Than Cycling?; [COVID] Coronavirus And Cycling; [Programming] Docker on OpenSuse; Cadence v Speed; [Bike] Gearing For Real Cyclists; [Programming] React plotting - visx; [Programming] React Leaflet; AliExpress Independent Sellers; Applebaum - Twilight of Democracy; [Politics] Back + US Elections; [Programming,Exercise] Simple Timer Script; [News] 2019: The year revolt went global; [Politics] The world's most-surveilled cities; [Bike] Hope Freehub; [Restaurant] Mama Chau's (Chinese, Providencia); [Politics] Brexit Podcast; [Diary] Pneumonia; [Politics] Britain's Reichstag Fire moment; install cairo; [Programming] GCC Sanitizer Flags; [GPU, Programming] Per-Thread Program Counters; My Bike Accident - Looking Back One Year; [Python] Geographic heights are incredibly easy!; [Cooking] Cookie Recipe; Efficient, Simple, Directed Maximisation of Noisy Function; And for argparse; Bash Completion in Python; [Computing] Configuring Github Jekyll Locally; [Maths, Link] The Napkin Project; You can Masquerade in Firewalld; [Bike] Servicing Budget (Spring) Forks; [Crypto] CIA Internet Comms Failure; [Python] Cute Rate Limiting API; [Causality] Judea Pearl Lecture; [Security, Computing] Chinese Hardware Hack Of Supermicro Boards; SQLAlchemy Joined Table Inheritance and Delete Cascade; [Translation] The Club; [Computing] Super Potato Bruh; [Computing] Extending Jupyter; Further HRM Details; [Computing, Bike] Activities in ch2; [Books, Link] Modern Japanese Lit; What ended up there; [Link, Book] Logic Book; Update - Garmin Express / Connect; Garmin Forerunner 35 v 230; [Link, Politics, Internet] Government Trolls; [Link, Politics] Why identity politics benefits the right more than the left; SSH Forwarding; A Specification For Repeating Events; A Fight for the Soul of Science; [Science, Book, Link] Lost In Math; OpenSuse Leap 15 Network Fixes; Update; [Book] Galileo's Middle Finger; [Bike] Chinese Carbon Rims; [Bike] Servicing Shimano XT Front Hub HB-M8010; [Bike] Aliexpress Cycling Tops; [Computing] Change to ssh handling of multiple identities?; [Bike] Endura Hummvee Lite II; [Computing] Marble Based Logic; [Link, Politics] Sanity Check For Nuclear Launch; [Link, Science] Entropy and Life

© 2006-2017 Andrew Cooke (site) / post authors (content).

Fibonacci Numbers

From: "andrew cooke" <andrew@...>

Date: Thu, 19 Jan 2006 18:41:44 -0300 (CLST)

Ha.  Finally something to make me smile after an extremely crappy couple
of days...

I was intrigued by this comment -
http://blogs.msdn.com/code4bill/archive/2005/12/20/505872.aspx - which
refers to the puzzle here -
http://www.microsoft.com/india/code4bill/archives/19_24_dec05.aspx (bottom
of page).

The idea is that you can (completely arbitrarily) assign the weights for a
"binary" digit to be 1,2,3,5,8,13,21... instead of 1,2,4,8,16,32,64,...
where those numbers are from the Fibonacci sequence (each number is the
sum of the previous two; for some reason the initial 0,1 are ignored).

Now since those numbers don't go up as quickly as 2^n you get ambiguities
(duplications?).  The first is 3, which is both 001 and 11 (low bits to
the left).

So.... I downloaded PLT scheme - http://www.plt-scheme.org/ - for no
particular reason except that I was bored with Python and started playing
around.  It took me a while to remember my (flaky) Lisp, but eventually I
got to the point where I had some working code, albeit not very elegant.

First thing I defined was an increment method that takes one of these
numbers and adds 1 to the binary part (see end of post).  Then I plotted
the "fibonacci" values against the "binary" values.  I can't post images
to this blog, but this wasn't that interesting anyway - although it did
appear to be fractal (OK, so that's pretty cool I guess).

Next I plotted how many different representations there were for each
natural number.  That was a much prettier graph, reminding me vaguely of
number spiral - http://www.numberspiral.com/ (just because it was kind-of
pretty and with a lot more arcs/structure than I expected).

Finally - and this is what made me smile - I followed the hint in the post
I linked to first above and looked at the numbers with a single
representation.  Now, I may have a bug, but they appear to be:

  1, 2, 4, 7, 12, 20, 33, 54, 88

Stupid old me, looking at those, thought "bleagh".  Can you see the
pattern dear reader?  Well, despite it being totally obvious I cheated -
http://www.research.att.com/~njas/sequences/?q=1%2C2%2C4%2C7%2C12%2C20%2C33%2C54%2C88
- which tells you soon enough that they're either 1 less than the
Fibonacci series, or the sum of the first n Fibonacci numbers.  Ha!  Sweet
or what?

And.... then I thought, OK, so what was the binary?  At first I thought
"OK, this is obvious - it's all 1s (since it's the sum, right?)".  But
it's not, because they threw away the first 1, remember?  (Check the
sequence above - it's the sums for 0, 1, 1, 2, 3, 5... but the problem
used 1, 2, 3, 5...)

So, any guesses?

I have no idea how this works, but here are some values (low bit to left):

  33 = 1 0 1 0 1 0 1
  54 = 0 1 0 1 0 1 0 1
  88 = 1 0 1 0 1 0 1 0 1

Heh.  Actually, as I type this, I do kind-of see how that works.  Given
that each value is already the sum of previous two...  Hmmm.

Andrew

PS Here's the increment code.  I represented each number by a pair of
lists - one list was the fibonacci numbers, the other was the binary
digits.  I have a strong suspicion this code could be much neater, but
can't see how (excuse the "I can write bad Haskell in any language"
style...):

  (define (increment fib-digits)
    (match fib-digits
      ; digit of zero is easy
      [((n . nn) . (0 . dd)) `((,n . ,nn) . (1 . ,dd))]
      ; for digit of 1 consider progressively longer series
      ; special case of singleton
      [((1) . (1)) '((1 2) . (0 1))]
      ; last two numbers - need to extend the fibonacci series
      [((n1 n2) . (1 1)) (cons (list n1 n2 (+ n1 n2)) '(0 0 1))]
      ; we have at least two more digits so recurse
      [((n . nn) . (1 . dd))
       (match-let (((nn2 . dd2) (increment `(,nn . ,dd))))
         `((,n . ,nn2) . (0 . ,dd2)))]))

Plots

From: "andrew cooke" <andrew@...>

Date: Fri, 20 Jan 2006 00:38:42 -0300 (CLST)

Couldn't resist it.  Here are the plots that I talk about above.

http://www.acooke.org/cgi/photo.py?start=fib-fractal - The plot of
Fibonacci v binary values for 100 and 10,000 points.  See the
self-similarity?

http://www.acooke.org/cgi/photo.py?start=fib-curves - The plot of the
number of equivalent values for the first 10,000 points.  Lots of
structure!

Andrew

Comment on this post