| 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

Lepton Decay Irregularity; An Easier Way; Julia's BinDeps (aka How To Install Cairo); Good Example Of Good Police Work (And Anonymity Being Hard); Best Santiago Burgers; Also; Michael Emmerich (Vibrator Translator) Interview (Japanese Books); Clarice Lispector (Brazillian Writer); Books On Evolution; Looks like Ara (Modular Phone) is dead; Index - Translations From Chile; More Emotion in Chilean Wines; Week 7; Aeon Magazine (Science-ish); QM, Deutsch, Constructor Theory; Interesting Talk Transcripts; Interesting Suggestion Of Election Fraud; "Hard" Books; Articles or Papers on depolarizing the US; Textbook for "QM as complex probabilities"; SFO Get Libor Trader (14 years); Why Are There Still So Many Jobs?; Navier Stokes Incomplete; More on Benford; FBI Claimed Vandalism; Architectural Tessellation; Also: Go, Blake's 7; Delusions of Gender (book); Crypto AG DID work with NSA / GCHQ; UNUMS (Universal Number Format); MOOCs (Massive Open Online Courses); Interesting Looking Game; Euler's Theorem for Polynomials; Weeks 3-6; Reddit Comment; Differential Cryptanalysis For Dummies; Japanese Graphic Design; Books To Be Re-Read; And Today I Learned Bugs Need Clear Examples; Factoring a 67 bit prime in your head; Islamic Geometric Art; Useful Julia Backtraces from Tasks; Nothing, however, is lost with less discomfort than that which, when lost, cannot be missed; Article on Didion; Cost of Living by City; British Slavery; Derrida on Metaphor; African SciFi; Traits in Julia; Alternative Japanese Lit; Pulic Key as Address (Snow); Why Information Grows; The Blindness Of The Chilean Elite; Some Victoriagate Links; This Is Why I Left StackOverflow; New TLS Implementation; Maths for Physicists; How I Am 8; 1000 Word Philosophy; Cyberpunk Reading List; Detailed Discussion of Message Dispatch in ParserCombinator Library for Julia; FizzBuzz in Julia w Dependent Types; kokko - Design Shop in Osaka; Summary of Greece, Currently; LLVM and GPUs; See Also; Schoolgirl Groyps (Maths); Japanese Lit; Another Example - Modular Arithmetic; Music from United; Python 2 and 3 compatible alternative.; Read Agatha Christie for the Plot; A Constructive Look at TempleOS; Music Thread w Many Recommendations; Fixed Version; A Useful Julia Macro To Define Equality And Hash; k3b cdrom access, OpenSuse 13.1; Week 2; From outside, the UK looks less than stellar; Huge Fonts in VirtualBox; Keen - Complex Emergencies; The Fallen of World War II; Some Spanish Fiction; Calling C From Fortran 95; Bjork DJ Set; Z3 Example With Python; Week 1; Useful Guide To Starting With IJulia; UK Election + Media; Review: Reinventing Organizations; Inline Assembly With Julia / LLVM; Against the definition of types; Dumb Crypto Paper; The Search For Quasi-Periodicity...; Is There An Alternative To Processing?; CARDIAC (CARDboard Illustrative Aid to Computation); The Bolivian Case Against Chile At The Hague; Clear, Cogent Economic Arguments For Immigration; A Program To Say If I Am Working; Decent Cards For Ill People; New Photo

© 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