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

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -