Perl 5.10, 392 384 372 235 369 (ASCII) / 234 (Unicode)
Bunun en kısa ASCII sürümü 369 karakter uzunluğunda:
@_=(fly,spider,bird,cat,dog);$_="There was an old lady who!ed a";for$P("",",
That wrJand Jand jJinside her",",
How absurd&",",
Imagine that&",",
What a hog&"){$p=$c;$c=$".shift@_;$t=$p?"She!ed the$c to catch the$p,
$t":"I don't know why she!ed that$c,
Perhaps she'll die.
$_";$_.="$c$P.
$t";s/&/ to! a$c/}s/!/ swallow/g;s/J/iggled /g;say"$_ horse,
She died of course."
Bu temel programdan başladı:
my @animals = qw(fly spider bird cat dog);
my $buf = "There was an old lady who swallowed a ";
for my $phrase ( "",
",\nThat wriggled and iggled and jiggled inside her",
",\nHow absurd&",
",\nImagine that&",
",\nWhat a hog&" ) {
$previous = $current;
$current = shift @animals;
$trail = $previous ? "She swallowed the $current to catch the $previous,\n$trail"
: "I don't know why she swallowed that $current,\n"
. "Perhaps she'll die.\n\n$buf";
$buf .= "$current$phrase.\n$trail";
$buf =~ s/&/ to swallow a $current/;
}
say "$buf horse,\nShe died of course.";
Temel fikir, kafiyenin sonunu ve bir sonrakinin başlangıcını korumak, devam $trail
ettikçe onu arttırmak. İlk kullanım için özel bir durumun gerekmesi ve hayvan adı değişkenini hayvana özgü cümle ile bile yeniden kullanma girişimi gereği önemsiz hale getirildi. Diğer optimizasyonlar şunları içerir:
- her şey için tek karakterli tanımlayıcılar
- hayvan listesi için alıntılanan dizeler yerine korkaklar kullanmak
- Akümülatörün çoğu ikame işlemini daha da kısaltmak
$_
için $buf
kullanılması (kullanımı @_
alışkanlık nedeniyledir ve başka herhangi bir karakterden daha fazla bir şey kazanmaz)
- doğrudan hayvan adı değişkeninin içinde bulunan önceki boşluğu dahil etmek (değişkenden alınan boşluk karakteri
$"
)
- En sık kullanılan ifadeleri kısaltmak için regexp ikamesi:
' swallow'
ve'iggled '
- Herhangi bir kod
\n
dizgisi veya tümü , değişmez dizgede gerçek satırlar ile değiştirilmiş
Son optimizasyon dışındakilerin tümü bunu verir:
@_ = (fly, spider, bird, cat, dog);
$_ = "There was an old lady who!ed a";
for $P ( "",
",\nThat wrJand Jand jJinside her",
",\nHow absurd&",
",\nImagine that&",
",\nWhat a hog&" ) {
$p = $c;
$c = $" . shift @_;
$t = $p ? "She!ed the$c to catch the$p,\n$t"
: "I don't know why she!ed that$c,\nPerhaps she'll die.\n\n$_";
$_ .= "$c$P.\n$t";
s/&/ to! a$c/;
}
s/!/ swallow/g;
s/J/iggled /g;
say "$_ horse,\nShe died of course.";
Ek olarak, bu golf belirtilen kodlama sorununun kurbanı. Belirgin bir kodlamada bayt yerine tek tek karakterleri sayarken, başlamadan önce program kaynağını UCS2'den deşifre ederek büyük bir kazanım elde edersiniz. Nihai sonuç artık çok okunaklı değil, ama tamam. (234 karakter, perl -E''
her zamanki gibi bir fark olarak sayılır ) (UCS2'yi geçerli kılmak için arkadaki yeni satırı geri eklemem gerekiyordu)
$ perl -MEncode=from_to -e'$_="䁟㴨晬礬獰楤敲Ɫ楲搬捡琬摯朩㬤弽≔桥牥⁷慳渠潬搠污摹⁷桯Ⅵ搠愢㭦潲⠢∬∬桡琠睲䩡湤⁊慮搠橊楮獩摥敲∬∬ੈ潷扳畲搦∬∬浡杩湥⁴桡琦∬∬桡琠愠桯朦∩笤瀽④㬤挽␢桩晴䁟㬤琽⑰㼢卨攡敤⁴桥④⁴漠捡瑣栠瑨攤瀬ਤ琢㨢䤠摯渧琠歮潷⁷桹桥Ⅵ搠瑨慴④Ⰺ健牨慰猠獨攧汬楥⸊ਤ弢㬤弮㴢④⸊⑴∻猯☯⁴漡④⽽猯ℯ睡汬潷⽧㭳⽊⽩杧汥搠⽧㭳慹∤张桯牳攬桥楥搠潦潵牳攮∊";from_to($_,utf8,ucs2);eval'
Unicode'a başvurmadan önce golf oynamak için çok iyi bir şey vardı, yoksa çok eğlenceli olmazdı.
Düzenleme: 234 karakter sürümünü bu tarayıcıya kopyalamanın / yapıştırmanın bir yolunu bulamıyor, bu yüzden 235 karakterden ayrılıyorum. Ellerimi UTF8'e duyarlı bir panoya soktuğumda bu akşam düzeltecek. bir yol buldum. İdeoda yarı kanıt.