Anonymous user
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*/
do i=1 while $.i\==''
do i=1 for words(blocks) /*process each of the blocks. */▼
$= 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▼
end /*
@.0=; @.1= z; !.=0 /*assign default and the first position*/
z= pad(z) /*fill─out (pad) the value with periods*/
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 '─position─' center("value", max(7, length($) ), '─') /*display header for output*/▼
if @.c=='' then iterate /*if string is null, skip the string. */
end /*m*/▼
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.*/
▲ end /*c*/
say
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= 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>
|