Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Good programming puzzle requiring a lot of conditional logic?

What is a classic programming puzzle which will require a lot of conditional logic and branches to solve?

Thanks

like image 567
GurdeepS Avatar asked Dec 30 '25 09:12

GurdeepS


2 Answers

Eight queens and Towers of Hanoi are classics. Solving Sudoku is quite interesting too and is really a graph coloring problem in disguise.

like image 85
jason Avatar answered Jan 02 '26 10:01

jason


I like the problem of writing a function that computes the least number of multiplications to compute x^N (e.g., for N = 30, you can compute x^N with 6 multiplies - x -> x^2 - > x^3 -> x^5 -> x^10 -> x^15 -> x^30.

There's no known efficient algorithm, so you have to use branch-and-bound. The conditional logic and branching come in when you are trying to bound. See this wikipedia article for more details - http://en.wikipedia.org/wiki/Addition_chain

like image 45
user486972 Avatar answered Jan 02 '26 10:01

user486972



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!