Nonoblock: Difference between revisions

2,774 bytes added ,  2 years ago
Added 11l
(Added AutoHotkey)
(Added 11l)
Line 62:
* The blog post [http://paddy3118.blogspot.co.uk/2014/03/nonogram-puzzle-solver-part-1.html Nonogram puzzle solver (part 1)] Inspired this task and donated its [[Nonoblock#Python]] solution.
<br><br>
 
=={{header|11l}}==
{{trans|Python}}
 
<lang 11l>F nonoblocks([Int] &blocks, Int cells) -> [[(Int, Int)]]
[[(Int, Int)]] r
I blocks.empty | blocks[0] == 0
r [+]= [(0, 0)]
E
assert(sum(blocks) + blocks.len - 1 <= cells, ‘Those blocks will not fit in those cells’)
V (blength, brest) = (blocks[0], blocks[1..])
V minspace4rest = sum(brest.map(b -> 1 + b))
 
L(bpos) 0 .. cells - minspace4rest - blength
I brest.empty
r [+]= [(bpos, blength)]
E
V offset = bpos + blength + 1
L(subpos) nonoblocks(&brest, cells - offset)
V rest = subpos.map((bp, bl) -> (@offset + bp, bl))
V vec = [(bpos, blength)] [+] rest
r [+]= vec
R r
 
F pblock(vec, cells)
‘Prettyprints each run of blocks with a different letter A.. for each block of filled cells’
V vector = [‘_’] * cells
L(bp_bl) vec
V ch = L.index + ‘A’.code
V (bp, bl) = bp_bl
L(i) bp .< bp + bl
vector[i] = I vector[i] == ‘_’ {Char(code' ch)} E Char(‘?’)
R ‘|’vector.join(‘|’)‘|’
 
L(blocks, cells) [
([2, 1], 5),
([Int](), 5),
([8], 10),
([2, 3, 2, 3], 15)
]
print("\nConfiguration:\n #. ## #. cells and #. blocks".format(pblock([(Int, Int)](), cells), cells, blocks))
print(‘ Possibilities:’)
V nb = nonoblocks(&blocks, cells)
L(vector) nb
print(‘ ’pblock(vector, cells))
print(‘ A total of #. Possible configurations.’.format(nb.len))</lang>
 
{{out}}
<pre>
 
Configuration:
|_|_|_|_|_| # 5 cells and [2, 1] blocks
Possibilities:
|A|A|_|B|_|
|A|A|_|_|B|
|_|A|A|_|B|
A total of 3 Possible configurations.
 
Configuration:
|_|_|_|_|_| # 5 cells and [] blocks
Possibilities:
|_|_|_|_|_|
A total of 1 Possible configurations.
 
Configuration:
|_|_|_|_|_|_|_|_|_|_| # 10 cells and [8] blocks
Possibilities:
|A|A|A|A|A|A|A|A|_|_|
|_|A|A|A|A|A|A|A|A|_|
|_|_|A|A|A|A|A|A|A|A|
A total of 3 Possible configurations.
 
Configuration:
|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_| # 15 cells and [2, 3, 2, 3] blocks
Possibilities:
|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|
A total of 15 Possible configurations.
</pre>
 
=={{header|AutoHotkey}}==
1,480

edits