
Solving Programming Puzzles Without Using Your Brain - lelf
https://doisinkidney.com/posts/2019-06-04-solving-puzzles-without-your-brain.html
======
bspammer
I love the idea of using OEIS to automate finding mathematical patterns in the
solution. Also, plotting the search space immediately is something I _know_ is
often unreasonably effective, but I almost never take the time to do. This is
a fantastic little article.

~~~
glangdale
Given that I'm a bit of a moron mathematically, I have, more times than I
cared to admit, made serious progress on a problem by (a) writing a Python or
C++ program to spew out a highly non-scalable count of some entity whose
nature I'm trying to understand and (b) taking that count and sticking it in
OEIS.

This has led to some pretty major insights, which one can carefully 'launder'
casually as something you knew all along. "Oh, of course the number of
subtrees can be found by half-Catalan numbers", you say, with aplomb, as if
you hadn't learned about half-Catalan numbers approximately 10 minutes ago.

------
mankeysee
Well haha still seems like a lot of brain was put into it.

Also, there's a simpler pattern to the sequence that is easily observable
without even opening OEIS.

~~~
gjm11
Unfortunately, if you spot _that_ pattern then you will not guess the correct
generalization. It seems that this may be a puzzle that's easier to solve if
you aren't good at spotting easy things.

~~~
mankeysee
Well tbh, it seems 2^k-1 does actually match the sequence as far as it is
shown. Perhaps there is a proof that n=2^k-1 for the numbers where 2^n is
divisible by (n+1). I'll have to see.

------
grive
Transforming a problem into pattern recognition seems like a good way to use
your brain natural inclinations.

Very neat little article.

------
catchmeifyoucan
I got lost at step 3. I wasn't super clear in how we went from line to
memoization. Cool article though - I had never thought of plotting before to
recognize patterns.

~~~
oisdk
If you write out the coordinates for a straight line from the origin they look
like this:

    
    
        3, 5; 6, 10; 9, 15...
    

So now, instead of having to test 6, 10 and 9, 15 when we see it, we can just
test 3, 5 once and we'll know the answer to all of the points on that line.
Then, to answer the question "which line is this point on?" we simplify the
fraction (i.e. 2, 6 -> 1, 3).

------
panzerklein
Google Foobar puzzles are amazing. Solving them was immensely fun and
challenging. Best code I ever wrote.

------
pmoriarty
_" While Python is usually great for programming puzzles, this step in
particular is crying out for something like QuickCheck: without it, we'll have
to roll our own."_

Instead of rolling his own, the author could have just used Python's
_Hypothesis_ package.[1][2]

[1] -
[https://github.com/HypothesisWorks/hypothesis](https://github.com/HypothesisWorks/hypothesis)

[2] -
[https://pypi.org/project/hypothesis/](https://pypi.org/project/hypothesis/)

------
username90
The bad thing about not using your brain is that you don't learn anything.

------
piterdevries
Do that in a face to face interview. Good luck with that.

~~~
ALittleLight
Do you mean write the naive solution and explain how you'd turn it into a good
solution? I think that would be well received.

