# [Community Puzzle] Short accounts make long friends

Coding Games and Programming Challenges to Code Better

Bonjour,
je nâ€™ai trouvĂ© aucun post sur ce puzzle, câ€™est pourquoi je crĂ©e celui-ci.
je bloque sur ce puzzle. Mon code est trop lent/long. Je combine tous les nombres avec toutes les opĂ©rations (mĂ©thode un peu brute-force). Je me doutais bien que cela allait coincer comme Ă§a.
Quelquâ€™un peut-il mâ€™indiquer une autre piste de rĂ©solution ?
Merci.

Hello,
I did not find any post on this puzzle, that is why I create this one.
I block on this puzzle. My code is too slow / long. I combine all the numbers with all the operations (a little brute-force method). I suspected that it would get stuck like this.
Can someone point me to another resolution lead?
Thank you.

1 Like

For any subset X of {a,b,c,d,e,f}, let S(X) be the set of all the values that can be reached using numbers from X. Find a way to compute S recursively â€“ while memoizing the already computed values â€“ to build an efficient enough dynamic programming approach.

2 Likes

Itâ€™s that kind of answer i was awaiting for. I donâ€™t ask for â€śtheâ€ť solution (no interest).
Thank you for this new approach. Iâ€™ll try it.
thanks again.

edit: but your approach also need to compute all that is possible from 6 numbers and 5 operators. Why should it be faster ?

@Zener Because with this approach you will structure the computation in such a way that you wonâ€™t do the same calculations too many times while, with your approach, one can guess that youâ€™re doing the same calculations lots of times.

1 Like

I also have tried brute-force, and it took like 40 minutes to calc all possible equations.
@Niako, now I am going to rewrite my code according with your suggestion.

Ahh, finally submitted! Less then a quarter of second.
The hardest problem, and Iâ€™ve learned a lot. Thank you, @Niako!

1 Like

@MooMooN, all cases go through but i only get 83% when i submit my solution. Iâ€™ve been tested my code with many other combination of numbers and it always works. It blocks on validator 5. Do you have any idea why ?

Validator 5 has nothing special so I did the puzzle to see what could go wrong.

I partition a set s into 2 subsets and find the results recursively on each subset, so basically it looks like this:

for s1, s2 in partition(s):
_for a in results(s1):
__for b in results(s2):
___consider all possible results

I could reproduce your error when I donâ€™t add a alone and b alone in all possible results

3 Likes