Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Make a textual Paint-like program

Write a program/function that can help users make simple drawings by moving a cursor contained within a grid of characters, and by selecting which characters should be at a specific position.

Expected Input and Output

The user will be able to work on an area of 80 x 25 characters and will start at position (0, 0). You must then execute commands given as input, each command represented by a specific character. You can assume that the input will only contain a valid set of commands. Your program must be able to execute the following commands:

  • w,a,s,d : Move the cursor up, left, down or right if the cursor will still be within the boundaries, do nothing otherwise. Your program must work correctly even if the user tries to leave the drawing area.
  • 0,1,2,3,4 : Replace the character at the cursor's position by the corresponding character : ░▒▓█.
  • ? : Read the next input character and save it. You can assume that only printable ASCII characters can be inputted (code 32 to 126 inclusive).
  • ! : Read the character at the cursor's position and save it. ! can therefore save printable ASCII characters and ░▒▓█.
  • 5 : Replace the character at the cursor's position by the last character received with the ? or ! command.

This is , so the shortest answer in bytes will win.

Test Cases

It will obviously be hard to display the final output, since it requires 25 lines, so these examples will only display the first five lines. Ignore the / and - symbols, they are just here as delimiters for readability.

Input: 1s1s1d2w2w2d3s3s3d4w4w4d3s3s3d2w2w2d1s1s1
Final Output:

░▒▓█▓▒░ /
░▒▓█▓▒░ /
░▒▓█▓▒░ /
 /
 /
--------------------------------------------------------------------------------/

Input: 2dsaw!s5s5d5d5d5d5d5d5s5s5a5a5a5a5w5w3w5w5a5a3
Final Output:

▓▒▒ /
▒ ▒ /
▒▒▓▒▒▒▒ /
 ▒ ▒ /
 ▒▒▒▒▒ /
--------------------------------------------------------------------------------/

Input: aaaaasd?H5d?e5d?l5d5d?a5d?!5a?o5s4d4aa4a4a4a4
Final Output:

 /
 Hello! /
 ██████ /
 /
 /
--------------------------------------------------------------------------------/

Answer*

Draft saved
Draft discarded
Cancel

AltStyle によって変換されたページ (->オリジナル) /