CountdownNumbers.jl

Solve numbers puzzles as seen on the television show Countdown
Author bcbi
Popularity
1 Star
Updated Last
8 Months Ago
Started In
January 2020

CountdownNumbers

Build Status Codecov

This package solves numbers puzzles as seen on the television show Countdown.

Installation

julia> import Pkg; Pkg.add("CountdownNumbers")

Usage

numbers([input_numbers...], target_number)

Examples

If an exact solution is possible, CountdownNumbers.jl will return the exact solution.

julia> using CountdownNumbers

julia> numbers([25, 50, 75, 100, 3, 6], 952)
CountdownNumbers.Operation: (((75 * (6 + 100)) * 3) - 50) / 25 = 952

julia> numbers([50, 75, 100, 25, 2, 1], 940)
CountdownNumbers.Operation: 1 + ((75 * (2 + (25 * 50))) / 100) = 940

Per the Countdown rules, correct solutions do not need to use all of the input numbers:

julia> using CountdownNumbers

julia> numbers([100, 75, 5, 6, 8, 7], 561)
CountdownNumbers.Operation: 75 + ((5 * 100) - (6 + 8)) = 561

If an exact solution is not possible, CountdownNumbers.jl will print a warning and return the solution closest to the target.

julia> using CountdownNumbers

julia> numbers([100, 75, 25, 50, 10, 6], 873)
┌ Warning: Could not find exact solution. Closest solution has L1 error 1
└ @ CountdownNumbers ~/.julia/packages/CountdownNumbers/IoXgC/src/public.jl:35
CountdownNumbers.Operation: (25 * ((10 * (75 + 100)) - 6)) / 50 = 872

julia> numbers([1, 1, 1, 1, 1, 1], 200)
┌ Warning: Could not find exact solution. Closest solution has L1 error 191
└ @ CountdownNumbers ~/.julia/packages/CountdownNumbers/IoXgC/src/public.jl:35
CountdownNumbers.Operation: ((1 + 1) + 1) * (1 + (1 + 1)) = 9

On Countdown, a puzzle consists of exactly six input numbers and a three-digit target number. However, CountdownNumbers.jl supports any number of input numbers and any positive target number.

julia> using CountdownNumbers
  
julia> numbers([1, 2, 3, 4], 25)
CountdownNumbers.Operation: 1 + ((2 * 3) * 4) = 25

Required Packages

Used By Packages

No packages found.