Guest User

Codegolf challenge Hexagon

a guest
Aug 2nd, 2018
186
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. FORM h USING s. "ABAP subroutine
  2.   DO s * 2 - 1 TIMES. "basically a simple for loop; loop over each line top to bottom
  3.     WRITE /''. "Newline. No effect on first line for some reason. *shrug*
  4.     "Also, WRITE /. works, too, but outputs TWO line feeds here. Ugh.
  5.     DATA(y) = sy-index. "Save current index in loop to Y
  6.     DO s * 2 - 1 TIMES. "Loop for each character left to right
  7.       IF sy-index > s - y      "Check if we need to write a '*'
  8.          AND sy-index > y - s. "by subtracting size from current line and vice versa
  9.         WRITE'*'. "Print the '*'. WRITE has an implicit space after the output!
  10.       ELSE.
  11.         WRITE ``. "Empty literal. CANNOT be '' or ' ' because then we don't get any output.
  12.       ENDIF.      "Yeah, WRITE is odd. Don't ask.
  13.     ENDDO.        "End of inner loop
  14.   ENDDO.          "End of outer loop
  15. ENDFORM.          "End of subroutine
RAW Paste Data