Coder Social home page Coder Social logo

jeetdas / clojure-coin-line-game Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 25 KB

Clojure implementation of a dynamic programming problem about coins in a line game

License: Eclipse Public License 1.0

Clojure 100.00%
clojure dynamic-programming algorithm lein numbered-coins

clojure-coin-line-game's Introduction

Coin Line Game

A simple 2-player game played as follows: An even number of coins is laid out in a row. Taking turns, each player removes the coin on one of the ends of the row. The object is to have the highest value in coins when all coins have been taken. Note that a greedy strategy of taking the largestvalue end coin is not sufficient.

Consider this situation:

5, 25, 10, 1

In this case, the player should take the 1 on the right end; after the opponent takes either the 5 or the 10, the player is guaranteed to get the 25. Simply taking the 5 “because it’s bigger” will result in the biggest coin going to the other player.

Algorithm

  1. If there are an even number of coins: Find the sum of all of the even-numbered coins, and all the odd-numbered coins. If the sum of the odd numbered coins is higher, take the leftmost coin; otherwise take the rightmost.

  2. Minimize loss/maximize gain by evaluating every single possiblity of running the application after either taking the first or the last coin (Implementation choppy and doesn't work well on large data sets).

Usage

Install Lein (https://gist.github.com/technomancy/2395913)

There are two text files, one with 10 numbers to test the algorithm and one with 10,000 numbers to run the program on.

To run: 'lein run filePath' from project directory

Example: lein run '/Users/jeet/Workspace/Clojure_projects/cs-441-coin-game/resources/10.txt'

License

Copyright © 2018 Jeet Das

Distributed under the Eclipse Public License either version 1.0 or any later version.

clojure-coin-line-game's People

Contributors

jeetdas avatar

Stargazers

 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.