Programming Rock, Paper, Scissors choice combinations - Javascript -



Programming Rock, Paper, Scissors choice combinations - Javascript -

forgive me if topic on has been created, i've looked , can't seem find it.

i trying figure out how output of every single possible combination of stone paper scissors choices there based on x amount games.

the equation how many possible results there simple - x^y = results.

(x yth power--where x equals number of games , y equals number of choices--equals number of possible combinations.)

so lets 1 person plays 3 games of rock, paper, scissors. that's 3^3 = 27.

if rock = 1, scissors = 2, , paper = 3, ( listed them in order can go left right on beats which) results be: 111, 112, 113, 121, 122, 123 ... , on...

but question is, how output? 3^3, outer loop, 1 inner loop, 1 inner loop one. need dynamic, can pass in x number of games, , y number of choices, , have homecoming array of possible combinations of choices there are. i'm thinking can have 1 loop every column (where columns equal number of games) .. i'm not sure how i'd this.

i need results in array can combos later on.

can help me out this?

all need logic, pseudo-code fine. solid script great too.

thanks in advance!

i think library solves problem: https://github.com/dankogai/js-combinatorics (script: https://raw.githubusercontent.com/dankogai/js-combinatorics/master/combinatorics.js) function utilize is:

basen = combinatorics.basen([1,2,3], 3); console.log(basen.toarray())

where 1,2,3 possible options , 3 number of repetitions. give array of 27 different combinations can achieve.

javascript

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -