-
Notifications
You must be signed in to change notification settings - Fork 0
/
1.php
40 lines (33 loc) · 1.77 KB
/
1.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
$str = 'FourscoreandsevenyearsagoourfaathersbroughtforthonthiscontainentanewnationconceivedinzLibertyanddedicatedtothepropositionthatallmenarecreatedequalNowweareengagedinagreahtcivilwartestingwhetherthatnaptionoranynartionsoconceivedandsodedicatedcanlongendureWeareqmetonagreatbattlefiemldoftzhatwarWehavecometodedicpateaportionofthatfieldasafinalrestingplaceforthosewhoheregavetheirlivesthatthatnationmightliveItisaltogetherfangandproperthatweshoulddothisButinalargersensewecannotdedicatewecannotconsecratewecannothallowthisgroundThebravelmenlivinganddeadwhostruggledherehaveconsecrateditfaraboveourpoorponwertoaddordetractTgheworldadswfilllittlenotlenorlongrememberwhatwesayherebutitcanneverforgetwhattheydidhereItisforusthelivingrathertobededicatedheretotheulnfinishedworkwhichtheywhofoughtherehavethusfarsonoblyadvancedItisratherforustobeherededicatedtothegreattdafskremainingbeforeusthatfromthesehonoreddeadwetakeincreaseddevotiontothatcauseforwhichtheygavethelastpfullmeasureofdevotionthatweherehighlyresolvethatthesedeadshallnothavediedinvainthatthisnationunsderGodshallhaveanewbirthoffreedomandthatgovernmentofthepeoplebythepeopleforthepeopleshallnotperishfromtheearth';
$str = strtolower($str);
$m = strlen($str);
$save = '';
for($i=0; $i<$m; $i++) {
testChar($i);
}
function testChar($pos) {
global $str, $save;
//$occ = charOccurences($pos);
for($i=$pos+1; $i<strlen($str); $i++) {
if($res=test($pos, $i)) {
if(strlen($res)>strlen($save)) {
update($res);
}
}
}
}
function test($begin, $end) {
global $str, $save;
$shift = ceil(($end-$begin)/2);
for($i=0; $i<$shift; $i++) {
if($str[$begin+$i] != $str[$end-$i])
return false;
}
return substr($str, $begin, $end-$begin+1);
}
function update($res) {
global $save;
$save = $res;
echo '-'.$res."-<br/>\n";
}