Pages

Showing posts with label problems. Show all posts
Showing posts with label problems. Show all posts

Tuesday, October 30, 2012

PY-04: Solving Problems, Part 2

In the last post, I covered how decrementing functions can be useful for finding the solutions to simple problems, notably for finding a cubed root of a value, "x". However, it is important to note that while decrementing functions are sometimes the best call, they are not always so. Our next lesson covers another method, by the name of exhaustive enumeration.


Before we begin, please note that open and close brackets, i.e. "[" and "]" respectively, will contain raw code.

Exhaustive Enumeration

Summary

Exhaustive enumeration is a function for solving problems by which the computer exhausts possible options in a systematic way, so that it can find the correct one. This is what is known in the world of programming as a "brute force" tactic for solving problems, because of its straight-forward methods.

As computers are so adept at computing instructions swiftly, once outlandish ways to solve problems are now useful realities. An example of exhaustive enumeration in real life (albeit a watered-down version) would be finding which answers on a multiple-choice test question are not correct, and by process of elimination (exhaustion), we can come to the correct answer more easily.

Friday, October 26, 2012

PY-03: Solving Problems, Part 1



Programs are very useful for the purpose of solving problems. Many programmers know this potential of programs, and use it to their advantage. However, all is not so straight-forward in the world of programming and problem-solving; there are as many ways to go about finding a solution as there are stars in the sky (perhaps more!).

All in all, the method by which you code a program for finding the solution to a problem is up to the programmer -- you. That is why it is important to learn some of the basic ways by which one can arrive at a solution. Only after you understand these ways, can you move on to more complicated problem-solving.

Before we begin, please note that open and close brackets, i.e. "[" and "]" respectively, will contain raw code.

Decrementing Function

The first method is the decrementing function. A decrementing function starts with a non-negative value, which is decreased each time the program repeats the function's loop. The function will loop so long as the starting value is non-negative, but once it is equal to or less than 0, it will terminate.