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*

Grid ASCII art code golf

Challenge

Create the shortest program that meets the requirements

Requirements

  1. The code must generate a 5x5 grid of 0s, like so:

    00000
    00000
    00000
    00000
    00000
    
  2. The code must accept an input (column, row, character). The grid must change accordingly:

    Start:

    00000
    00000
    00000
    00000
    00000
    

    Input:

    (2,5,*)
    

    Output:

    0*000
    00000
    00000
    00000
    00000
    

    (Note: the bottom-left corner is position 1,1.)

  3. The program must return an error message other than the grid if the row/column input is not 1,2,3,4, or 5. This can be any message of your choice (as long as it's not the grid), so 0 is an acceptable error-output.

  4. The program must work with all printable ASCII characters (of a US keyboard).

THE WINNER

The winner will be the person who has the shortest code and fulfills all requirements. If more than one answer works and has the same (shortest) length, the person who answered first will be the winner.

Answer*

Draft saved
Draft discarded
Cancel
5
  • \$\begingroup\$ {a←5 5⍴0⋄a[⊂⌽⍺]←⍵⋄⊖a} saves a few bytes. \$\endgroup\$ Commented Nov 29, 2016 at 13:52
  • \$\begingroup\$ @Zgarb Oh, fantastic! I didn't know indexing worked like that. \$\endgroup\$ Commented Nov 29, 2016 at 13:53
  • \$\begingroup\$ You can save two bytes by converting to a tradfn body: a←5 5⍴0⋄a[⊂⎕]←⍞⋄⊖a \$\endgroup\$ Commented Nov 29, 2016 at 14:29
  • \$\begingroup\$ @Adám how does that work? It doesn't seem to work on TryAPL. \$\endgroup\$ Commented Nov 29, 2016 at 14:37
  • \$\begingroup\$ @ConorO'Brien Right. TryAPL prohibits prompting for input, but you can get the full version for free. \$\endgroup\$ Commented Nov 29, 2016 at 14:42

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