Friday, July 30, 2010

Genius + Brute Force = Ingenious

These two statements have been branded with fire in my mind:
  • Genius find a solution instantly
  • Brute Force searches for a needle in a haystack
Sometimes we need to generate random numbers. History has kept evidence of Dice and Coin toss as methods of generating random choices.

Donald Knuth invented algorithms for pseudo-random number generation.

Edsger Dijkstra stated that there are two approaches to solve computer problems: Mozart Vs. Beethoven. (As a curious fact, Mozart and Beethoven met each other in 1787) The former is a genius, but the latter works by brute force.

In India, Pachisi and Chaturanga were played with Dice. Orthodox Chess can be also played with dice, but Chess isn't normally played that way. The praise of what is random have been lost.

In Watchmen movie, Dr. Manhattan talks about the "Pleasure of Randomness" If there's an origin for that phrase, I'd like to find it out. Also, some levels of randomness are required to produce Fine Arts.

To try to get in touch with that "Pleasure of Randomness", I decided to create a little program that generated three numbers between zero and one-hundred inclusive. Then, I will use only the first two numbers and some operations to generate a result equal to the third number. For example, if those three numbers where {2, 3, 6}, then (2+3)+(3-2)=6. Of course that 2*3=6, but what would you do if numbers were {53, 92, 59}? This is what I did, using Python IDLE:
## OUR THREE RANDOM NUMBERS

a=53 ; b=92 ; c=59 ;

## EXPLORING NUMBERS
92-53 = 39   (b-a)
53-39 = 14 a-(b-a)
39-14 = 25 (b-a)-(a-(b-a))

25-14 = 11 (b-a)-(a-(b-a)) - (a-(b-a)) //???

92-11-11-11 = 59 //MAGIC!

b \
-((b-a)-(a-(b-a))-(a-(b-a))) \
-((b-a)-(a-(b-a))-(a-(b-a))) \
-((b-a)-(a-(b-a))-(a-(b-a))) \
== c

## SIMPLIFICATION

>>> ((b-a)-(a-(b-a))-(a-(b-a)))
11
>>> ((b-a)-(a-b+a)-(a-(b-a)))
11
>>> (b-a-a+b-a-(a-(b-a)))
11
>>> (b-a-a+b-a-(a-b+a))
11
>>> (b-a-a+b-a+(-a+b-a))
11
>>> (b-a-a+b-a-a+b-a)
11
>>> b-a-a+b-a-a+b-a
11
>>> 3*b-5*a
11
>>> (9*b-15*a)
33
>>> b-(9*b-15*a)==c
True
>>> b+(-9*b+15*a)
59
>>> b-9*b+15*a
59
>>> 15*a-8*b
59
Looking at this simplification, some questions pops out from my mind: Would a genius had gotten an equation like this from the start? Would have a genius known that a solution found using this method could be simplified without even trying to solve one problem in the first place? I don't know, but I'm sure I'm not a genius.

This simple game taught me some lessons:
  • Pseudo-Random exploration is helpful to find a solution.
  • Be ware of the word 'repeat'. It could hide a mathematical operation.

---
20100729T0948:
round a problem many times
look for hindrances, obstacles, inconveniences
re-round each found obstacle and find inner obstacles
until one obstacle is solved
then, that solution will solve another
and so, like a domino effect,
the first and original problem
starts to get solved
- [id, status, created, modified, position, modcount]

20100729T1125:
writing undefined sentences to describe the problem
making calculations with parameters to find a result
opening many files to understand and solve the code

20100729T1143:
TDD to automate tests "seems" the way to go.
GUI needs to be scriptable, and HTML allows this.
Maybe JavaScript could be a problem, but if you could
append a [SCRIPT] tag and run it, it will be no problem

Enterprise, Human Resources, People and Wars:
- If you kill people, you must find and train new ones.
- If you forgive people, they will squeeze you.

No comments:

Post a Comment