...因为为什么不这样!
REPORT z.DATA:a(16),c TYPE qfranint.a = 'bugs in the code'.data(b) = 99.WRITE:/ b,a.WHILE b > 0.WRITE:/ b,a,/'Take one down and patch it around'.CALL FUNCTION
'QF05_RANDOM_INTEGER' EXPORTING ran_int_max = 21 IMPORTING ran_int = c.b = b + c - 17.IF b < 1.b = 0.ENDIF.WRITE:/ b,a,/,/ b,a.ENDWHILE.
与其他语言相比,它当然没有竞争力,但是我什至设法将它的大小从最初编写的330个字节减少到最小,因此我将其视为个人的胜利。
由于ABAP不允许行数超过255个字符,因此我不得不用换行符代替空格。在Windows上,由于CRLF,此大小最初增加到296字节,但仅在其中LF的情况下运行良好。ABAP当然需要很多空间,所以这没什么大不了的。
WRITE只是将文本转储到GUI,所以我想那有点像stdout吗?我可能可以通过使用结构或表在此处节省一些字节,但是由于SAP如何处理混合结构(包含字符和数字),所以我想象的方法仅适用于非Unicode系统...我个人认为不行,尽管可以同时访问两者。
我想在我们的系统中可以找到唯一的随机数功能模块,我想可能会有一个名称或参数较短的模块。不知道!
或多或少可读的代码,包括以下注释:
REPORT z.
"Define a (text) and c (random)
DATA: a(16),
c TYPE qfranint. "A stupid data type for a random INT
"This is shorter than using VALUE (saves 3 bytes)
a = 'bugs in the code'.
"This is slightly shorter than doing ',b TYPE i' and 'b = 99'. (saves 2 bytes)
data(b) = 99.
"first line has to be outside of loop due to our exit condition (saved me ~5 bytes)
WRITE: / b,a. "\n xx bugs in the code
WHILE b > 0.
WRITE: / b,a, "\n xx bugs in the code
/'Take one down and patch it around'.
"This ridiculous function for random numbers...
"To save some bytes, I leave ran_int_min at it's default
"of 1, and set the max to 21 instead, from which I remove
"17 later on, resulting in a range of [-16,4]
"Compare:
" ' - 17' = 5 bytes
" ' ran_int_min = -16' = 18 bytes
"(saves 13 bytes)
CALL FUNCTION 'QF05_RANDOM_INTEGER'
EXPORTING ran_int_max = 21
IMPORTING ran_int = c.
"Maximum number of bugs added: 4 = 21 - 17
"Maximum number of bugs removed: -16 = 1 - 17
b = b + c - 17.
IF b <= 0.
b = 0.
ENDIF.
WRITE: / b,a,/,/ b,a. "\nxx bugs in the code\n\nxx bugs in the code
ENDWHILE.
感谢您的挑战!
对我的老板:请不要解雇我,我只是在自学!