7
\$\begingroup\$

What general tips do you have for golfing in Acc!!? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to Acc!! (e.g. "remove comments" is not an answer).

Please post one tip per answer.

\$\endgroup\$
3

2 Answers 2

3
\$\begingroup\$

Omit Braces When Possible

Unlike some golfing languages, Acc!! does not automatically close braces. However, a known bug in the official interpreter occasionally allows for the omission of braces.

Due to specific implementation details, the } character serves a dual purpose in the official interpreter: it terminates the loop and increments the associated loop variable. Therefore, you can only safely omit the closing } if your code does not depend on the loop variable being incremented on each iteration.

Example

Count i while _-90 {
  _*2
  Count j while _%50-40 {
    _+10
    Write 10
    Count k while _-k {
      Write 48
    }  # This cannot be omitted because the loop depends on k being incremented.
  }  # This can be omitted since the code does not rely on j.
}  # This can also be omitted as the code does not depend on i.

Try it online!

\$\endgroup\$
3
\$\begingroup\$

Unary output without loops

The official interpreter implements the Write command using exec("print(chr(%s), end='')" % expr), opening a window for code injection exploits. Despite this, the potential for such exploits remains limited because expr can only include the characters 0-9a-z_N()*/%^+-, and it prohibits consecutive alphabets or underscores.

An example of a code injection exploit involves using an expr formatted as a)*(b. This format leads to the execution of print(chr(a)*(b), end=''), enabling the character with the ASCII code a to be printed b times without the need for a loop.

Example

# Output the character '/' 10 times:
Write 47)*(10

# Note that both 'a' and 'b' in the form 'a)*(b' can be complex expressions:
2890
Write _/64)*(_%64

Try it online!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.