# How to design an algorithm to calculate countdown style maths number puzzle

Posted on

algorithm, combinatorics

I have always wanted to do this but every time I start thinking about the problem it blows my mind because of its exponential nature.

The problem solver I want to be able to understand and code is for the countdown maths problem:

Given set of number X1 to X5 calculate how they can be combined using mathematical operations to make Y.

You can apply multiplication, division, addition and subtraction.

So how does `1,3,7,6,8,3`

make `348`

?

Answer: `(((8 * 7) + 3) -1) *6 = 348`

.

How to write an algorithm that can solve this problem? Where do you begin when trying to solve a problem like this? What important considerations do you have to think about when designing such an algorithm?

## Related posts

- How to design an algorithm to calculate countdown style maths number puzzle
- Most efficient algorithm to calculate vertex normals from set of triangles for Gouraud shading
- R – Design an algorithm to calculate the most user viewed pages
- What algorithm can calculate the power set of a given set
- Python – How to calculate % score from ORB algorithm
- C++ algorithm to calculate least common multiple for multiple numbers
- Java – How to calculate the complexity of an algorithm?
- Python – KenKen puzzle addends: REDUX A (corrected) non-recursive algorithm
- Algorithm to convert a number in an unknown base to the equivalent base 10 number
- Algorithm to calculate number of intersecting discs
- Java – calculate average waiting time for a preemptive shortest job first scheduling algorithm
- Algorithm to check if a number if a perfect number
- C++ – how to design CPM algorithm
- C# – Algorithm to calculate nearest location based on longitude & latitude
- How to calculate time complexity of backtracking algorithm
- R – How to calculate the number of permutations in base 3 combinatorics
- How to calculate the inverse key matrix in Hill Cipher algorithm
- Php – Combinatorics: Building 10 groups of 100 elements while elements remain sorted
- Algorithm used to calculate 5 star ratings
- Find the solutions to “The Algorithm Design Manual”?
- A fast algorithm for creating a puzzle
- Algorithm for finding smallest number with given number of factors
- Design an efficient algorithm to sort 5 distinct keys in fewer than 8 comparisons
- The efficient Algorithm for Solving Jigsaw Puzzle
- Algorithm/Data Structure Design Interview Questions
- R – Combinatorics with repeated chars on initial group
- The fastest algorithm to calculate the minimum distance between two sets of points
- Algorithm in C to calculate coefficients of polynomial using Lagrange interpolation
- R – How to design an approximate solution algorithm
- Python – Skyscraper puzzle algorithm
- How would you write a non-recursive algorithm to calculate factorials
- Algorithm to calculate the odds of a team winning a sports match given full history
- Ios – Which is the best algorithm to provide moves to solve 15 puzzle?
- R – Algorithm to find an optimum number of rumthe-style sets
- How to solve the 15-puzzle with A-Star or Dijkstra’s Algorithm
- I am looking for an algorithm to solve a “sliding puzzle”, the kind of puzzle where you have an image broken into 16 pieces in a 4×4 frame
- How to calculate MIPS for an algorithm for ARM processor
- Ruby – Calculate an RFC 2104-compliant HMAC with the SHA256 hash algorithm in ruby
- R – Combinatorics : Grouping Characters Challenges
- An efficient algorithm to calculate the integer square root (isqrt) of arbitrarily large integers
- Java – permutations/combinatorics library for java?
- How to calculate fitness function ( genetic algorithm)
- Looking for algorithm to calculate h-index fast
- Iphone – Compilation Error on #include
Algorithm:No such file or Directory - An algorithm to calculate probability of a sum of the results happening
- Algorithm/formula to calculate Product ranking on a ecommerce website(Based on following criteria)
- C++ – n-puzzle solving with A* algorithm using C++
- Java – Set Combinatorics Algorithm in Java
- Graph algorithm to calculate node degree
- How does one calculate the runtime of an algorithm
- Recursive algorithm to calculate square root
- Java – Modifying Levenshtein Distance algorithm to not calculate all distances
- Algorithm needed to calculate difference between two times
- Java – A* Algorithm 8-puzzle
- Java – Recursive algorithm to calculate the square root and cube root
- How to calculate worst case analysis of this algorithm
- The fastest algorithm to calculate all factors of an integer number?
- R – Algorithm to create hex flood puzzle
- C# – How to calculate ASN.1 DER encoding of a particular hash algorithm
- C++ – Algorithm to calculate the start day of the next month
- R – Algorithm to calculate the number of matches in Swiss system tournament
- C# – My Algorithm to Calculate Position of Smartphone – GPS and Sensors
- Java – Code for Variations with repetition (combinatorics)
- Custom paging algorithm to calculate pages to display
- R – Algorithm to calculate next set in sequence
- How to calculate Running time of an algorithm
- How to calculate the big oh of the binary search algorithm
- Image processing -Algorithm to calculate centroids of white space in binary image
- R – Algorithm to calculate power set (all possible subsets) of a set in R
- Php – the paper “Oliver [1993]” describing a PHP algorithm to calculate text similarity
- R – What’s a good, non-recursive algorithm to calculate a Cartesian product
- Algorithm for crossword puzzle with given grid
- Voting algorithm: how to calculate rank
- R – Grid based puzzle board game block removal algorithm
- What algorithm to use to calculate a check digit
- R – Simple combinatorics in R
- Java – Scanline algorithm: how to calculate intersection points
- C++ – Efficient algorithm to calculate Correlation between two Arrays
- The best algorithm to calculate the most scored item
- How to calculate heuristic value in a* algorithm
- Algorithm to add two digits to the end of a number to calculate a specific modulus
- Google-maps – Algorithm to calculate the distances between many geo points
- Efficient maths algorithm to calculate intersections
- Python – Combinatorics Counting Puzzle: Roll 20, 8-sided dice, what is the probability of getting at least 5 dice of the same value
- Python – Algorithm to find which number in a list sum up to a certain number
- Algorithm to calculate the number of 1s for a range of numbers in binary
- C# – Efficient algorithm to find a combination, which summation is equal to a known number, in a set of number
- Matlab – how to calculate threshold value in eigenfaces or pca algorithm for each images in training set in matlab during face recognition
- How to calculate the threshold value for numeric attributes in Quinlan’s C4.5 algorithm
- Algorithm to calculate the number of divisors of a given number
- Ruby – An algorithm for converting a base-10 number to a base-N number
- Fast algorithm to calculate Pi in parallel

## Best Solution

Very quick and dirty solution in Java:

UPDATEIt's basically just simple brute force algorithm with exponential complexity. However you can gain some improvemens by leveraging some heuristic function which will help you to order sequence of numbers or(and) operations you will process in each level of

`getOperatiosn()`

function recursion.Example of such heuristic function is for example difference between mid result and total target result.

This way however only best-case and average-case complexities get improved. Worst case complexity remains untouched.

Worst case complexity can be improved by some kind of branch cutting. I'm not sure if it's possible in this case.