Restructuring

This commit is contained in:
2024-07-01 13:49:44 +00:00
parent f11b705ef0
commit 8d60e1b905
194 changed files with 1296 additions and 112 deletions

View File

@ -0,0 +1,15 @@
title: Coded triangle numbers
url: http://projecteuler.net/problem=42
desc: |
The nth term of the sequence of triangle numbers is given by, tn = 0.5n(n+1); so the first ten triangle numbers are:
1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...
By converting each letter in a word to a number corresponding to its alphabetical position and adding these values we form a word value. For example, the word value for SKY is 19 + 11 + 25 = 55 = t10. If the word value is a triangle number then we shall call the word a triangle word.
Using words.txt (right click and 'Save Link/Target As...'), a 16K text file containing nearly two-thousand common English words, how many are triangle words?
solution: Bruteforce
solutions:
solve.php:
desc: Expects data on STDIN
language: php
parameters: < ProjectEuler\042\words.txt

View File

@ -0,0 +1,18 @@
<?php
$words = explode('","',substr(file_get_contents('php://STDIN'),1,-1));
//Find triangles
for($t=1;$t<40;$t++) {
$triangle_numbers[] = 0.5*$t*($t+1);
}
foreach($words as $word) {
for($c =0; $c < strlen($word); $c++) {
$char_sum += ord($word[$c]) - 64;
}
if(in_array($char_sum,$triangle_numbers)) {
$result++;
}
$char_sum = 0;
}
echo $result;

File diff suppressed because one or more lines are too long