Last active
January 8, 2020 10:55
-
-
Save mrcat323/f3116b6796b06d044d623653b5fa36d9 to your computer and use it in GitHub Desktop.
Sums of Digits, algorithm and code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# Sums of Digits | |
# Algorythm and code | |
# By Mr CaT | |
# Copyright (c) 2017 | |
function fix($a,$b,$c) | |
{ | |
global $d; # Our global var, will be $d | |
$d = $a * $b + $c; # D is a * b and plus c | |
# Convert string to array | |
$ar = str_split($d); | |
# Our var result must be empty | |
$result = ""; | |
for($i=0;$len = sizeof($ar), $i < $len; $i++) { | |
# The same thing like '$result = $result + $ar[$i]'; | |
# We just plus all elements of array | |
$result += $ar[$i]; | |
} | |
# Printing the result | |
echo $result; | |
} | |
# The result will be '14' | |
fix(255, 12, 32); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment