Giter VIP home page Giter VIP logo

closest_fibonacci's Introduction

closest_fibonacci

Extends the Fixnum class to provide a closest_fibonacci method, returning the largest integer value from the Fibonacci Sequence smaller than the given integer.

Notes

To grade, run bundle install (requires rspec), then rake.

I used a Fibonacci Sequence generator I found on the internet (source URL in the comments). My logic is that greater minds than mine have been at work on that problem, so I should take advantage of their work. That said, I did write test cases to ensure the generator behaved as it should.

Usage

First install the gem, then:

require 'rubygems'
require 'closest_fibonacci'

12345.closest_fibonacci
# 10946

To-do

There are many things that would make this gem better that I have skipped over given the nature of this project. For example:

  • A custom rspec matcher could eliminate the repetitive pattern of number.closest_fibonacci.should == another_number in the specs.

  • Better input checking should be used. For example, negative numbers or non-numeric input should be checked for and an appropriate exception raised.

Copyright

Copyright (c) 2011 Todd Eichel. See LICENSE.txt for further details.

closest_fibonacci's People

Contributors

tfe avatar

Stargazers

 avatar  avatar

Watchers

 avatar  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.