Skip to content

Instantly share code, notes, and snippets.

@savasdersimcelik
Created November 17, 2017 22:50
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 savasdersimcelik/e449a533dbcf784b49a8e7f380a193c8 to your computer and use it in GitHub Desktop.
Save savasdersimcelik/e449a533dbcf784b49a8e7f380a193c8 to your computer and use it in GitHub Desktop.
<?php
/**
* Author : Savaş Dersim ÇELİK
* Version: 1.0.0
* Web: http://webinyo.com
* Mail: savasdersimcelik@gmail.com
* Description : Harshad Sayılarını Listeleyen Algoritma
*/
error_reporting(0);
function harshad($param)
{
$parcala = str_split($param);
$topla = 0;
if (strlen($param) < 2) {
return false;
}
for ($i=0; $i < count($parcala); $i++) {
$topla = $topla + $parcala[$i];
}
if ($param % $topla == 0) {
return true;
}
}
$sayac = 0;
for ($s=0; $s < 200000; $s++) {
if (harshad($s)) {
$sayac++;
}
}
echo $sayac;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment