Project Euler.net Answers
Problem 22
Solved on 2/27/2008
Using names.txt, a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out the alphabetical value for each name, multiply this value by its alphabetical position in the list to obtain a name score.
For example, when the list is sorted into alphabetical order, COLIN, which is worth 3 + 15 + 12 + 9 + 14 = 53, is the 938th name in the list. So, COLIN would obtain a score of 938 × 53 = 49714.
What is the total of all the name scores in the file?
Find the sum of all the multiples of 3 or 5 below 1000.
first I ran ...cat names.txt | tr ',' '\n' >> names.csv to get it into a csv
next I sorted it in spreadsheet and added a rank column
then I ftp the file to the server>
$handle = fopen("names_ord.csv", "r");
$c = 0;
$answer = 0;
while ($c <5163) {
$data = fgetcsv($handle, 100, ",");
$rank = $data[0];
$name = $data[1];
$value = $this->getValue($name);
$tv = $rank*$value;
$answer += $tv;
$c++;
}
public function getValue($name){
$len = strlen($name);
$return = 0;
for($p = 0;$p<$len; $p++){
$return += ord(substr($name, $p,1))-64;
}
return $return;
}
$answer = 871,198,282
Wells Ideas Inc. launches their redesigned site.
The site is built on a symfony platform and utilizes client information from their project management site.
- Bertrand Russell
Contact Us | Site Map | Open Source Solutions | Templates | Client Login
