php - Optimized solution for a rolling dice code puzzle -
I was asked to provide a solution to this rolling dice problem in an interview when I showed them my solution, then they Said that there is another way to find solutions. I'm only looking for answers in PHP scripts.
Question:
Two people are playing the game of rolling 2 dipes. Every person revolves twice and records the results of all efforts (quantity of two colors). So after the efforts of both the players, we have two lists according to the results of two players.
They want to know whether they get all possible results (1 to 12) or not. If they get all possible results in the same number then they are called lucky.
Input : Two integer array (L1, L2)
Output according to the results of two players: Case of Lucky or unlucky on the basis
My answer:
& lt; Php function rollingdis ($ input1, $ input2) {$ a = array_count_values ($ input 1); $ B = array_count_values ($ input2); If (array_diff_assoc ($ a, $ b) || array_diff_assoc ($ b, $ a)) {return 'unlock';} return 'lucky'; }
Comments
Post a Comment