CJam, 1051 827 643 569 545 407 327 279 235 233 229
''"','#'C'J'a'm',' qYew::-Yf#:+e#'''''''''"
f{-ci'(*''2*\}'^,40>"*/:N"-"][ZZ[\^__`bcdgimpstsz{}~~~"
Chương trình trên tạo mã nguồn thực tế, dài 1.179.112 byte.
Kiểm tra
Sử dụng trình thông dịch Java , mã nguồn có thể được tạo và kiểm tra như thế này:
$ alias cjam='java -jar cjam-0.6.5.jar'
$ cjam gen.cjam > diff.cjam
$ cksum diff.cjam
896860245 1179112 diff.cjam
$ cjam diff.cjam < diff.cjam
#CJam, 229
Phiên bản thay thế
Với chi phí 36 điểm - cho số điểm cuối cùng là 265 - chúng tôi có thể làm cho mã nguồn ngắn hơn 99,92%:
'''()))))(''''(((('''())))))))))))))))))))))))))))('''()))))))))))))))))))))))))))))))))))('''())))))))))))))))))))))))))))))))))))))))))))))))))))))))))('''())))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))('''()))))(''''((((((('())))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))('())))))))))))))))))))))))))))))))))))))))))))))))))('())))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))('())))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))('()))))))))))))))))))('()))))))))))))))))))('())))))('())))))))))))))))))))))))))))))))))))))))))))))))))('()))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))(''(((('()))))))))))))))))))('())))('())))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))(''((((''''''''''''''''''()+,-.0123456789;<=>?@ABCDEFGHIJKLMOPQRSTUVWXYZ[\]][ZZ[\^__`bcdgimpstsz{}~~~
Bạn có thể thử phiên bản trực tuyến này trong trình thông dịch của CJam .
Ý kiến
Chúng tôi muốn thực thi mã
'#'C'J'a'm',' qYew::-Yf#:+
giữ điểm càng thấp càng tốt. Để đạt được điều này, chúng tôi sẽ xây dựng chuỗi ký tự đó theo từng ký tự (với một vài lần không trước và sau) và đánh giá kết quả.
May mắn thay, '
(đẩy ký tự theo nghĩa đen), (
(giảm) và )
(tăng) là các ký tự ASCII liên tiếp, do đó việc đẩy các ký tự tùy ý là tương đối rẻ tiền.
Các ký tự ASCII sau '
có thể được đẩy như '()…)(
, trong đó số lượng )
phụ thuộc vào điểm mã.
Ví dụ, +
có thể được đẩy như '())))(
. Khoảng cách giữa '
và (
và (
và )
là 1. Các dấu )(
triệt tiêu lẫn nhau; chức năng duy nhất của chúng là mở đường cho các mục sau '
(tương ứng với ký tự tiếp theo) với các ký tự liên tiếp.
Nhân vật được đẩy theo cách này sẽ nâng số điểm lên 4 điểm.
Các ký tự ASCII trước '
có thể được đẩy như ''(…(
, trong đó số lượng (
phụ thuộc vào điểm mã.
Ví dụ, #
có thể được đẩy như ''((((
. Khoảng cách giữa '
và (
là 1.
Nhân vật được đẩy theo cách này sẽ nâng số điểm lên 2 điểm.
''(…(
thực sự hoạt động cho tất cả các ký tự ASCII, vì Ký tự rộng 16 bit và bao quanh. Ví dụ, +
có thể được đẩy như ''
, theo sau là 65,532 (
s.
Kỹ thuật này được sử dụng trong phiên bản 1,2 megabyte của mã.
Các nhân vật '
có thể được đẩy như ''
, để lại điểm số không bị ảnh hưởng.
Mã
e# Push these characters on the stack: ','#'C'J'a'm',' qYew::-Yf#:+e#'''''''''
''
'()))))(
''
''((((
''
'())))))))))))))))))))))))))))(
''
'()))))))))))))))))))))))))))))))))))(
''
'())))))))))))))))))))))))))))))))))))))))))))))))))))))))))(
''
'())))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))(
''
'()))))(
''
''(((((((
'())))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))(
'())))))))))))))))))))))))))))))))))))))))))))))))))(
'())))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))(
'())))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))(
'()))))))))))))))))))(
'()))))))))))))))))))(
'())))))(
'())))))))))))))))))))))))))))))))))))))))))))))))))(
'()))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))(
''((((
'()))))))))))))))))))(
'())))(
'())))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))(
''((((
''
''
''
''
''
''
''
''
''()
+ e# Concatenate the two topmost single quotes.
, e# Push the length of the resulting string (2).
-.0123456789 e# Push that number.
; e# Discard it from the stack.
< e# Compare a single quote with 2. Pushes 0.
= e# Compare a single quote with 0. Pushes 0.
> e# Compare a single quote with 0. Pushes 1.
? e# Ternary if. Discards a single quote and 1.
@ e# Rotate the remaining three single quotes.
ABCDEFGHIJKLMOPQRSTUVWXYZ e# Push 25 items on the stack.
[\] e# Swap the last two and wrap them in an array.
e# So far, we've pushed the elements of "','#'C'J'a'm',' qYew::-Yf#:+e#'''"
e# followed by the elements of [10 11 12 13 14 15 16 17 18 19 20]
e# and ["" "" "" 3.141592653589793 "" "" " " 0 0 0 -1 1 [3 2]].
] e# Wrap the entire stack in an array.
[ e# Begin an array. Does nothing.
ZZ e# Push 3 twice.
[ e# Begin an array. Does nothing.
\^ e# Swap both 3s and push the bitwise XOR. Pushes 0.
__ e# Push two copies.
` e# Inspect the last copy. Pushes the string "0".
b e# Convert "0" from base 0 to integer. Pushes 48.
cd e# Cast 48 to Character, then Double. Pushes 48.0.
gi e# Apply the sign function, then cast to integer. Pushes 1.
mp e# Check 1 for primality. Pushes 0.
s e# Cast the result to string. Pushes the string "0".
e# We now have three elements on the stack: an array, 0, and "0"
t e# Set the element at index 0 of the array to the string "0".
s e# Cast the array to string.
e# This pushes the string consisting of the characters
e# 0,'#'C'J'a'm',' qYew::-Yf#:+
e# and
e# e#'''10111213141516171819203.141592653589793 000-1132
e#
e# When evaluated this does the following:
e# 0, Push an empty array. Does not affect output.
e# '#'C'J'a'm',' Push the characters of "#CJam, ".
e# q Read all input from STDIN.
e# Yew Push the overlapping slices of length 2.
e# ::- Reduce each pair of characters to their difference.
e# Yf# Square each difference.
e# :+ Add the results.
e# e#… Comment. Does nothing.
z e# Zip. This wraps the string on the stack in an array.
{}~ e# Execute an empty block.
~ e# Unwrap the array.
~ e# Evaluate the string.