Git Product home page Git Product logo

binary_vs_trinary's Introduction

Searching for the lightweight coin binary vs trinary

Details:

You are give X coins. And You know all the coins weigh the same except one. One coin is lighter than all the rest. All you have is the coins and an old balance scale that tells if you either one side is heavier or they weights are equal. How do you find the light coin?

Binary search is fast right? You would think so. Either my code is bad or Trinary is the way to go here.

Run it like so:

ruby coin_finder.rb

Sample Output:

Binary search averaged 2 moves for 10 coins

Binary search averaged 8 moves for 100 coins

Binary search averaged 17 moves for 1000 coins

Binary search averaged 30 moves for 10000 coins

Binary search averaged 46 moves for 100000 coins

Trinary search averaged 2 moves for 10 coins

Trinary search averaged 6 moves for 100 coins

Trinary search averaged 12 moves for 1000 coins

Trinary search averaged 21 moves for 10000 coins

Trinary search averaged 31 moves for 100000 coins

binary_vs_trinary's People

Contributors

rbeltran avatar

Watchers

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