r/funny • • Jun 09 '12

Pidgonacci Sequence

Post image

[deleted] — view deleted post

1.6k Upvotes

22k comments sorted by

View all comments

Show parent comment

1

u/Therianthrope Jun 10 '12

What about for Mac?

1

u/day_cq Jun 10 '12

I don't have a Mac.. so, I don't know.. but I think it's Terminal.app in mac.

You still have to install Haskell Platform (or ghc only http://www.haskell.org/ghc/ ). And, compile the script in Terminal.app by typing ghc --make -O2 fib.hs and run the script by typing ./fib n n-2fib n-1fib

1

u/Therianthrope Jun 10 '12

Working on it, Xcode is taking me a bit because I had to find my Snow Leopard disk.

1

u/day_cq Jun 10 '12

hey, I put fib.py here:

https://gist.github.com/2905324#file_fib.py

i think macs come with Python.. Just copy past fib.py to fib.py and run

 python  fib.py 3 1 1

in your terminal. keep pressing enter until you reach the 3000 or something.. or just start with nth by typing

python fib.py n n-2fib n-1fib

Ctrl+C will quit the program.

1

u/the_skeptic Jun 10 '12

Terminal comes with Python!

  • Open Terminal.
  • Copy the code below into a file named fibonacci.py and save in a folder of your choice.
  • Naivgate to that folder in the Terminal and run the command python fibonacci.py.
  • Voilá!

      a = 0
    
      b = 1
    
      temp = 0
    
      counter = 1
    
      res = 'y'
      
      goTo = input("Give the number you want to skip to: ")
      
      print("fib(1) = 1")
    
      while counter < goTo or res != 'n':
          if counter >= goTo:
              res = raw_input("Continue? (y/n): ")
          temp = a
          a = b
          b = a + temp
          counter += 1
          print 'F({0}) =\n{1}\n'.format(counter,b)

1

u/Therianthrope Jun 10 '12

"unexpected character after line continuation character" Why do I always get this error?

1

u/the_skeptic Jun 10 '12

I don't know. It works by a simple copy-paste when I try. Make shure to have all indentation be a mutiple of four white spaces, that is, there should be four spaces before "if" and all lines below, except for the "res = ..." line which should have 8 spaces in front.

Does it give any indication as to which line gives the error?