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

Pages: 1-

Fibs challenge

Name: Anonymous 2011-12-09 11:18

program which will:
Display the largest fibs you can in your language of choice, but using only your own code
(no non-standard libraries like multiple precision arithmetic).

Name: Anonymous 2011-12-09 11:36

Name: Anonymous 2011-12-09 11:48

WOW SON u so stoopid
let F0 = 0 and F1 = 1

>>0
>>1
>>1
>>2
>>3
>>5
>>8
>>13
>>21
...
>>Fn-1+Fn-2

Name: Anonymous 2011-12-09 12:42

fibs = 0 : 1 : zipWith (+) fibs (tail fibs)

main = print $ maximum fibs


It could take a while.

Name: Anonymous 2011-12-09 17:04

>>4
ohh haskell

the best language to write a fibonacci function

Name: Anonymous 2011-12-09 18:53

main(){return!puts("14764850684189816403580"...);}

Could probably go on to the point where the system can't handle the string length.

Name: F r o z e n V o i d !!mJCwdV5J0Xy2A21 2011-12-09 22:40

#include <math.h>
#define f8 long double
#define cf8 const long double
inline f8 fibs(unsigned long long x){
cf8 PHI=1.61803398874989484820458683436563811772030917980576286213544862270526046281890244970720720418939113748475L;
cf8 PHN =-0.61803398874989484820458683436563811772030917980576286213544862270526046281890244970720720418939113748475L;
cf8 SQRT5=2.23606797749978969640917366873127623544061835961152572427089L;
f8 p=(f8)x;
f8 p1=powl(PHI,p);
f8 p2=powl(PHN,p);
f8 r=(p1-p2)/SQRT5;
return roundl(r);}

main(){return printf("%.30Lf\n\n",fibs(23550));}

Name: Anonymous 2011-12-09 23:03

Nothing like frozenvoid showing off his shitty coding styles

Name: Anonymous 2011-12-09 23:24

>>4
It could take a while.
SLOW AS FUCK

Name: Anonymous 2011-12-09 23:25

I wrote one in C++ that displayed one infinitely large(not really, but I easily got it to display a Fibonacci number that was 700,000 digits. I did it by making a new class bigInt, that was a string. I overloaded all basic operators needed to calc fibonacci and then just wrote an iterative fib function. I'll try to dig it up.

Name: Anonymous 2011-12-09 23:41

>>10'
>that feel when long ago for a project euler question i did the exact same thing in java with a number that was huge and had to be calculated through defined multiplication,etc sets

Name: Anonymous 2011-12-10 0:02


(define increment list)
#<unspecified>
(define decrement car)
#<unspecified>
(define zero '())
#<unspecified>
(define one (increment zero))
#<unspecified>
(define two (increment one))
#<unspecified>
(define is-zero? null?)
#<unspecified>
(define (is-one? n)
  (and (not (is-zero? n))
       (is-zero? (decrement n))))
#<unspecified>

(define (add num1 num2)
  (if (is-zero? num1)
    num2
    (add (decrement num1) (increment num2))))
#<unspecified>

(define (sub num1 num2)
  (if (is-zero? num2)
    num1
    (sub (decrement num1) (decrement num2))))
#<unspecified>

(define (fibs n)
  (cond ((is-zero? n) zero)
        ((is-one? n) one)
        (else (add (fibs (sub n one)) (fibs (sub n two))))))
#<unspecified>

(display (fibs '()))
()#<unspecified>
(display (fibs '(())))
(())#<unspecified>
(display (fibs '((()))))
(())#<unspecified>
(display (fibs '(((())))))
((()))#<unspecified>
(display (fibs '((((()))))))
(((())))#<unspecified>
(display (fibs '(((((())))))))
(((((())))))#<unspecified>
(display (fibs '((((((()))))))))
((((((((()))))))))#<unspecified>
(display (fibs '(((((((())))))))))
(((((((((((((())))))))))))))#<unspecified>
(display (fibs '((((((((()))))))))))
(((((((((((((((((((((())))))))))))))))))))))#<unspecified>
(display (fibs '(((((((((())))))))))))
((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))#<unspecified>

Name: Anonymous 2011-12-10 0:32

>>12
Cool.
>>1
As you have not specified any concrete limitations on the machine that is supposed to be running it, the language and the implementation, the question isn't really answerable.
On an abstract machine, one could see the program halt as F(n+1)>F(n), thus there's no maximum Fibonnaci number.
In a language with a proper numeric tower (such as Common Lisp or Scheme), you could write the fibs normally and bignums would be handled transparently behind the scenes. At least as far as the specification is concerned (it concerns to concrete finite machine), the computation could go on forever and numbers could very well be unbounded (if whatever universe/machine the language was implemented on allowed it).
If you would place the concrete constraints as far as what is allowed (machine, language, implementation, etc), the problem would become solvable in the real world as you would introduce some upper limit, and thus also introduce concrete limits as to what the maximum computable Fibonnaci number for a particular machine/implementation would be.

Name: Anonymous 2011-12-10 0:32

*see the program never halt

Name: Anonymous 2011-12-10 1:53

I wish I was better at lambda calculus. I'd write one in unlambda using Church numerals. Or Xarn numerals

Name: Anonymous 2011-12-10 2:03

>>14
*see the program never halt
Sounds like someone has a solution to the halting problem.

Name: Anonymous 2011-12-10 2:04

>>16

HALT MY ANUS

Name: Anonymous 2011-12-10 2:31

>>16
No, I don't, but you may be able to show (or even prove) wether a particular program halts or not. The halting problem is merely that you can't solve it for any program, or to put it differently, there are programs for which it isn't decidable.

Name: Anonymous 2011-12-10 2:33

>>15
Might be nice to write one in combinatory logic as well.

Name: Anonymous 2011-12-10 11:21

((λp.((λg.(λx.g (x x)) (λx.g (x x))) (λrn.((p n) ((λmnfx.m f (n f x)) (r (p (p n))) (r (p n))) n))) λnfx.n (λgh.h (g f)) (λu.x) (λu.u))

I'm not entirely sure if this is right, but I don't think it is. Works for {0, 1, 2, 3} at least, but I can think of a possible error. I'll fix it later.

Name: Anonymous 2011-12-10 13:42

>>9
You're an idiot.

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