Last active
April 17, 2024 06:49
-
-
Save ElectricCoffee/5e87957047f21cfc9a82b7743de55e37 to your computer and use it in GitHub Desktop.
A simple script to find the percentage chance of rolling a pair on N dice.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NB. Preliminary research | |
die =. 1 + i. 6 | |
solution_1 =. ,(2 = #@~.)"1 (,"0 1/ ,"0/~)~ die NB. this solution assembles a matrix | |
solution_2 =. _3 (2 = #@~.)\ ; { 3 $ < die NB. this solution uses the catalogue function to create a table of boxes | |
solution_3 =. (2 = #@~.)"1 (#: i.@(*/)) 3 $ 6 NB. this solution was provided by elcaro | |
calc_pct =. 100 * # %~ +/ NB. chained forks are one hell of a drug | |
NB. Implemented solution | |
find_pairs =. verb define | |
6 find_pairs y | |
: | |
range =. 1 + i. x NB. the dice values... to be fair staring at 1 isn't strictly necessary. | |
window =. -y NB. go through the range y items at a time. Negation is just there to make the window chunky rather than sliding | |
counter =. y - 1 NB. when there are 3 dice, a pair will mean 2 unique dice, when there are 4, a pair will mean 3 unique dice. | |
window (counter = #@~.)\ ; { y $ < range | |
) | |
calc_pct find_pairs 3 | |
calc_pct 8 find_pairs 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment