Skip to content

Instantly share code, notes, and snippets.

@thinkspill
Last active July 11, 2018 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thinkspill/2ce98b398c6baf8cdbef07898c7b571b to your computer and use it in GitHub Desktop.
Save thinkspill/2ce98b398c6baf8cdbef07898c7b571b to your computer and use it in GitHub Desktop.
Calculates Majority Values
<?php
$a = 1;
$b = 10;
$c = 100;
$d = 1000;
$v[] = '0000000';
$v[] = '0000001';
$v[] = '0000002';
$v[] = '0000003';
$v[] = '0000011';
$v[] = '0000012';
$v[] = '0000013';
$v[] = '0000021';
$v[] = '0000022';
$v[] = '0000023';
$v[] = '0000031';
$v[] = '0000032';
$v[] = '0000033';
$v[] = '0000111';
$v[] = '0000112';
$v[] = '0000113';
$v[] = '0000121';
$v[] = '0000122';
$v[] = '0000123';
$v[] = '0000131';
$v[] = '0000132';
$v[] = '0000133';
$v[] = '0000211';
$v[] = '0000212';
$v[] = '0000213';
$v[] = '0000221';
$v[] = '0000222';
$v[] = '0000223';
$v[] = '0000231';
$v[] = '0000232';
$v[] = '0000233';
$v[] = '0000311';
$v[] = '0000312';
$v[] = '0000313';
$v[] = '0000321';
$v[] = '0000322';
$v[] = '0000323';
$v[] = '0000331';
$v[] = '0000332';
$v[] = '0000333';
$patterns[] = ['a', 'b', 'c', 'd'];
$patterns[] = ['b', 'c', 'd', 'a'];
$patterns[] = ['c', 'd', 'a', 'b'];
$patterns[] = ['d', 'a', 'b', 'c'];
foreach ($v as $template) {
foreach ($patterns as $pattern) {
$currentTemplate = str_replace('0', $pattern[0], $template);
$currentTemplate = str_replace('1', $pattern[1], $currentTemplate);
$currentTemplate = str_replace('2', $pattern[2], $currentTemplate);
$currentTemplate = str_replace('3', $pattern[3], $currentTemplate);
$strings[$pattern[0]][] = $currentTemplate;
}
}
$values = [];
foreach ($strings as $key => $patterns) {
foreach ($patterns as $pattern) {
$values[$key][$pattern] = 0;
$arr = str_split($pattern);
foreach ($arr as $char) {
$values[$key][$pattern] += $$char;
}
}
$values[$key] = array_unique($values[$key]);
asort($values[$key]);
}
foreach ($values as $k => $v) {
echo "$k\n";
foreach ($v as $k => $v) {
echo "$k\t$v\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment