Nonoblock: Difference between revisions

→‎{{header|REXX}}: replaced the algorithm and added other examples.
(→‎{{header|REXX}}: added the REXX computer programming language.)
(→‎{{header|REXX}}: replaced the algorithm and added other examples.)
Line 1,571:
=={{header|REXX}}==
<lang rexx>/*REXX program enumerates all possible configurations (or an error) for nonogram puzzles*/
parse arg N blocks $.=; $.1= 5 2 /*obtain optional args from CL*/1
if N=='' | N=="," then parse value 5 2 1 with N blocks /*Not specified? Use default $.*/2= 5
N= strip(N); blocks= space(blocks) $.3= 10 /*assign striped N and blocks.*/8
say 'For ' N " cells and blocks of: " $.4= 15 blocks /*display the2 title3 for2 output*/3
$= $.5= 5 2 /*assign starter value for $. */3
do i=1 while $.i\==''
do i=1 for words(blocks) /*process each of the blocks. */
$=parse $var copies('#', word(blocks,$.i) ) N blocks /*buildobtain N and blocks a string forfrom 1starray. value*/
endN= strip(N); /*i*/ blocks= space(blocks) /*assign stripped N and /*$ now has a leading blankblocks. */
#= 1 call nono /*numberincoke NONO ofsubroutine positionsfor (soheavy far)work*/
end /*ki*/
$= translate( strip($), ., ' ') /*change blanks to periods. */
exit /*stick a fork in it, we're all done. */
if length($)>N then do; say '***error*** invalid blocks for number of cells.'; exit 13
/*──────────────────────────────────────────────────────────────────────────────────────*/
end
@.0=;nono: say copies('=', 70) @.1= $ /*assigndisplay defaultseperator andfor the first positiontitle.*/
$= pad($) say 'For ' N " cells and blocks of: " blocks /*fill─out (pad)display the valuetitle withfor periodsoutput*/
do prependz=1; new= . || @.prepend /*createassign positionsstarter withvalue leadingfor dotsZ. */
if length do w=1 for words(newblocks)>N then leave /*Length is too long? Then/*process each of the stopblocks. adding*/
call add z= z copies('#', word(blocks,w) ) /*addbuild positiona that has astring leadingfor dot.1st value*/
end /*prependw*/ /*Z [↑] now prependhas positionsa withleading dotsblank. */
do i#= 1 for words(blocks) /*process eachnumber of thepositions blocks.(so far)*/
$ z= translate( strip($z), ., ' '); L= length(z) /*change blanks to periods. */
if length($)L>N then do; say '***error*** invalid blocks for number of cells.'; exit 13return
end
@.0=; @.1= z; !.=0 /*assign default and the first position*/
z= pad(z) /*fill─out (pad) the value with periods*/
 
do kdo prepend=1 for # while words(blocks)\==0 /*process each ofall the positions so(leading far.)*/
do cnew=1 . for|| words(blocks)@.prepend /* " /*create positions with leading "dots. " " position blocks. */
p= locif length(@.c, knew)>N then leave /*findLength locationis oftoo blocklong? in position.Then stop adding*/
if p==0call add | p>=N then iterate /*Locationadd zeroposition orthat out─of─range?has a Skipleading dot. */
new= strip(end /*prepend*/ insert(., @.c, p), 'T', .) /*insert a[↑] dot andprepend strippositions trailingwith 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 k=1 for #N /*process each of the positions so far.*/
say center(m,do c=1 for N 10) pad(@.m) /*display an index count" and a " " " position blocks. */
if @.c=='' then iterate /*if string is null, skip the string. */
end /*m*/
exit p= loc(@.c, k) /*stickfind alocation forkof block in it,position. we're all done. */
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 /*mk*/
end /*c*/
say
say '─position─' center("value", max(7, length($z) ), '─') /*displayshow headerhdr for output.*/
 
do m=1 for #
say center(m, 10) pad(@.m) /*display the index count and position.*/
end /*m*/
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
loc: _=0; do arg(2); _=pos('#.',pad(arg(1)),_+1); if _==0 then return 0; end; return _+1
add: if !.new==1 then return; #= # + 1; @.#= new; !.new=1; 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
 
Line 1,618 ⟶ 1,632:
2 .##.#
3 ##..#
======================================================================
For 5 cells and blocks of:
 
─position─ ─value─
1 .....
======================================================================
For 10 cells and blocks of: 8
 
─position─ ──value───
1 ########..
2 .########.
3 ..########
======================================================================
For 15 cells and blocks of: 2 3 2 3
 
─position─ ─────value─────
1 ##.###.##.###..
2 .##.###.##.###.
3 ..##.###.##.###
4 ##..###.##.###.
5 .##..###.##.###
6 ##...###.##.###
7 ##.###..##.###.
8 .##.###..##.###
9 ##..###..##.###
10 ##.###...##.###
11 ##.###.##..###.
12 .##.###.##..###
13 ##..###.##..###
14 ##.###..##..###
15 ##.###.##...###
======================================================================
For 5 cells and blocks of: 2 3
***error*** invalid blocks for number of cells.
</pre>