Skip to content

Instantly share code, notes, and snippets.

@mrcat323
Last active January 8, 2020 10:55
Show Gist options
  • Save mrcat323/f3116b6796b06d044d623653b5fa36d9 to your computer and use it in GitHub Desktop.
Save mrcat323/f3116b6796b06d044d623653b5fa36d9 to your computer and use it in GitHub Desktop.
Sums of Digits, algorithm and code
<?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