2 kyu

Fastest Code : Equal to 24

443 of 964myjinxin2015

Description:

This is the Performance version of simple version. If your code runs more than 7000ms, please optimize your code or try the simple version

Task

A game I played when I was young: Draw 4 cards from playing cards, use + - * / and () to make the final results equal to 24.

You will coding in function equalTo24. Function accept 4 parameters a b c d(4 numbers), value range is 1-100.

The result is a string such as "2*2*2*3" ,(4+2)*(5-1); If it is not possible to calculate the 24, please return "It's not possible!"

All four cards are to be used, only use three or two cards are incorrect; Use a card twice or more is incorrect too.

You just need to return one correct solution, don't need to find out all the possibilities.

The different between "challenge version" and "simple version":

1) a,b,c,d range:  In "challenge version" it is 1-100, 
                   In "simple version" it is 1-13.
2) "challenge version" has 1000 random testcases,
   "simple version" only has 20 random testcases.

Some examples:

equalTo24(1,2,3,4) //can return "(1+3)*(2+4)" or "1*2*3*4"
equalTo24(2,3,4,5) //can return "(5+3-2)*4" or "(3+4+5)*2"
equalTo24(3,4,5,6) //can return "(3-4+5)*6"
equalTo24(1,1,1,1) //should return "It's not possible!"
equalTo24(13,13,13,13) //should return "It's not possible!"
equalTo24(1,2,3,4) # can return "(1+3)*(2+4)" or "1*2*3*4"
equalTo24(2,3,4,5) # can return "(5+3-2)*4" or "(3+4+5)*2"
equalTo24(3,4,5,6) # can return "(3-4+5)*6"
equalTo24(1,1,1,1) # should return "It's not possible!"
equalTo24(13,13,13,13) # should return "It's not possible!"

Series:

Puzzles
Games

Stats:

CreatedJun 1, 2016
PublishedJun 1, 2016
Warriors Trained5924
Total Skips1361
Total Code Submissions11812
Total Times Completed964
JavaScript Completions443
CoffeeScript Completions13
Python Completions532
Total Stars330
% of votes with a positive feedback rating91% of 192
Total "Very Satisfied" Votes163
Total "Somewhat Satisfied" Votes24
Total "Not Satisfied" Votes5
Total Rank Assessments5
Average Assessed Rank
2 kyu
Highest Assessed Rank
2 kyu
Lowest Assessed Rank
4 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • JohanWiltink Avatar
  • Voile Avatar
  • metalim Avatar
  • Jomopipi Avatar
  • user9644768 Avatar
  • fsafsffs Avatar
Ad