Skip to content

Instantly share code, notes, and snippets.

@savasdersimcelik
Created November 28, 2017 19:42
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save savasdersimcelik/d50457f623c50308e80a3574a9225667 to your computer and use it in GitHub Desktop.
PHP Dengeli Sayılar Algoritması
<?php
/**
* Author : Savaş Dersim ÇELİK
* Version: 1.0.0
* Web: http://webinyo.com
* Mail: savasdersimcelik@gmail.com
* Description : PHP Dengeli Sayılar Algoritması
*/
function tekcift($param)
{
$t = 0;
$c = 0;
foreach ($param as $key => $value) {
if ($value%2 == 0) {
$c++;
}else{
$t++;
}
}
if ($c == $t) {
return true;
}else{
return false;
}
}
function kontrol($param)
{
$parcala = str_split($param);
$badet = count(array_unique($parcala));
$gadet = count($parcala);
if ($gadet == $badet){
if (tekcift($parcala)) {
return true;
}
}
}
$sayac = 0;
for ($i=0; $i < 9999; $i++) {
if (kontrol($i)) {
$sayac++;
}
}
echo $sayac;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment