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

Pages: 1-

Basic Fibs

Name: Anonymous 2013-08-01 16:07

screen 12
dim as integer i = 0
dim as ulongint a = 0, b = 1, c = 0

input "? ", i
while i >= 0
    print a; " ";
    c = b
    b = a + b
    a = c
    i -= 1
wend
sleep

And they said BASIC wasn't useful for anything.

Name: Anonymous 2013-08-01 16:25

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

And they said Haskell wasn't useful for anything.

Name: Anonymous 2013-08-01 16:51

>>2
Won't you get some kind of stack overflow error at some point? Because like, the stack can only hold so many thunks or what not.

Name: Anonymous 2013-08-01 17:01

Reported.

Name: Anonymous 2013-08-01 17:38

fib_fioc = lambda x: ((5**.5*.5+.5)**x-(-5**.5*.5-.5)**-x)/(5**.5)

Name: Anonymous 2013-08-01 18:03

>>3
I'm pretty sure, Haskell compiler has hardcoded optimization for these simple usage cases, but in general case it would fail.

Name: Anonymous 2013-08-01 18:15

>>3

No this is tail recursive and there is only one next thunk due to laziness.


zipWith :: (x -> y -> z) -> [x] -> [y] -> [z]
                                    /-- this is the thunk
zipWith f (x:xs) (y:ys) = f x y : zipWith f xs ys
zipWith f _ _ = []


So if we have three terms, the computations is as follow (with thunks marked):

fibs = 1 : 1 : 2 : zipWith (+) (1 : 1 : 2 :  thunk) (1 : 2 : thunk)

Because of laziness the thunks are only evaluated when needed.

Name: Anonymous 2013-08-01 18:35

>>7
I get that. But doesn't each unevaluated think get stored on the stack?

Name: Anonymous 2013-08-01 18:48

>>8

Yes it gets stored there, but it is only one. Only one is needed to define the next computation. The thunks above are all shared.

Name: Anonymous 2013-08-01 19:13

fibs = 0 : 1 : zipWith (+) fibs $ tail fibs
And they said HASKAL wasn't useful for anything.

Name: Anonymous 2013-08-01 19:14

>>2
Took it right out of my mouth.

Name: Anonymous 2013-08-01 19:15

>>3,6
RETARDS

Name: Anonymous 2013-08-01 19:15

>>11
cock

Name: Anonymous 2013-08-01 19:27

>>10
Yeah, that looks a bit saner.

Name: Anonymous 2013-08-01 19:27

>>12
Don't make me have to report you.

Name: Anonymous 2013-08-01 20:52

>>15
Do it, I already told you mods left.

Name: Anonymous 2013-08-02 0:21

format PE64 console
entry main
include 'win64a.inc'

section '.shit1' code readable writeable executable
main:
mov [x], 0
mov [x+8], 1
mov [x+16], 0
invoke printf, manyfibs
invoke scanf, prompt, many
stuff:
invoke printf, fib, [x]
mov rax, [x+8]
mov [x+16], rax
add rax, [x]
mov [x+8], rax
mov rax, [x+16]
mov [x], rax
dec [many]
cmp [many], 0
jnz stuff
mov eax, 0
ret

section '.shit2' import data readable writeable executable
library stdlib,'msvcrt.dll'
import stdlib, printf, "printf", scanf, "scanf"
fib db ' '
prompt db '%llu', 0
many dq 0
x dq 0,0,0
manyfibs db 'HOW MANY FIBS DO YOU WANT??? ',0

And they said FASM wasn't useful for anything.

Name: Anonymous 2013-08-02 7:24

>>17
Thats cute, but its just a CRT wrapper.

Name: Anonymous 2013-08-02 7:36

All hail the tetracyts!

   ▲
  ▲ ▲
 ▲ ▲ ▲
▲ ▲ ▲ ▲

Name: Anonymous 2013-08-02 10:11

>>16
Your mom just left

Name: Anonymous 2013-08-02 10:24

>>20

All hail the tetracyts!

   ▲   
  ▲ ▲  
 ▲ ▲ ▲ 
▲ ▲ ▲ ▲

Name: Anonymous 2013-08-02 15:36

check 'em

Name: Anonymous 2013-08-04 1:29

>>1
120Kb

>>17
2Kb

Why is FreeBASIC so crappy?

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