QBIC、82 72バイト
:[0,23|[0,59|[0,59|~b+c+d=a|?!b$+@:`+right$(@0`+!c$,2)+A+right$(B+!d$,2)
これは、数字へのキャスト、トリミング、および先頭への追加など、QBasicの不幸な点にぶつかります 0ます。必要に応じは非常にコストがかかります。
サンプル出力:
Command line: 119
1:59:59
2:58:59
2:59:58
3:57:59
[... SNIP 270 lines ...]
23:58:38
23:59:37
説明私はそれについて小説を書きました:
: Get N, call it 'a'
[0,23| Loop through the hours; this FOR loop is initialised with 2 parameters
using a comma to separate FROM and TO, and a '|' to delimit the argument list
[0,59| Same for the minutes
[0,59| And the seconds
QBIC automatically creates variables to use as loop-counters:
b, c, d (a was already taken by ':')
~b+c+d=a IF a == b+c+d
| THEN
? PRINT
! CAST
b 'b'
$ To String; casting num to str in QBasic adds a space, this is trimmed in QBIC
+@:` Create string A$, containing ":"
+right$ This is a QBasic function, but since it's all lowercase (and '$' is
not a function in QBIC) it remains unaltered in the resulting QBasic.
(@0`+!c$,2) Pad the minutes by prepending a 0, then taking the rightmost 2 characters.
+A Remember that semicolon in A$? Add it again
+right$ Same for the seconds
(B+!d$,2) Reusing the 0-string saves 2 bytes :-)