Skip to content

Instantly share code, notes, and snippets.

@savasdersimcelik
Last active November 30, 2017 20:40
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/402747b7c804cd568ad9b6250207b4f6 to your computer and use it in GitHub Desktop.
Save savasdersimcelik/402747b7c804cd568ad9b6250207b4f6 to your computer and use it in GitHub Desktop.
PHP Armstrong Sayılar Algoritması
<?php
/**
* Author : Savaş Dersim ÇELİK
* Version: 1.0.0
* Web: http://webinyo.com
* Mail: savasdersimcelik@gmail.com
* Description : Armstrong sayılar PHP Algoritması
*/
function armstrong($param){
$toplam = 0;
$parcala = str_split($param);
foreach ($parcala as $key => $value) {
$toplam = $toplam + pow($value, strlen($param));
}
return $toplam;
}
$sayac = 0;
for ($i=1; $i < 100000; $i++) {
if (armstrong($i) == $i) {
echo $i. '<br>';
$sayac++;
}
}
echo $sayac;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment