-
Notifications
You must be signed in to change notification settings - Fork 0
/
help-me-compress-this-song.php
64 lines (49 loc) · 1.63 KB
/
help-me-compress-this-song.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/**
* Code Golf: Help me compress this song
*
* @link https://codegolf.stackexchange.com/questions/216411/help-me-compress-this-song
*/
// The code-golf framework includes the testing frameworks and handles the command line
require __DIR__.'/a/CodeGolfFramework.php';
class HelpMeCompressThisSong extends ACodeGolfProblem
{
// required methods
public function runTests() {
it(
'generates the target poem',
$this->getFunctionOutput(function () { $this->cmprssThsSng(); }) === self::EXPECTED_OUTPUT
);
}
public function getTheGolfedCode() {
return str_replace('\n', "\n", parent::getFunctionBody('cmprssThsSng', __CLASS__));
}
public function runTheGolfedCode($argc, array $argv) {
this->cmprssThsSng();
}
public function cmprssThsSng() {
$a='aeiou';$x='muha na zid';$y="Priletela $x,";echo implode("\n\n",array_merge([$z="$y $x, $x.\n$y\n$x."],array_map(fn($e)=>preg_replace("/[$a]/",$e,$z),str_split($a))));
}
const EXPECTED_OUTPUT = <<< END
Priletela muha na zid, muha na zid, muha na zid.
Priletela muha na zid,
muha na zid.
Pralatala maha na zad, maha na zad, maha na zad.
Pralatala maha na zad,
maha na zad.
Preletele mehe ne zed, mehe ne zed, mehe ne zed.
Preletele mehe ne zed,
mehe ne zed.
Prilitili mihi ni zid, mihi ni zid, mihi ni zid.
Prilitili mihi ni zid,
mihi ni zid.
Prolotolo moho no zod, moho no zod, moho no zod.
Prolotolo moho no zod,
moho no zod.
Prulutulu muhu nu zud, muhu nu zud, muhu nu zud.
Prulutulu muhu nu zud,
muhu nu zud.
END;
}
exit((new HelpMeCompressThisSong($argc, $argv))->run());
// That's all, folks!