Skip to content

Instantly share code, notes, and snippets.

@sniper7kills
Last active August 29, 2015 14:20
Show Gist options
  • Save sniper7kills/d6eef1da44da886c7d30 to your computer and use it in GitHub Desktop.
Save sniper7kills/d6eef1da44da886c7d30 to your computer and use it in GitHub Desktop.
Grant-P17
<?php
$char_count=0;
//Number To British English
function num2brit($number)
{
$n2t = new NumberFormatter("en", NumberFormatter::SPELLOUT);
$out = "";
//Thousands
if($number/1000 >= 1)
{
$out .= $n2t->format(floor($number/1000))." Thousand ";
if($number%1000 > 0)
$out .= "And ";
$number=$number%1000;
}
//Hundreds
if($number/100 >= 1)
{
$out .= $n2t->format(floor($number/100))." Hundred ";
$number=$number%100;
if($number%100 > 0)
$out .= "And ";
$number=$number%100;
}
if($number > 0)
{
$out .= $n2t->format($number);
}
return $out;
}
//This part works for the most part. We just were using American English not British English....
for($x=1;$x<=1000;$x++)
{
//Converts the number to text format
$text = num2brit($x);
//Keep only A-Z and a-z, get rid of spaces and tack's (-)
$text = preg_replace("/[- ]/", '', $text);
//die($text);
//Creates an array with ascii code as the Key and the number of times as the value
$array = count_chars($text,1);
foreach($array as $key => $value)
{
$char_count+=$value;
}
//die($char_count."\n");
}
echo "There are ".$char_count." Characters total when adding them all up from one to one thousand";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment