Giter VIP home page Giter VIP logo

pirate-riddle's Introduction

Solver for the Pirate Riddle with N pirates

The problem

Below is the Pirate riddle in its most common form, with 5 pirates. Adapted from Popular Mechanics.

Five pirates are to divide 100 gold coins among themselves. The pirates have a system that they are sworn to follow. It works like this: The captain proposes a way to divide the coins. Then all the pirates, including the captain, vote on whether or not to accept the proposal. If a majority accept or there is a tie they divvy the coins as proposed. Otherwise the captain is killed and the next ranking pirate takes over as captain. The new captain makes a proposal and they vote again with the same rules.

There are a few important things to know about the pirates. First, they will make their decisions according to whatever will net them the most money without getting them killed. Second, all other things being equal, they would prefer to kill the captain. Third, they do not trust each other in the slightest and will make no agreements amongst themselves to determine how they vote. Finally, the pirates are perfect logicians, capable of considering all possible outcomes.

Let's consider the pirates A, B, C, D and E, with A being the captain and the rest of the pirates ordered by rank. How should Pirate A suggest they divvy up the coins?

The code in this repo solves this riddle with an arbitrary number of pirates. The 100 coins of the original riddle can only be distributed optimally to a maximum of 200 pirates. After that the solver increases the total number of coins by one for each pirate over number 200.

Scripts

Run the solver using stack:

stack build
stack exec pirate-riddle-exe -- 5

Run the Hspec test suite:

stack test

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.