Git Product home page Git Product logo

fibonacci-list's Introduction

fibonacci-list

Implements a table view that calculates Fibonacci numbers as you scroll.

This simple application set out to solve the following problem:

Calculate and display the Fibonacci number from 1 -> N 
(where N is possible max for unsigned int in an iphone).
Display each Fib(n) in a table view. 
The scrolling MUST be smooth.

Problems

  1. Swift's Foundation does not have support for an arbitrarily sized integer such as Java's BigInteger, and as such can't natively store values anywhere near the size of even fib(1000) let alone fib(UInt.max). An NSDecimalNumber object can represent up to 38 digits accurately, which is higher than any other native object but still can only accurately represent up to about n = 190.
  2. The problem states we need to support up to fib(UInt.max) but a UITableView doesn't support an index beyond Int.max

Result

This application solves a simplified version of the above problem. It implements a generic memoization function and uses that function to create a memoized, recursive Fibonacci implementation. Due to the lack of BigInteger support in Swift and in lieu of importing a third party library such as swift-pons the app uses NSDecimalNumber to store the Fibonacci results.

Improvements

There are a few improvements to the app that could be made to more closely match the exact spec as well as improve performance at extremely high n values, but that I thought were out of the scope of a small assignment such as this.

  1. Use swift-pons or something similar to account for huge Fibonacci values.
  2. Use a sliding range of fibonacci results rather than a typical list. This range would shift as the user scrolls and discard results that are more than a certain distance away from the user's current scroll position. This would ensure that the app's memory footprint would never grow so large that the OS will kill it, and it would grant us the ability to support displaying fib(UInt.max) since our table view's indices would no longer be tightly coupled with the n value we are calculating. This is a highly unusual and fairly complex implementation of a table view and as such I thought it would be out of the scope of this assignment, but I also thought it worth pointing out here.

Installation Instructions

Run the following commands to download the repository and open the project in Xcode.

git clone [email protected]:Killectro/fibonacci-list.git
cd fibonacci-list
open FibonacciList/FibonacciList.xcodeproj

fibonacci-list's People

Contributors

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