Trouble With Algorithms

here’s what I’d do

0 . relax - grab a coffee and snack - keep munching for the next 8 steps
1 . simply read the problem statement and instructions once - no need to completely understand anything
2 . work through any provided examples in your head once
3 . look at the test cases in order
4 . carefully examine the inputs of a test case - how many inputs are there - what is the type of each input - what is the meaning of each input
5 . carefully examine the output and result of a test case - what is the type of the output - what does the output mean?
6 . Make sense of the relationship between the output and the inputs - does it jibe with your understanding of the problem? read and re-read the problem statement till it does
7 . do not solve any test case or the problem in general - the goal is to simply validate the test case against the problem statement
8 . repeat for 2-3 test cases

after completing the steps above you’re ready to approach solutions to the problem

now to work

put the snack down - seriously
grab paper and pencil
we want to approach a solution - not necessarily actually solve the problem since with programming there’s no actual solution till the code works
we just want a preliminary phase - an intermediate stage that will guide us and to which we can return and reconsider when the code turns ornery

write the first test case - use whatever notation you like
e.g. the first palindromes test case is palindrome(“eye”) should return a boolean

ok - that’s stupid
write the second test case - palindrome(“eye”) should return true - this is what I’d write

eye -> true

the idea now is to describe a solution in everyday language - no code - no variables - no arrays - no loops - no lambda combinators
pretend you’ll need to explain the solution to a fifth-grader - from 100 years ago - before fifth-graders used to write facebook apps

while we want to avoid programming terms at this stage we do want to be as precise and most importantly as deterministic as possible
we want a solution with instructions that are repeatable no matter who or what follows them
it’s just that our early instructions will be in ordinary english given to the hypothetical fifth-grader

1 Like