Giter Club home page Giter Club logo

countdownsolver.jl's Introduction

CountdownSolver.jl

Solves the countdown problem.

Problem description

Given a set S of natural numbers, combine these using +, -, /, * and () to get a desired result r. The brackets are required to distinguish between otherwise identitical combinations, e.g.:

$$2 * 25 + 3 * 4 =/= 2 * (25 + 3) * 4$$

Some useful resources on the topic:

It seems brute force is the only way of doing this, i.e. try as many combinations in 30 seconds and see which one is closest to the desired result. This algorithm could be desribed as follows:

  1. Set A = [(,n) for n in S] to be the set of available numbers and how they were obtained (order of operations).
  2. For (a1,a1) in unique(product(A,A)), combine a1 and a1 using +, -, /, * and ().
  3. If this combination is equal to r, then stop. Else, save this number and the associated operations with it in A_new.
  4. Set A = union(A,A_new).
  5. Go back to step 2.

The problem with this algorithm is that some impossible combinations are produced, e.g. if S = [2,3,10,25] then a possible combination (in terms of the algorithm) is 2 * 3 * 2, even though 2 only appears once. I can get over this by saving the numbers used as well as the order of operation in the set A.

Develop

Just do include(<path_to_CountdownSolver.jl>) before running a script or a test. Similarly for the functions to build the web UI.

Alternatively:

julia> ENV["JULIA_PKG_DEVDIR"] = joinpath(ENV["HOME"], "Desktop", "Julia_Dev")
(@v1.5) pkg> add git@github.com:junglegobs/CountdownSolver.jl.git
(@v1.5) pkg> dev CountdownSolver # Will copy files to Desktop/Julia_Dev
julia> using Revise
(@v1.5) pkg> activate CountdownSolver
julia> using CountdownSolver

The package is now located at joinpath(ENV["HOME"], "Desktop", "Julia_Dev"). Any exported functions from the module CountdownSolver are now accessible, and the Revise.jl package ensures that any changes are automatically taken into account. By activating CountdownSolver, any packages will be added to the CountdownSolver.jl package (and not your main environment).

countdownsolver.jl's People

Contributors

junglegobs avatar

Watchers

 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.