How to resolve the algorithm Nonoblock step by step in the J programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Nonoblock step by step in the J programming language
Table of Contents
Problem Statement
Nonoblock is a chip off the old Nonogram puzzle.
Given a row of five cells and a block of two cells followed by a block of one cell - in that order, the example could be shown as: And would expand to the following 3 possible rows of block positions:
Note how the sets of blocks are always separated by a space. Note also that it is not necessary for each block to have a separate letter. Output approximating This: This would also work:
(This is the algorithm used in the Nonoblock#Python solution).
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Nonoblock step by step in the J programming language
Source code in the j programming language
nonoblock=:4 :0
s=. 1+(1+x)-+/1+y
pad=.1+(#~ s >+/"1)((1+#y)#s) #: i.s^1+#y
~.pad (_1}.1 }. ,. #&, 0 ,. 1 + i.@#@])"1]y,0
)
neat=: [: (#~ # $ 0 1"_)@": {&(' ',65}.a.)&.>
neat 5 nonoblock 2 1
│A│A│ │B│ │
│A│A│ │ │B│
│ │A│A│ │B│
neat 5 nonoblock ''
│ │ │ │ │ │
neat 10 nonoblock 8
│A│A│A│A│A│A│A│A│ │ │
│ │A│A│A│A│A│A│A│A│ │
│ │ │A│A│A│A│A│A│A│A│
neat 15 nonoblock 2 3 2 3
│A│A│ │B│B│B│ │C│C│ │D│D│D│ │ │
│A│A│ │B│B│B│ │C│C│ │ │D│D│D│ │
│A│A│ │B│B│B│ │C│C│ │ │ │D│D│D│
│A│A│ │B│B│B│ │ │C│C│ │D│D│D│ │
│A│A│ │B│B│B│ │ │C│C│ │ │D│D│D│
│A│A│ │B│B│B│ │ │ │C│C│ │D│D│D│
│A│A│ │ │B│B│B│ │C│C│ │D│D│D│ │
│A│A│ │ │B│B│B│ │C│C│ │ │D│D│D│
│A│A│ │ │B│B│B│ │ │C│C│ │D│D│D│
│A│A│ │ │ │B│B│B│ │C│C│ │D│D│D│
│ │A│A│ │B│B│B│ │C│C│ │D│D│D│ │
│ │A│A│ │B│B│B│ │C│C│ │ │D│D│D│
│ │A│A│ │B│B│B│ │ │C│C│ │D│D│D│
│ │A│A│ │ │B│B│B│ │C│C│ │D│D│D│
│ │ │A│A│ │B│B│B│ │C│C│ │D│D│D│
neat 5 nonoblock 2 3
You may also check:How to resolve the algorithm Bitmap/Bresenham's line algorithm step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm Create an HTML table step by step in the C# programming language
You may also check:How to resolve the algorithm One-dimensional cellular automata step by step in the Raku programming language
You may also check:How to resolve the algorithm Fermat numbers step by step in the Julia programming language
You may also check:How to resolve the algorithm Empty string step by step in the Go programming language