GurdeepS
GurdeepS

Reputation: 67233

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

Upvotes: 2

Views: 829

Answers (5)

Bob Palmer
Bob Palmer

Reputation: 4762

If the purpose is for an interview (i.e. you need to have a candidate bang out some code as part of the evaluation process), I've always liked Project Euler question 11.

If it's for your own use to learn a new language, etc. I prefer some of the code kata at codingdojo.org (the OCR one is pretty entertaining in any language).

Upvotes: 2

user486972
user486972

Reputation: 386

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

Upvotes: 3

Jan
Jan

Reputation: 8141

Here are a lot of small programming puzzles. a Lot of them are about logic

Upvotes: 2

Luc M
Luc M

Reputation: 17324

Sudoku

Upvotes: 2

jason
jason

Reputation: 241701

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

Upvotes: 9

Related Questions