Fibonacci in Racket

Published on 31 October 2019 (Updated: 10 May 2022)

Welcome to the Fibonacci in Racket page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

#lang racket

;; A naive iimplementation of fibonacci

(define (fib n)
  (cond
    [(<= n 2)  1]
    [else
     (+ (fib (- n 1)) (fib (- n 2)))]))
     

  
(define (fibonacci n)
  (cond
    [(or (not n) (< n 0)) (display "Usage: please input the count of fibonacci numbers to output")]
    
    [else
     (for ([i (in-range 1 (add1 n))]) 
       (displayln (string-append (number->string i) ": " (number->string (fib i)))))
     ]))
    
  
(fibonacci 
  (string->number 
    (cond
      [(vector-empty? (current-command-line-arguments)) ""] 
      [else (vector-ref (current-command-line-arguments) 0)]
    )
  )
)

Fibonacci in Racket was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.