| 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.

Last 100 entries

Interesting (But Largely Illegible) Typeface; Retiring Essentialism; Poorest in UK, Poorest in N Europe; I Want To Be A Redneck!; Reverse Racism; The Lost Art Of Nomography; IBM Data Center (Photo); Interesting Account Of Gamma Hack; The Most Interesting Audiophile In The World; How did the first world war actually end?; Ky - Restaurant Santiago; The Black Dork Lives!; The UN Requires Unaninmous Decisions; LPIR - Steganography in Practice; How I Am 6; Clear Explanation of Verizon / Level 3 / Netflix; Teenage Girls; Formalising NSA Attacks; Switching Brakes (Tektro Hydraulic); Naim NAP 100 (Power Amp); AKG 550 First Impressions; Facebook manipulates emotions (no really); Map Reduce "No Longer Used" At Google; Removing RAID metadata; New Bike (Good Bike Shop, Santiago Chile); Removing APE Tags in Linux; Compiling Python 3.0 With GCC 4.8; Maven is Amazing; Generating Docs from a GitHub Wiki; Modular Shelves; Bash Best Practices; Good Emergency Gasfiter (Santiago, Chile); Readings in Recent Architecture; Roger Casement; Integrated Information Theory (Or Not); Possibly undefined macro AC_ENABLE_SHARED; Update on Charges; Sunburst Visualisation; Spectral Embeddings (Distances -> Coordinates); Introduction to Causality; Filtering To Help Colour-Blindness; ASUS 1015E-DS02 Too; Ready Player One; Writing Clear, Fast Julia Code; List of LatAm Novels; Running (for women); Building a Jenkins Plugin and a Jar (for Command Line use); Headphone Test Recordings; Causal Consistency; The Quest for Randomness; Chat Wars; Real-life Financial Co Without ACID Database...; Flexible Muscle-Based Locomotion for Bipedal Creatures; SQL Performance Explained; The Little Manual of API Design; Multiple Word Sizes; CRC - Next Steps; FizzBuzz; Update on CRCs; Decent Links / Discussion Community; Automated Reasoning About LLVM Optimizations and Undefined Behavior; A Painless Guide To CRC Error Detection Algorithms; Tests in Julia; Dave Eggers: what's so funny about peace, love and Starship?; Cello - High Level C Programming; autoreconf needs tar; Will Self Goes To Heathrow; Top 5 BioInformatics Papers; Vasovagal Response; Good Food in Vina; Chilean Drug Criminals Use Subsitution Cipher; Adrenaline; Stiglitz on the Impact of Technology; Why Not; How I Am 5; Lenovo X240 OpenSuse 13.1; NSA and GCHQ - Psychological Trolls; Finite Fields in Julia (Defining Your Own Number Type); Julian Assange; Starting Qemu on OpenSuse; Noisy GAs/TMs; Venezuela; Reinstalling GRUB with EFI; Instructions For Disabling KDE Indexing; Evolving Speakers; Changing Salt Size in Simple Crypt 3.0.0; Logarithmic Map (Moved); More Info; Words Found in Voynich Manuscript; An Inventory Of 3D Space-Filling Curves; Foxes Using Magnetic Fields To Hunt; 5 Rounds RC5 No Rotation; JP Morgan and Madoff; Ori - Secure, Distributed File System; Physical Unclonable Functions (PUFs); Prejudice on Reddit; Recursion OK; Optimizing Julia Code; Cash Handouts in Brazil; Couple Nice Music Videos; It Also Works!

© 2006-2013 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