
Ask HN: How do you approach a problem when you are stuck? - altaaf_baatli
I have been thinking about this. For eg, let&#x27;s say I am following implementing a design pattern and I am stuck at implementing a specific feature adhering to that pattern. I usually search for it online and then try to implement as suggested (I don&#x27;t have much experience, I am a new grad). What do you think?. Should I implement my own solution first even if it violates the design pattern, then check if my solution was correct, or do I search on the internet the correct way to implement the feature?
======
muzani
I assume you're learning, not debugging.

There's a period of time where it's worth trying. It varies a lot, depending
on your willpower and how important a problem is.

If you're just trying to solve a Hackerrank problem, you should probably spend
30-60 minutes on it. You'll want to go long enough to not get frustrated with
it.

Sometimes copying solutions is better. I learned map(), reduce(), filter()
that way - these are all things that can be solved a slow way, but doing it in
less lines of code is very good.

You can try copying a solution, then try solving the problem again based off
memory. It's good to practice repeated basics like array manipulation and type
conversion until it's muscle memory. Design patterns tend to be quite rare and
it's fine to do it once and reference it every other time.

------
JohnFen
If I'm well and truly stuck, then what I do is put the problem on the back
burner for a while (typically a day or two), and work on a different,
preferably unrelated, thing. I very often find that when I come back to the
problem I was stuck on, I find a solution or direction that I was blind to
before.

I use this "distraction" technique when I'm stuck on any problem in life, too,
not just programming ones. I find it very powerful.

If I remain stuck, then I begin to entertain the idea that the problem itself
is the result of a different problem elsewhere and investigate that
possibility. Sometimes a problem is intractable because the issue isn't really
in the code you're working on, but is the result of a larger design issue.

------
afarrell
ADHDer here. I can help with this.

When you are stuck, it probably means you are too focused. You should turn
your attention-thermostat more toward the exploratory side of things. You also
probably want to talk the problem through with a coworker whom you like who is
good at being a sounding board.

\------------------

# Explanation: Working Memory and Scope of Attention

# Working Memory

You know how a computer processor has registers and it performs operations on
the values stored in those registers? Your brain has Working Memory and it can
hold 4-9 "chunks" of information. More if you are relaxed and confident in
your social position, Fewer chunks if you are stressed or worried about being
kicked out of your social group.

A "chunk" is any piece of information that you are able to think about as a
single thing.

\- Your own home address is 1 chunk

\- A stranger's home address is 4 chunks (house number, street name,
city+state, postcode)

\- A stranger's address whom you've said out loud a couple times is 2 chunks I
guess.

\- A design pattern you know well is 1 or 2 chunks.

\- A design pattern you've not yet learned is 5-15 chunks.

Your brain decides what to hold in your Working Memory based on a whole lot of
things. The mental act of focusing is ignoring ideas and stimuli in order to
preserve specific information in your working memory. If you google
"mindfulness meditation" or "sniper breath control technique" and try doing
either, you can observe this process in action.

> I am a new grad

Great. Picture a massive undirected graph of all the wikipedia articles and
their links to each other. Now picture a graph of all conceivable ideas and
the conceptual links that might lead the thought of one to lead to another.
When you focus, you tell your brain "If the concept doesn't seem like X, don't
traverse this edge."

In your case, it seems like you are telling your brain "If adding the new idea
doesn't mean that I can put together full solution from what is in Working
Memory, stop." Well it turns out that code and design patterns can be
complicated and trying to do the whole thing at once might take more Working
Memory than you have. However, doing the imperfect solution would:

1) Take some of the complexity out of your head and put it into a text editor.
Thus, it would also "chunk" it and free up space in your working memory for
manipulating the rest of the complexity.

2) Cause you to traverse the graph of ideas more. With your working memory
freed up, you might spot a solution which is based on the crappy version but
closer to what you want.

So my advice is to ego for a walk for a bit and let your brain expand the set
of possibly-relevant ideas.

------
yourdadbitch
Fuck u bit- __*CH

------
internet_user
"Invert, always invert" \- Jacobi.

------
yourdadbitch
Fuck you bitch

