[첫화면으로]CodeGolf/99BottlesOfBeer

마지막으로 [b]

[Code Golf | 99 Bottles Of Beer]

주인장 혼자 끙끙댄 걸로는 Perl 223바이트가 한계. 1등은 170바이트인데 도대체 53글자를 어디서 줄인다냐 -_-;

# 줄바꿈을 전부 없애면 223바이트
$B=" on the wall";
sub b{"$_[0] bottle".(($_[0]>1)?"s":"")." of beer"}
print b($_),"$B, ",b($_),".\n",
(($_>1)?"Take one down and pass it around, ":"Go to the store and buy some more, "),
b($_-1||99),"$B.\n\n"
for reverse(1..99)

1. 홀인원을 향하여

이건 안된다는군요...

#!/usr/bin/perl
use LWP::Simple;
my $a=get "http://codegolf.com/competition/output/99-bottles-of-beer";
$a=~s/\<.+\>//g;
print $a;

-- 조프 2007-6-11 6:39 pm

음 역시나 찾아보니 "You will be unable to import/require/include any modules or files in your solution. You have to write all the code yourself, and it has to be in the code file you upload."

-- 조프 2007-6-11 6:41 pm

http://99-bottles-of-beer.net/language-perl-737.html

-- 조프 2007-6-11 6:48 pm

아 Alternative Versions 는 보지 마시길.
-- 조프 2007-6-11 6:49 pm

저는 역시 길이 없는 데서 길을 만드는 건 못하는 것 같아요 흐... 일단 방향이 주어지면 거기서 어떻게든 줄이는 건 하겠는데.

-- Raymundo 2007-6-11 7:14 pm

Alternative Versions를 참고해서 196자까지는 만들어봤습니다.

-- 조프 2007-6-11 8:31 pm
$y=99;
$B=" on the wall";
sub b{$n=$y||99;"$n bottle"."s"x!!--$n." of beer"}
print b,"$B, ",b,".\n",
--$y?"Take one down and pass it around, ":"Go to the store and buy some more, ",
b,"$B.\n\n"
while $y

오오 조프님 불타오르시는군요!

-- Raymundo 2007-6-11 10:14 pm

"s"x!!(--$n) 이라니... 절로 고개가 숙여지는군요.

-- Raymundo 2007-6-11 10:19 pm

그게 위에 올린 사이트에 있던 소스입니다...
-- 조프 2007-6-11 10:43 pm

^^; 사실 저도 그 버전 아까 봤는데요, ("보지 마시길"하는 문구를 보고 10분 정도 참았으나, 어차피 제 힘으로 더 줄이려면 얼마나 많은 시행착오가 있을지 몰라서..;;)

이왕 참조하는 김에 그 페이지 하단에 있는 것도 참조하여... 180자짜리를 만들었습니다. 근데 위의 코드는 그래도 이해가 되는데 하단에 있는 건.... 제가 수정해 놓고도 왜 이게 되는지 모르는 부분들이 있군요. -_-;
-- Raymundo 2007-6-11 11:03 pm

sub'b{[@b=(abs||99,bottle."s"x!!++$_,of,beer),on,the,wall]}
print "@{+b}, @b.\n"
.($_?"Take one down and pass it around":"Go to the store and buy some more")
.", @{+b}.\n\n"for-99..-1

음, Take one 어쩌고 하는 라인의 앞뒤를, .으로 스트링 붙이기를 하지 않고 쉼표로 구분하면 괄호를 없앨 수 있으니 2글자 줄일 수 있군요.

괄호 제거, print 직후의 공백 제거, 그리고 "\n"을 코드 자체의 줄바꿈으로 처리해서 174바이트짜리:

sub b{[@b=(abs||99,bottle."s"x!!++$_,of,beer),on,the,wall]}print"@{+b}, @b.
",$_?"Take one down and pass it around":"Go to the store and buy some more",", @{+b}.

"for-99..-1
4글자를 도대체 어디에서 더 제거할 수 있을 것인가!! 아니면 170자짜리가 되려면 이런 형태에서는 불가능하고 처음부터 뜯어고쳐야 할지도?
-- Raymundo 2007-6-12 12:21 pm

(코드 적는데는 코멘트 매크로가 방해만 되는 터라, 매크로 없앴습니다)



기타분류

마지막 편집일: 2012-2-11 12:25 am (변경사항 [d])
965 hits | Permalink | 변경내역 보기 [h] | 페이지 소스 보기