Andrew Cooke | Contents | Latest | RSS | Twitter | 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

Lepl parser for Python.

Colorless Green.

Photography around Santiago.

SVG experiment.

Professional Portfolio

Calibration of seismometers.

Data access via web services.

Cache rewrite.

Extending OpenSSH.

C-ORM: docs, API.

Last 100 entries

[Link, Programming] MySQL UTF8 Broken; NCOA for $20; [Link, Books] Latin American Authors; [Link, Computing] Optimizatin Puzzle; [Link, Books, Politics] Orwell Prize; [Link] What the Hell Is Happening With Qatar?; [Link] Deep Learning + Virtual Tensor Machines; [Link] Scaled Composites: Largest Wingspan Ever; [Link] SCP Foundation; [Bike] Lessons From 2 Leading 2 Trailing; [Link] Veg Restaurants in Santiago; [Link] List of Contemporary Latin American Authors; [Bike] FTHR; [Link] Whoa - NSA Reduces Collection (of US Residents); [Link] Red Bull's Breitbart; [Link] Linux Threads; [Link] Punycode; [Link] Bull / Girl Statues on Wall Street; [Link] Beautiful Chair Video; Update: Lower Pressures; [Link] Neat Python Exceptions; [Link] Fix for Windows 10 to Avoid Ads; [Link] Attacks on ZRTP; [Link] UK Jazz Invasion; [Review] Cuba; [Link] Aricle on Gender Reversal of US Presidential Debate; {OpenSuse] Fix for Network Offline in Updater Applet; [Link] Parkinson's Related to Gut Flora; Farellones Bike Park; [Meta] Tags; Update: Second Ride; Schwalbe Thunder Burt 2.1 v Continental X-King 2.4; Mountain Biking in Santiago; Books on Ethics; Security Fail from Command Driven Interface; Everything Old is New Again; Interesting Take on Trump's Lies; Chutney v6; References on Entropy; Amusing "Alexa.." broadcast; The Shame of Chile's Education System; Playing mp4 gifs in Firefox on Opensuses Leap 42.2; Concurrency at Microsoft; Globalisation: Uk -> Chile; OpenSuse 42.2 and Synaptics Touch-Pads; Even; Cherry Jam; Lebanese Writer Amin Maalouf; C++ - it's the language of the future; Learning From Trump; Chinese Writer Hu Fayun; And; Apricot Jam; Also; Excellent Article on USA Politics; Oh Metafilter; Prejudice Against The Rurals; Also, Zizek; Trump; Why Trump Won; Doxygen + Latex on CentOS 6; SMASH - Solve 5 Biggest Problems in Physics; Good article on racism, brexit, and social divides; Grandaddy are back!; Consciousness From Max Entropy; Democrats; Harvard Will Fix Black Poverty; Modelling Bicycle Wheels; Amusing Polling Outlier; If Labour keeps telling working class people...; Populism and Choice; Books on Defeat; Enrique Ferrari - Argentine Author; Transcript of German Scientists on Learning of Hiroshima; Calvert Journal; Owen Jones on Twitter; Possible Japanese Authors; Complex American Literature; Chutney v5; Weird Componentized Virus; Interesting Argentinian Author - Antonio Di Benedetto; Useful Thread on MetaPhysics; RAND on fighting online anarchy (2001); NSA Hacked; Very Good LRB Article on Brexit; Nussbaum on Anger; Tasting; Apple + Kiwi Jam; Hit Me; Sudoku - CSP + Chaos; Recycling Electronics In Santiago; Vector Displays in OpenGL; And Anti-Aliased; OpenGL - Render via Intermediate Texture; And Garmin Connect; Using Garmin Forerunner 230 With Linux; (Beating Dead Horse) StackOverflow; Current State of Justice in China; Axiom of Determinacy; Ewww; Fee Chaos Book

© 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

[Fwd: Re: [OT] Programming humour; was Re: [pragprog] Re: demographics (notC rules and idioms)]

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

Date: Sat, 11 Feb 2006 08:48:09 -0300 (CLST)

---------------------------- Original Message ----------------------------
Subject: Re: [OT] Programming humour;      was Re: [pragprog] Re:
demographics  (notC rules and idioms)
From:    "Mathieu Bouchard" <matju@...
Date:    Sat, February 11, 2006 07:40
To:      pragprog@...
--------------------------------------------------------------------------

On Sat, 11 Feb 2006, andrew cooke wrote:

> also, "fibonacci number system", with digits 0,1 and weights
> 1,2,3,5,8,13,21...  where most natural numbers have more than one
> representation.  for example, 5 is 011 or 0001 (written here with least
> significant digit to left).
> for more info - http://www.acooke.org/cute/FibonacciN0.html

You can avoid all duplications by disallowing a "1" from following exactly
a "1". In short, in all of the possible representations of a given number,
only one does not contain two ones in a row.

What's bad with that scheme is that it can't cover fractions between 0 and
1 because there's no sensible continuation of fibonacci to the left of the
sequence that could involve fractions. The base closest to fibonacci's
that can support real numbers would be base 1.618033989... that number is
the main root of x^2-x-1 and is commonly known as the golden ratio.

 _ _ __ ___ _____ ________ _____________ _____________________ ...
| Mathieu Bouchard - tél:+1.514.383.3801 - http://artengine.ca/matju
| Freelance Digital Arts Engineer, Montréal QC Canada

Comment on this post