Top Coder Challenge: it adds up / countdown! | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 7

Top Coder Challenge: it adds up / countdown!

See here: https://www.youtube.com/watch?v=pfa3MHLLSWI You are given one number N, 6 numbers chosen randomly in the following set : 1,2,3,4,5,6,7,8,9,25,50,75,100. The goal is to use the numbers & operators (+-×/) to be as close as possible as N. You cant repeat the numbers and each step has to produce integers. See https://www.youtube.com/watch?v=h9vH7YGotQc With [1,6,2,9,7,7],945 answer is (7*2+1)*7*9=945 With [1,2,3,4,5,6],999 =>2*4*5*6*(1+3)=960 (999 not doable) Write a program solving this game and giving a solution.

10th Sep 2017, 9:07 AM
VcC
VcC - avatar
17 Réponses
+ 4
6! = 720 possible number positions 4^5 = 1024 possible operations
10th Sep 2017, 3:42 AM
hamletmun
hamletmun - avatar
+ 4
I've finished my first version, it barely runs :) plus I'll be optimizing it this is by backtracking https://code.sololearn.com/WqsZ5ifZ0c37/?ref=app
10th Sep 2017, 10:18 PM
ysraelcon
ysraelcon - avatar
+ 3
Also look at this as a way to get rid of () : https://en.wikipedia.org/wiki/Reverse_Polish_notation As well as this research paper (fairly recent) on the number of options to evaluate : https://arxiv.org/pdf/1502.05450.pdf Solution implementing the depth first method : https://code.sololearn.com/ccQZXwI4XcH7/#py
10th Sep 2017, 8:57 AM
VcC
VcC - avatar
+ 2
I'm building my own one :), based on: http://www.jlabstudio.com/webgl/ejemplos/cifrasyletras/
9th Sep 2017, 2:36 PM
ysraelcon
ysraelcon - avatar
0
Now i have ! Congrats you won. Can be a good exercice to try to make the code more compact by using arrays of functions. Regarding the complexity i think this complexity is intrinsically high. Unless you find a smart way to deal with operator priority (lile only testing solutions where they are in non decreasing priority order since the numbers will take any position - this would be still exponential but quicker by a factor of 50).
10th Sep 2017, 5:49 AM
VcC
VcC - avatar
10th Sep 2017, 6:12 AM
VcC
VcC - avatar
0
Agree but a brute force solution even with some redundancies would win the challenge so far ! In this case finding the way to quickly do the brutal method is already a good coding exercise (using functionnal programming). And since the problem is of limited size by definition the asymptotic complexity for very large sizes is less important than how it runs for n=6.
10th Sep 2017, 6:28 AM
VcC
VcC - avatar
0
Thanks to you. Your solution led me to look for complexity analysis. Funny to see so few references.
10th Sep 2017, 10:11 AM
VcC
VcC - avatar
- 1
You cant repeat the numbers and each step has to produce integer numbers.
9th Sep 2017, 4:58 AM
VcC
VcC - avatar
- 1
Other test examples : #[100,10,7,5,7,75],232 #[8,75,1,10,9,3],747 #[2,6,1,8,5,9],265 #[2,5,10,75,50,8],417 #[3,100,8,8,10,6],683
9th Sep 2017, 7:59 AM
VcC
VcC - avatar
- 1
@moby The challenge is to make a programml finding the solution given the target and the authorized numbers.
9th Sep 2017, 1:40 PM
VcC
VcC - avatar
- 1
Hey good 1st step anyways ;-)
9th Sep 2017, 2:16 PM
VcC
VcC - avatar
- 1
Hope so ! You kook like one of the few taking more complex challenges here ;-)
9th Sep 2017, 3:05 PM
VcC
VcC - avatar
- 1
Try to find the calculations(+ - * /) you have to do in the given number to find the target. Now code a program doing this automatically when given a set of numbers and a target
9th Sep 2017, 8:10 PM
VcC
VcC - avatar
- 1
Just looked at the code from my laptop - looks much more readable. Less the case from a mobile phone !
10th Sep 2017, 6:32 AM
VcC
VcC - avatar
- 1
You never give up ! Good one.
11th Sep 2017, 5:23 AM
VcC
VcC - avatar
- 1
Btw you did not select a winner for range extraction...
11th Sep 2017, 5:23 AM
VcC
VcC - avatar