Hey all, for your answer to be considered the winner we need to see two solutions, 1 for the basic version and 1 for the intermediate version, both refined to be as efficient as possible. Preferably put both solutions in one repl.it file called
Also, a combination of just one digit is valid. I.e. the ways to make
2 are :
2 Or for the intermediate difficulty just
And some notes so far:
Firstly, every one of these solutions is a very nice implementation! I'm just posting ways it could be made even better...
@gargol12 your code needs to:
you only use three.
@smreia there is quite a lot of redundant code in your solution, For example when you check
n1 != n2 this is already checked in the if block above it, perhaps have another look through to make it more efficient.
@fredswed your code includes 0:
@rd0122 if you're looking for efficiency, there's a few places you can neaten up the code. E.g.
nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]
av_nums = [x for x in nums if x < z]
can be turned into:
av_nums = [x for x in range (1,10) if x < z]
And you do a couple of slow calculations multiple times instead of using some temp variables. On the other hand you also use temp variables where they're not needed. If you look over your code there's one place that you could add an extra line rather than having 6 lines at the bottom of your code.
Your code will be a really really great solution if you make some of these changes
@shrinkhla same as a few above your code allows for
0. Also please use
repl.it , if you wish your code to be considered when looking for the winner
@lmreia it seems like your recursion checks too many different inputs. If you can cut this down this would be a very good contender for best solution. E.g. for
3 your program runs the inside of that for loop 78 times. Whereas you only really need to check:
1 - small
1 + 1 - small
1 + 2 - correct break
2 - small
3 - correct break
So in an optimum world it would only run the middle of the for loop 5 times. Also, could you edit your code so it assumes a max of 5 possible digits, as stated in the challenge description, or so it has a max of
Hope this helps everyone, don't forget the two key points at the start!!