QBIC、93 91 84バイト
:{X=space$(a)+@--O--`┘a=a-sgn(a-5)~t>-1|?X[t|?]t=t-1?@____|`+@ `+_fB|\_xB+A+_fB
X $の宣言を置き換えることにより、いくつかのバイトを削除しました。地上距離を出力するFORループを最適化しました。以下の説明は古いバージョンのものですが、基本的には同じように機能します。
テスト(および美観)のために、103バイトのわずかに異なるバージョンがありました。
:{_z.5|_CX=Y[a|X=X+@ `]X=X+@--O--`
a=a-sgn(a-5)
~u>0|?X';`[u|?]u=u-1?@____|`+@ `+_fC|\_xC+_tB+_fC
これらは機能的に同じです。2番目のものには、フレーム間で画面がクリアされ、フレーム間で0.5秒間停止するという追加機能があります。
サンプル出力
フレーム間に2つの改行を追加したことに注意してください。上記の最もゴルフされたコードは、フレーム間に空の行を追加せず、よりクールなコードは画面をクリアします。
Command line: 10
--O--
____| |____
--O--
____| |____
--O--
____| |____
--O--
____| |____
--O--
____| |____
____|--O--|____
説明
これはQBICについて私が本当に好きな多くのことに触れており、その機能のいくつかがボンネットの下でどのように機能するかについての良い洞察を与えると感じているので、私は説明を少しやり過ぎました。QBICは、そのコアがCodegolfのQBasicインタープリターであることに注意してください。QBICコードが入ります-QBasicコードが出てきます(そしてその後実行されます)。
:{ get the starting offset (called 'a') from the command line, and start a DO-loop
---- cool code only ----
_z.5|_C At the start of a DO-loop, pause for half a second and clear the screen
---- resume golf-mode ----
---- #1 - The tip of the left wing is anywhere between 0 and 10 positions to the right.
---- Create the plane with the spacing in X$
X=Y Clear X$
[a| For each point in the current offset
X=X+@ `] Add a space to X$
- Every capital letter in QBIC references that letter+$, a variable of type String
- @ and ` start and end a string literal, in this case a literal space.
- ] ends one language construct (an IF, DO or FOR). Here, it's NEXT
X=X+@--O--` Create the actual plane
- @ and `once again create a string literal. Every literal that is created in this
way is assigned its own capital letter. This is our second literal, so the body of
our plane is stored in B$ (A$ contains the space, remember?)
---- #2 Adjust the offset for the next iteration
a=a-sgn(a-5) The clever bit: We have an offset X in the range 0 - 10, and 5 attempts to
get this to be == 5. X - 5 is either positive (X = 6 - 10), negative
(X = 0 - 4) or 0 (X=5). sgn() returns the sign of that subtraction
as a 1, -1 or 0 resp. We then sub the sign from 'a', moving it closer to 5.
---- #3 Draw the plane, the empty airspace and the landing strip
~u>0| Are we there yet?
- ~ is the IF statement in QBIC
- It processes everything until the | as one true/false expression
- All the lower-case letters are (or better, could be) references to numeric
variables. Since QBasic does not need to post-fix those, they double as 'natural'
language: ignored by QBIC and passed as literal code to the QBasic beneath.
- The lower-case letters q-z are kinda special: at the start of QBIC, these
are set to 1 - 10. We haven't modified 'u' yet, so in the first DO-loop, u=5
?X';` If we're still air-borne, print X$ (our plane, incl. spacers)
- ? denotes PRINT, as it does in QBasic.
- ' is a code literal in QBIC: everything until the ` is not parsed, but
passed on to QBasic.
- In this case, we want a literal ; to appear after PRINT X$. This suppresses
QBasic's normal line-break after PRINT. This needs to be a code literal
because it is the command to read a String var from the command Line in QBIC.
[u|?] FOR EACH meter above the ground, print a newline
u=u-1 Descent 1 meter
?@____|` Print the LHS of the landing strip
+@ ` plus 5 spaces
+_fC| plus the LHS reversed.
\ ELSE - touchdown!
_x Terminate the program (effectively escape the infinite DO-loop)
- the _x command has an interesting property: ULX, or Upper/Lowercase Extensibility.
Writing this command with an uppercase _X does something similar, yet different.
The _x command terminates, and prints everything found between _x and | before
quitting. Uppercase _X does not look for |, but only prints something if it is
followed by a character in the ranges a-z and A-Z - it prints the contents of
that variable.
C+B+_fC But before we quit, print C$ (the LHS of the landing strip) and the plane,
and the LHS flipped.
---- #4 QBIC has left the building
- Did I say _x looks for a | ? Well, that gets added implicitly by QBIC at the end of
the program, or when one ( ']' ) or all ( '}' ) opened language constructs are closed.
- Also, all still opened language constructs are automatically closed at EOF.
- Had we stored anything in Z$, that would also be printed at this time.