"Reverse Alphabet Codes"
Given the following information:
a = 26, b = 25, c = 24, d = 23 ..... x = 3, y = 2, z = 1
What is the sum of each letter of this sentence: "The quick brown fox jumped over the cow"? (Note, a white space has no value).
You can simply reuse the code from challenge 4 and modify it to use these numbers, then change it to it does addition rather than multiplication.
Awnser:
T - 7 - 7
H - 19 - 26
E - 22 - 48
Q - 10 - 58
U - 6 - 64
I - 18 - 82
C - 24 - 106
K - 16 - 122
B - 25 - 147
R - 9 - 156
O - 12 - 168
W - 4 - 172
N - 13 - 185
F - 21 - 206
O - 12 - 218
X - 3 - 221
J - 17 - 238
U - 6 - 244
M - 14 - 258
P - 11 - 269
E - 22 - 291
D - 23 - 314
O - 12 - 326
V - 5 - 331
E - 22 - 353
R - 9 - 362
T - 7 - 369
H - 19 - 388
E - 22 - 410
C - 24 - 434
O - 12 - 446
W - 4 - 450
= 450
H - 19 - 26
E - 22 - 48
Q - 10 - 58
U - 6 - 64
I - 18 - 82
C - 24 - 106
K - 16 - 122
B - 25 - 147
R - 9 - 156
O - 12 - 168
W - 4 - 172
N - 13 - 185
F - 21 - 206
O - 12 - 218
X - 3 - 221
J - 17 - 238
U - 6 - 244
M - 14 - 258
P - 11 - 269
E - 22 - 291
D - 23 - 314
O - 12 - 326
V - 5 - 331
E - 22 - 353
R - 9 - 362
T - 7 - 369
H - 19 - 388
E - 22 - 410
C - 24 - 434
O - 12 - 446
W - 4 - 450
= 450
Source:
function solution(){ $result = 0; $word = "The quick brown fox jumped over the cow"; $letter2 = array( "A"=>26,"B"=>25,"C"=>24,"D"=>23,"E"=>22,"F"=>21,"G"=>20,"H"=>19,"I"=>18,"J"=>17,"K"=>16,"L"=>15,"M"=>14,"N"=>13,"O"=>12,"P"=>11,"Q"=>10,"R"=>9,"S"=>8,"T"=>7,"U"=>6,"V"=>5,"W"=>4,"X"=>3,"Y"=>2,"Z"=>1); $array = str_split(strtoupper(str_replace(" ", "", $word))); foreach( $array as $char){ $result += $letter2[$char]; echo $char." - ".$letter2[$char]." - ".number_format($result)."<br />"; } echo "<br /><strong> = ".number_format($result, 0, '.', '')."</strong>"; }