| 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

Now Is Cat Soft LLC's Chance To Save Up To 32% On Mail; NSA Hacked; Call Center Services for Cat Soft LLC; Very Good LRB Article on Brexit; Nussbaum on Anger; Credit Card Processing for Cat Soft LLC; Discover new movies on demand in our online cinema; Tasting; Credit Card Processing for Cat Soft LLC; Apple + Kiwi Jam; Hit Me; Increase Efficiency with GPS Vehicle Tracking for Cat Soft LLC; Sudoku - CSP + Chaos; Recycling Electronics In Santiago; Vector Displays in OpenGL; Call Center Services for Cat Soft LLC; And Anti-Aliased; OpenGL - Render via Intermediate Texture; And Garmin Connect; Using Garmin Forerunner 230 With Linux; Payroll Service Quotes for Cat Soft LLC; (Beating Dead Horse) StackOverflow; Current State of Justice in China; Now Is Cat Soft LLC's Chance To Save Up To 32% On Mail; Axiom of Determinacy; Ewww; Fee Chaos Book; Course on Differential Geometry; Increase Efficiency with GPS Vehicle Tracking for Cat Soft LLC; Okay, but...; Sparse Matrices, Deep Learning; Sounds Bad; Applebaum Rape; Tomato Chutney v4; Have to add...; Culturally Liberal and Nothing More; Weird Finite / Infinite Result; Your diamond is a beaten up mess; Maths Books; Good Bike Route from Providencia / Las Condes to Panul\; Iain Pears (Author of Complex Plots); Plum Jam; Excellent; More Recently; For a moment I forgot StackOverflow sucked; A Few Weeks On...; Chilean Book Recommendations; How To Write Shared Libraries; Jenny Erpenbeck (Author); Dijkstra, Coins, Tables; Python libraries error on OpenSuse; Deserving Trump; And Smugness; McCloskey Economics Trilogy; cmocka - Mocks for C; Concept Creep (Americans); Futhark - OpenCL Language; Moved / Gone; Fan and USB issues; Burgers in Santiago; The Origin of Icosahedral Symmetry in Viruses; autoenum on PyPI; Jars Explains; Tomato Chutney v3; REST; US Elections and Gender: 24 Point Swing; PPPoE on OpenSuse Leap 42.1; SuperMicro X10SDV-TLN4F/F with Opensuse Leap 42.1; Big Data AI Could Be Very Bad Indeed....; Cornering; Postcapitalism (Paul Mason); Black Science Fiction; Git is not a CDN; Mining of Massive Data Sets; Rachel Kaadzi Ghansah; How great republics meet their end; Raspberry, Strawberry and Banana Jam; Interesting Dead Areas of Math; Later Taste; For Sale; Death By Bean; It's Good!; Tomato Chutney v2; Time ATAC MX 2 Pedals - First Impressions; Online Chilean Crafts; Intellectual Variety; Taste + Texture; Time Invariance and Gauge Symmetry; Jodorowsky; Tomato Chutney; Analysis of Support for Trump; Indian SF; TP-Link TL-WR841N DNS TCP Bug; TP-Link TL-WR841N as Wireless Bridge; Sending Email On Time; Maybe run a command; Sterile Neutrinos; Strawberry and Banana Jam; The Best Of All Possible Worlds; Kenzaburo Oe: The Changeling; Peach Jam

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