Git Product home page Git Product logo

ruby-fibonacci-challenge's Introduction

General Assembly Logo

Ruby Fibonacci Challenge

In this challenge, you will create a Fibonacci sequence generator. It will be enumerable and lazy, like Range and the previously created SteppedRange.

Prerequisites

Instructions

  1. Fork and clone this repository.
  2. Change into the new directory.
  3. Install dependencies.
  4. Create and checkout a new branch to work on.
  5. Fulfill the listed requirements.

Starter code is available in lib/challenge.rb. A pull request is not required, but it is necessary if you want a code review.

You may wish to refer to FAQs related to forking, cloning.

Requirements

  • FibonacciRange is Enumerable.
  • FibonacciRange has one instance variable @stop. It stores no other state on the instance.
  • #each stores no more than three values to do its work: current_fib, previous_fib, and next_fib.
  • FibonacciRange.new takes one required, positional argument: stop
  • FibonacciRange always starts at 0 when creating a new sequence.
  • You should not create a list when FibonacciRange.new is called. Instead, FibonacciRange.new(10).map(&:itself) should return [0, 1, 1, 2, 3, 5, 8]. This is referred to as "lazy evaluation".
  • FibonacciRange.new(10).to_a should return [0, 1, 1, 2, 3, 5, 8]

Pay attention to your linter and fix any syntax errors as they occur. You should run rspec spec to run the included tests. Tests will tell you whether or not you've met these requirements.

Bonus

Write a class, FibonacciNumber, that returns the nth number in the Fibonacci sequence. Requirements:

  • FibonacciNumber stores no state on the instance.
  • FibonacciNumber.new and FibonacciNumber.new(1) should both return the the first Fibonacci number, 0. In this case, we use "first" as mathematicians would use it, whereas programmers would say "zeroth".
  • FibonacciNumber.new(3).to_i returns the third Fibonacci number. Since the Fibonacci sequence is 0, 1, 1, 2, 3, 5..., the third number is 1.

This will be very difficult. You may or may not choose to reuse your FibonacciRange. Try it both ways, starting with using FibonacciRange. You will have to make some interesting decisions about how to use it. Then, try a solution without FibonacciRange, instead using recursion. Make note of the tradeoffs between (pros and cons of) each solution.

Tasks

Developers should run these often!

  • bin/rake nag (or bundle exec rake nag): runs code quality analysis tools on your code and complains.
  • bin/rake test (or bundle exec rake test): runs automated tests.
  • bin/rake will run both nag and test
  1. All content is licensed under a CC­BY­NC­SA 4.0 license.
  2. All software code is licensed under GNU GPLv3. For commercial use or alternative licensing, please contact [email protected].

ruby-fibonacci-challenge's People

Contributors

bernardlee avatar payne-chris-r avatar jrhorn424 avatar micfin avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.