Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

What is your magnum opus?

Name: Anonymous 2009-04-13 12:57

I created a Scheme LISP compiler that assembles to machine code in x86 format. What have you guys done that many people use today?

Name: Anonymous 2009-04-15 1:03

>>40
It can do fib 100000000 in less than 2 seconds if your machine has enough RAM.

Name: Anonymous 2009-04-15 1:37

>>41
proof or GTFO.

Name: Anonymous 2009-04-15 1:39

>>40
do your own damn project euler questions!

Name: Anonymous 2009-04-15 1:45

>>42
You are not welcome here.

Name: Anonymous 2009-04-15 1:48

>>42
It should be trivial to implement it in O(1) using memoization, however this would mean high RAM usage. And one can use a hybrid approach which requires very little RAM(constant), where only the last 2 values of fibs are stored and passed recursively(tail-recursive, so can be implemented as iteration too). The hybrid approach has one disadvantage to the memoization version, as the first should be able to instantly return a previously calculated fibs, while the hybrid one actually recalculates fibs each time.

P.S.: I'm not >>41

Name: Anonymous 2009-04-15 1:57

O(1)

Your use of this term intrigues me. Have we forgotten amortization, /prog/?

Name: Anonymous 2009-04-15 1:59

One could use that formula to calculate fib n, though it technically isn't "O(1)"

Name: Anonymous 2009-04-15 2:15

>>46
It's O(1) with probability of 1.

Name: Anonymous 2009-04-15 2:19

Fibs discussion is the height of /prog/ achievements. Continue.

Name: Anonymous 2009-04-15 2:39

O(1) fibonacci is only possible for fixed-size integers. and it's slow as fuck unless that size is extremely small (much smaller than you'd need for fib 100000000). so it's actually completely useless.

Name: Anonymous 2009-04-15 3:19

My attempt at the hybrid version:


(*let fibs n =
  let rec fibq fkm1 fkm2 k n =
    if (n<2) then (if (n=0) then 0 else 1)
    else if (n=k) then (fkm1+fkm2)
         else fibq (fkm1+fkm2) fkm1 (k+1) n
  in fibq 1 0 2 n*)

(*#load "nums.cma";;*)

open Big_int;;

let fibs_big n =
  let rec fibq fkm1 fkm2 k n =
    if (n<2) then (if (n=0) then big_int_of_int(0) else big_int_of_int(1))
    else if (n=k) then (add_big_int fkm1 fkm2)
         else fibq (add_big_int fkm1 fkm2) fkm1 (k+1) n
  in fibq (big_int_of_int(1)) (big_int_of_int(0)) 2 n;;

let f10_8 = string_of_big_int (fibs_big 1000000);;

print_endline f10_8;
flush stdout


It actually runs in a reasonable amount of time, but something like 10**10 is very slow due to the amount of memory needed to represents the bignums as >>50 stated

Name: Anonymous 2009-04-15 3:37

>>51
You spelled let* wrong.  (Didn't read past that.)

Name: Anonymous 2009-04-15 3:52

>>52
It's not LISP code, but O'Caml code. The code compiles and runs fine. IHBT

Name: Anonymous 2009-04-15 4:08

let f10_8 = string_of_big_int (fibs_big 1000000);;
that's only 106, idiot.

Name: Anonymous 2009-04-15 4:51

>>53
It also works in F# if you use option strict

Name: Anonymous 2011-02-02 22:49


Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List