Nonoblock: Difference between revisions

→‎{{header|REXX}}: added the REXX computer programming language.
(→‎{{header|REXX}}: added the REXX computer programming language.)
Line 1,567:
|..XX.XXX.XX.XXX|
5 cells, (2 3) blocks => impossible
</pre>
 
=={{header|REXX}}==
<lang rexx>/*REXX program enumerates all possible configurations (or an error) for nonogram puzzles*/
parse arg N blocks /*obtain optional args from CL*/
if N=='' | N=="," then parse value 5 2 1 with N blocks /*Not specified? Use default.*/
N= strip(N); blocks= space(blocks) /*assign striped N and blocks.*/
say 'For ' N " cells and blocks of: " blocks /*display the title for output*/
$= /*assign starter value for $. */
do i=1 for words(blocks) /*process each of the blocks. */
$= $ copies('#', word(blocks,i) ) /*build a string for 1st value*/
end /*i*/ /*$ now has a leading blank. */
#= 1 /*number of positions (so far)*/
$= translate( strip($), ., ' ') /*change blanks to periods. */
if length($)>N then do; say '***error*** invalid blocks for number of cells.'; exit 13
end
@.0=; @.1= $ /*assign default and the first position*/
$= pad($) /*fill─out (pad) the value with periods*/
do prepend=1; new= . || @.prepend /*create positions with leading dots. */
if length(new)>N then leave /*Length is too long? Then stop adding*/
call add /*add position that has a leading dot. */
end /*prepend*/ /* [↑] prepend positions with dots. */
 
do k=1 for # /*process each of the positions so far.*/
do c=1 for words(blocks) /* " " " " position blocks. */
p= loc(@.c, k) /*find location of block in position. */
if p==0 | p>=N then iterate /*Location zero or out─of─range? Skip.*/
new= strip( insert(., @.c, p), 'T', .) /*insert a dot and strip trailing dots.*/
if strip(new, 'T', .)=@.c then iterate /*Is it the same value? Then skip it. */
if length(new)<=N then call add /*Is length OK? Then add position. */
end /*k*/
end /*c*/
say
say '─position─' center("value", max(7, length($) ), '─') /*display header for output*/
 
do m=1 for #
say center(m, 10) pad(@.m) /*display an index count and a position*/
end /*m*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
loc: _=0; do arg(2); _=pos('#.',pad(arg(1)),_+1); if _==0 then return 0; end; return _+1
add: #= # + 1; @.#= new ; return
pad: return left( arg(1), N, .)</lang>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
For 5 cells and blocks of: 2 1
 
─position─ ─value─
1 ##.#.
2 .##.#
3 ##..#
</pre>