Skip to content

Instantly share code, notes, and snippets.

@fajarwz
Created February 21, 2022 16:08
Show Gist options
  • Save fajarwz/54febb0ae53a2f0c10a02d50a6d8052e to your computer and use it in GitHub Desktop.
Save fajarwz/54febb0ae53a2f0c10a02d50a6d8052e to your computer and use it in GitHub Desktop.
get minimum dice flip count
<?php
function flip_count($arr) {
$flip_count;
$min_flip_count = 9999999;
foreach ($arr as $value) {
$flip_count = 0;
foreach ($arr as $value2) {
if ($value == $value2) {
$flip_count += 0;
} else if ($value + $value2 == 7) {
$flip_count += 2;
} else {
$flip_count += 1;
}
}
if ($flip_count < $min_flip_count) {
$min_flip_count = $flip_count;
}
}
return $min_flip_count;
}
echo flip_count([1,2,3]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment