{}
62
%OFF

Stop copy pasting code you don't actually understand

Build the coding confidence you need to become a developer companies will fight for

Stop copy pasting code you don't actually understand

Become a PRO
Become a PRO
62
%OFF

Stop copy pasting code you don't actually understand

Build the coding confidence you need to become a developer companies will fight for

Stop copy pasting code you don't actually understand

Become a PRO
Become a PRO
run-icon
main.php
<?php // roll 3 dice // what is the maximum number of dice rolled the same? $diceSetAside = 0; $rolls = 0; $noOfDice = 10; $noOfRolls = pow(6, $noOfDice); $padTemplate = '%0'. $noOfDice .'d'; for($allDice=0;$allDice<$noOfRolls;$allDice++) { // convert e.g. 100 base 10 // to 244 // the roll 6 is represented by 0 $allDiceSix = base_convert((string)$allDice, 10, 6); // pad with leading zeroes $allDiceSixPad = sprintf($padTemplate, $allDiceSix); // count the most frequent die value $tmp = max(array_count_values(str_split($allDiceSixPad))); // set that number of dice aside in this round $diceSetAside += $tmp; // count this round $rolls++; } print "$diceSetAside $rolls " . $diceSetAside/$rolls; ?>
Output