Nonoblock: Difference between revisions

Content added Content deleted
m (Small improvement to Pascal code)
m (sntax highlighting fixup automation)
Line 66: Line 66:
{{trans|Python}}
{{trans|Python}}


<lang 11l>F nonoblocks([Int] &blocks, Int cells) -> [[(Int, Int)]]
<syntaxhighlight lang="11l">F nonoblocks([Int] &blocks, Int cells) -> [[(Int, Int)]]
[[(Int, Int)]] r
[[(Int, Int)]] r
I blocks.empty | blocks[0] == 0
I blocks.empty | blocks[0] == 0
Line 107: Line 107:
L(vector) nb
L(vector) nb
print(‘ ’pblock(vector, cells))
print(‘ ’pblock(vector, cells))
print(‘ A total of #. Possible configurations.’.format(nb.len))</lang>
print(‘ A total of #. Possible configurations.’.format(nb.len))</syntaxhighlight>


{{out}}
{{out}}
Line 156: Line 156:


=={{header|Action!}}==
=={{header|Action!}}==
<lang Action!>DEFINE MAX_BLOCKS="10"
<syntaxhighlight lang="action!">DEFINE MAX_BLOCKS="10"
DEFINE NOT_FOUND="255"
DEFINE NOT_FOUND="255"


Line 270: Line 270:
Test(15,t4,4)
Test(15,t4,4)
Test(5,t5,2)
Test(5,t5,2)
RETURN</lang>
RETURN</syntaxhighlight>
{{out}}
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Nonoblock.png Screenshot from Atari 8-bit computer]
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Nonoblock.png Screenshot from Atari 8-bit computer]
Line 319: Line 319:


=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==
<lang AutoHotkey>;-------------------------------------------
<syntaxhighlight lang="autohotkey">;-------------------------------------------
NonoBlock(cells, blocks){
NonoBlock(cells, blocks){
result := [], line := ""
result := [], line := ""
Line 393: Line 393:
return output
return output
}
}
;-------------------------------------------</lang>Examples:<lang AutoHotkey>
;-------------------------------------------</syntaxhighlight>Examples:<syntaxhighlight lang="autohotkey">
Results .= NonoBlock(5, [2, 1]) "------------`n"
Results .= NonoBlock(5, [2, 1]) "------------`n"
Results .= NonoBlock(5, []) "------------`n"
Results .= NonoBlock(5, []) "------------`n"
Line 401: Line 401:
MsgBox, 262144, , % Results
MsgBox, 262144, , % Results
return
return
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>---------------------------
<pre>---------------------------
Line 439: Line 439:


=={{header|C}}==
=={{header|C}}==
<lang c>#include <stdio.h>
<syntaxhighlight lang="c">#include <stdio.h>
#include <string.h>
#include <string.h>


Line 501: Line 501:


return 0;
return 0;
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 541: Line 541:
=={{header|C sharp}}==
=={{header|C sharp}}==
This solution uses a StringBuilder. Spaces are moved from right to left and the problem is then solved recursively.
This solution uses a StringBuilder. Spaces are moved from right to left and the problem is then solved recursively.
<lang csharp>using System;
<syntaxhighlight lang="csharp">using System;
using System.Linq;
using System.Linq;
using System.Text;
using System.Text;
Line 591: Line 591:
}
}


}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre style="height:50ex;overflow:scroll">
<pre style="height:50ex;overflow:scroll">
Line 628: Line 628:


=={{header|C++}}==
=={{header|C++}}==
<lang cpp>
<syntaxhighlight lang="cpp">
#include <iomanip>
#include <iomanip>
#include <iostream>
#include <iostream>
Line 728: Line 728:
return 0;
return 0;
}
}
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 779: Line 779:
=={{header|D}}==
=={{header|D}}==
{{trans|python}}
{{trans|python}}
<lang d>import std.stdio, std.array, std.algorithm, std.exception, std.conv,
<syntaxhighlight lang="d">import std.stdio, std.array, std.algorithm, std.exception, std.conv,
std.concurrency, std.range;
std.concurrency, std.range;


Line 862: Line 862:
writeln;
writeln;
}
}
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>Configuration (5 cells and [2, 1] blocks):
<pre>Configuration (5 cells and [2, 1] blocks):
Line 960: Line 960:


=={{header|EchoLisp}}==
=={{header|EchoLisp}}==
<lang scheme>
<syntaxhighlight lang="scheme">
;; size is the remaining # of cells
;; size is the remaining # of cells
;; blocks is the list of remaining blocks size
;; blocks is the list of remaining blocks size
Line 1,006: Line 1,006:
(writeln "❌ no solution for" size blocks)
(writeln "❌ no solution for" size blocks)
(nonoblock size blocks (stack 'cells)))))
(nonoblock size blocks (stack 'cells)))))
</syntaxhighlight>
</lang>
{{out}}
{{out}}
Line 1,049: Line 1,049:
=={{header|Elixir}}==
=={{header|Elixir}}==
{{trans|Ruby}}
{{trans|Ruby}}
<lang elixir>defmodule Nonoblock do
<syntaxhighlight lang="elixir">defmodule Nonoblock do
def solve(cell, blocks) do
def solve(cell, blocks) do
width = Enum.sum(blocks) + length(blocks) - 1
width = Enum.sum(blocks) + length(blocks) - 1
Line 1,111: Line 1,111:
e in RuntimeError -> IO.inspect e
e in RuntimeError -> IO.inspect e
end
end
end)</lang>
end)</syntaxhighlight>


{{out}}
{{out}}
Line 1,165: Line 1,165:
=={{header|Go}}==
=={{header|Go}}==
{{trans|Kotlin}}
{{trans|Kotlin}}
<lang go>package main
<syntaxhighlight lang="go">package main


import (
import (
Line 1,212: Line 1,212:
printBlock("2323", 15)
printBlock("2323", 15)
printBlock("23", 5)
printBlock("23", 5)
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 1,254: Line 1,254:
Implementation:
Implementation:


<lang J>nonoblock=:4 :0
<syntaxhighlight lang="j">nonoblock=:4 :0
s=. 1+(1+x)-+/1+y
s=. 1+(1+x)-+/1+y
pad=.1+(#~ s >+/"1)((1+#y)#s) #: i.s^1+#y
pad=.1+(#~ s >+/"1)((1+#y)#s) #: i.s^1+#y
Line 1,260: Line 1,260:
)
)


neat=: [: (#~ # $ 0 1"_)@": {&(' ',65}.a.)&.></lang>
neat=: [: (#~ # $ 0 1"_)@": {&(' ',65}.a.)&.></syntaxhighlight>


Task example:
Task example:


<lang J> neat 5 nonoblock 2 1
<syntaxhighlight lang="j"> neat 5 nonoblock 2 1
│A│A│ │B│ │
│A│A│ │B│ │
│A│A│ │ │B│
│A│A│ │ │B│
Line 1,291: Line 1,291:
│ │ │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
neat 5 nonoblock 2 3
</syntaxhighlight>
</lang>


=={{header|Java}}==
=={{header|Java}}==
{{works with|Java|8}}
{{works with|Java|8}}
<lang java>import java.util.*;
<syntaxhighlight lang="java">import java.util.*;
import static java.util.Arrays.stream;
import static java.util.Arrays.stream;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toList;
Line 1,347: Line 1,347:
return sb.toString();
return sb.toString();
}
}
}</lang>
}</syntaxhighlight>
<pre>blocks [2, 1], cells 5
<pre>blocks [2, 1], cells 5
11010
11010
Line 1,383: Line 1,383:


=={{header|JavaScript}}==
=={{header|JavaScript}}==
<lang javascript>const compose = (...fn) => (...x) => fn.reduce((a, b) => c => a(b(c)))(...x);
<syntaxhighlight lang="javascript">const compose = (...fn) => (...x) => fn.reduce((a, b) => c => a(b(c)))(...x);
const inv = b => !b;
const inv = b => !b;
const arrJoin = str => arr => arr.join(str);
const arrJoin = str => arr => arr.join(str);
Line 1,444: Line 1,444:
test(10, 4, 3);
test(10, 4, 3);
test(5, 2, 3);
test(5, 2, 3);
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>5 cells. Blocks: 2,1
<pre>5 cells. Blocks: 2,1
Line 1,496: Line 1,496:


=={{header|Julia}}==
=={{header|Julia}}==
<lang julia>minsized(arr) = join(map(x->"#"^x, arr), ".")
<syntaxhighlight lang="julia">minsized(arr) = join(map(x->"#"^x, arr), ".")
minlen(arr) = sum(arr) + length(arr) - 1
minlen(arr) = sum(arr) + length(arr) - 1
Line 1,532: Line 1,532:
nonoblocks([2, 3, 2, 3], 15)
nonoblocks([2, 3, 2, 3], 15)
nonoblocks([2, 3], 5)
nonoblocks([2, 3], 5)
</lang> {{output}} <pre>
</syntaxhighlight> {{output}} <pre>
With blocks [2, 1] and 5 cells:
With blocks [2, 1] and 5 cells:
##.#.
##.#.
Line 1,565: Line 1,565:
=={{header|Kotlin}}==
=={{header|Kotlin}}==
{{trans|Java}}
{{trans|Java}}
<lang scala>// version 1.2.0
<syntaxhighlight lang="scala">// version 1.2.0


fun printBlock(data: String, len: Int) {
fun printBlock(data: String, len: Int) {
Line 1,597: Line 1,597:
printBlock("2323", 15)
printBlock("2323", 15)
printBlock("23", 5)
printBlock("23", 5)
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 1,636: Line 1,636:


=={{header|Lua}}==
=={{header|Lua}}==
<lang Lua>local examples = {
<syntaxhighlight lang="lua">local examples = {
{5, {2, 1}},
{5, {2, 1}},
{5, {}},
{5, {}},
Line 1,682: Line 1,682:
main (example[1], example[2])
main (example[1], example[2])
print ('A total of ' .. total .. ' possible configurations.')
print ('A total of ' .. total .. ' possible configurations.')
end</lang>
end</syntaxhighlight>


{{out}}
{{out}}
Line 1,736: Line 1,736:
=={{header|M2000 Interpreter}}==
=={{header|M2000 Interpreter}}==
===Recursive===
===Recursive===
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module NonoBlock {
Module NonoBlock {
Form 80,40
Form 80,40
Line 1,792: Line 1,792:
}
}
NonoBlock
NonoBlock
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 1,828: Line 1,828:
</pre >
</pre >
===Non Recursive===
===Non Recursive===
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module Nonoblock (n, m) {
Module Nonoblock (n, m) {
Print "Cells:",n," Blocks:",m
Print "Cells:",n," Blocks:",m
Line 1,919: Line 1,919:
Nonoblock 15,4,2,3,2,3
Nonoblock 15,4,2,3,2,3
Nonoblock 5,2,3,2
Nonoblock 5,2,3,2
</syntaxhighlight>
</lang>


=={{header|Mathematica}}/{{header|Wolfram Language}}==
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<lang Mathematica>ClearAll[SpacesDistributeOverN, Possibilities]
<syntaxhighlight lang="mathematica">ClearAll[SpacesDistributeOverN, Possibilities]
SpacesDistributeOverN[s_, p_] :=
SpacesDistributeOverN[s_, p_] :=
Flatten[
Flatten[
Line 1,943: Line 1,943:
Possibilities[{8}, 10]
Possibilities[{8}, 10]
Possibilities[{2, 3, 2, 3}, 15]
Possibilities[{2, 3, 2, 3}, 15]
Possibilities[{2, 3}, 5]</lang>
Possibilities[{2, 3}, 5]</syntaxhighlight>
{{out}}
{{out}}
<pre>{".##.#", "##..#", "##.#."}
<pre>{".##.#", "##..#", "##.#."}
Line 1,953: Line 1,953:
=={{header|Nim}}==
=={{header|Nim}}==
{{trans|Go}}
{{trans|Go}}
<lang Nim>import math, sequtils, strformat, strutils
<syntaxhighlight lang="nim">import math, sequtils, strformat, strutils




Line 1,986: Line 1,986:
printBlock("8", 10)
printBlock("8", 10)
printBlock("2323", 15)
printBlock("2323", 15)
printBlock("23", 5)</lang>
printBlock("23", 5)</syntaxhighlight>


{{out}}
{{out}}
Line 2,026: Line 2,026:


With 15 cells and [2,3,2,3] blocks, it's a question of how to distribute 5 gap characters among 5 gaps (including the 2 gaps at the ends). To allow for the requirement that the 3 inner gaps must be strictly positive, we can reduce the size of each inner gap by 1, provided we remember to restore the deleted gap character when printing the result. Then 2 gap characters need to be distributed among 5 non-negative gaps. In general, for integers n > 0 and s, the task amounts to finding all arrays of n non-negative integers that sum to s. An iterative method is shown below.
With 15 cells and [2,3,2,3] blocks, it's a question of how to distribute 5 gap characters among 5 gaps (including the 2 gaps at the ends). To allow for the requirement that the 3 inner gaps must be strictly positive, we can reduce the size of each inner gap by 1, provided we remember to restore the deleted gap character when printing the result. Then 2 gap characters need to be distributed among 5 non-negative gaps. In general, for integers n > 0 and s, the task amounts to finding all arrays of n non-negative integers that sum to s. An iterative method is shown below.
<lang pascal>
<syntaxhighlight lang="pascal">
program Nonoblock;
program Nonoblock;
uses SysUtils;
uses SysUtils;
Line 2,128: Line 2,128:
PrintSolutions( 5, [2,3]);
PrintSolutions( 5, [2,3]);
end.
end.
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 2,170: Line 2,170:


=={{header|Perl}}==
=={{header|Perl}}==
<lang perl>use strict;
<syntaxhighlight lang="perl">use strict;
use warnings;
use warnings;


Line 2,189: Line 2,189:
10 8
10 8
15 2 3 2 3
15 2 3 2 3
5 2 3</lang>
5 2 3</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 2,233: Line 2,233:


=={{header|Phix}}==
=={{header|Phix}}==
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">nobr</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">res</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">string</span> <span style="color: #000000;">neat</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">ni</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">ch</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">sequence</span> <span style="color: #000000;">blocks</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">nobr</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">res</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">string</span> <span style="color: #000000;">neat</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">ni</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">ch</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">sequence</span> <span style="color: #000000;">blocks</span><span style="color: #0000FF;">)</span>
Line 2,283: Line 2,283:
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</lang>-->
<!--</syntaxhighlight>-->
{{out}}
{{out}}
<pre>
<pre>
Line 2,365: Line 2,365:


=={{header|Python}}==
=={{header|Python}}==
<lang python>def nonoblocks(blocks, cells):
<syntaxhighlight lang="python">def nonoblocks(blocks, cells):
if not blocks or blocks[0] == 0:
if not blocks or blocks[0] == 0:
yield [(0, 0)]
yield [(0, 0)]
Line 2,416: Line 2,416:
for i, vector in enumerate(nonoblocks(blocks, cells)):
for i, vector in enumerate(nonoblocks(blocks, cells)):
print(' ', pblock(vector, cells))
print(' ', pblock(vector, cells))
print(' A total of %i Possible configurations.' % (i+1))</lang>
print(' A total of %i Possible configurations.' % (i+1))</syntaxhighlight>


{{out}}
{{out}}
Line 2,479: Line 2,479:
Also, the blocks are not identified. I suppose they could be easily enough, but in the nonogram task, these patterns are converted to bit-fields shortly after the nonoblock generation, and bits have no names (sad, but true).
Also, the blocks are not identified. I suppose they could be easily enough, but in the nonogram task, these patterns are converted to bit-fields shortly after the nonoblock generation, and bits have no names (sad, but true).


<lang racket>#lang racket
<syntaxhighlight lang="racket">#lang racket
(require racket/trace)
(require racket/trace)


Line 2,543: Line 2,543:
(tst 10 '[8])
(tst 10 '[8])
(tst 15 '[2 3 2 3])
(tst 15 '[2 3 2 3])
(tst 5 '[2 3]))</lang>
(tst 5 '[2 3]))</syntaxhighlight>


{{out}}
{{out}}
Line 2,578: Line 2,578:
(formerly Perl 6)
(formerly Perl 6)
{{trans|Perl}}
{{trans|Perl}}
<lang perl6>for (5, [2,1]), (5, []), (10, [8]), (5, [2,3]), (15, [2,3,2,3]) -> ($cells, @blocks) {
<syntaxhighlight lang="raku" line>for (5, [2,1]), (5, []), (10, [8]), (5, [2,3]), (15, [2,3,2,3]) -> ($cells, @blocks) {
say $cells, ' cells with blocks: ', @blocks ?? join ', ', @blocks !! '∅';
say $cells, ' cells with blocks: ', @blocks ?? join ', ', @blocks !! '∅';
my $letter = 'A';
my $letter = 'A';
Line 2,586: Line 2,586:
say $row while $row ~~ s/^^ (\.*) <|w> (.*?) <|w> (\w+) \.<!|w> /$1$0.$2/;
say $row while $row ~~ s/^^ (\.*) <|w> (.*?) <|w> (\w+) \.<!|w> /$1$0.$2/;
say '';
say '';
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>5 cells with blocks: 2, 1
<pre>5 cells with blocks: 2, 1
Line 2,622: Line 2,622:


=={{header|REXX}}==
=={{header|REXX}}==
<lang rexx>/*REXX program enumerates all possible configurations (or an error) for nonogram puzzles*/
<syntaxhighlight lang="rexx">/*REXX program enumerates all possible configurations (or an error) for nonogram puzzles*/
$.=; $.1= 5 2 1
$.=; $.1= 5 2 1
$.2= 5
$.2= 5
Line 2,674: Line 2,674:
loc: _=0; do arg(2); _=pos('#.',pad(arg(1)),_+1); if _==0 then return 0; end; return _+1
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
add: if !.new==1 then return; #= # + 1; @.#= new; !.new=1; return
pad: return left( arg(1), N, .)</lang>
pad: return left( arg(1), N, .)</syntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
<pre>
Line 2,722: Line 2,722:
=={{header|Ruby}}==
=={{header|Ruby}}==
'''Simple version:'''
'''Simple version:'''
<lang ruby>def nonoblocks(cell, blocks)
<syntaxhighlight lang="ruby">def nonoblocks(cell, blocks)
raise 'Those blocks will not fit in those cells' if cell < blocks.inject(0,:+) + blocks.size - 1
raise 'Those blocks will not fit in those cells' if cell < blocks.inject(0,:+) + blocks.size - 1
nblock(cell, blocks, '', [])
nblock(cell, blocks, '', [])
Line 2,754: Line 2,754:
p e
p e
end
end
end</lang>
end</syntaxhighlight>


{{out}}
{{out}}
Line 2,798: Line 2,798:
===Class version===
===Class version===
The output form consulted the one of the python.
The output form consulted the one of the python.
<lang ruby>class NonoBlock
<syntaxhighlight lang="ruby">class NonoBlock
def initialize(cell, blocks)
def initialize(cell, blocks)
raise 'Those blocks will not fit in those cells' if cell < blocks.inject(0,:+) + blocks.size - 1
raise 'Those blocks will not fit in those cells' if cell < blocks.inject(0,:+) + blocks.size - 1
Line 2,851: Line 2,851:
end
end
end
end
end</lang>
end</syntaxhighlight>


{{out}}
{{out}}
Line 2,905: Line 2,905:
=={{header|Rust}}==
=={{header|Rust}}==
{{works with|Rust|1.29.2}}
{{works with|Rust|1.29.2}}
<lang rust>struct Nonoblock {
<syntaxhighlight lang="rust">struct Nonoblock {
width: usize,
width: usize,
config: Vec<usize>,
config: Vec<usize>,
Line 2,983: Line 2,983:
println!();
println!();
}
}
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 3,026: Line 3,026:


=={{header|Swift}}==
=={{header|Swift}}==
<lang swift>import Foundation
<syntaxhighlight lang="swift">import Foundation


func nonoblock(cells: Int, blocks: [Int]) {
func nonoblock(cells: Int, blocks: [Int]) {
Line 3,077: Line 3,077:
print()
print()


nonoblock(cells: 5, blocks: [2, 3])</lang>
nonoblock(cells: 5, blocks: [2, 3])</syntaxhighlight>


{{out}}
{{out}}
Line 3,119: Line 3,119:
{{tcllib|generator}}
{{tcllib|generator}}
{{trans|Python}}
{{trans|Python}}
<lang tcl>package require Tcl 8.6
<syntaxhighlight lang="tcl">package require Tcl 8.6
package require generator
package require generator


Line 3,186: Line 3,186:
}
}


package provide nonoblock 1</lang>
package provide nonoblock 1</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 3,241: Line 3,241:
{{trans|Kotlin}}
{{trans|Kotlin}}
{{libheader|Wren-math}}
{{libheader|Wren-math}}
<lang ecmascript>import "/math" for Nums
<syntaxhighlight lang="ecmascript">import "/math" for Nums


var genSequence // recursive
var genSequence // recursive
Line 3,274: Line 3,274:
printBlock.call("8", 10)
printBlock.call("8", 10)
printBlock.call("2323", 15)
printBlock.call("2323", 15)
printBlock.call("23", 5)</lang>
printBlock.call("23", 5)</syntaxhighlight>


{{out}}
{{out}}
Line 3,314: Line 3,314:
=={{header|zkl}}==
=={{header|zkl}}==
{{trans|Python}}
{{trans|Python}}
<lang zkl>fcn nonoblocks(blocks,cells){
<syntaxhighlight lang="zkl">fcn nonoblocks(blocks,cells){
if(not blocks or blocks[0]==0) vm.yield( T(T(0,0)) );
if(not blocks or blocks[0]==0) vm.yield( T(T(0,0)) );
else{
else{
Line 3,346: Line 3,346:
vec.apply2('wrap([(a,b)]){ a.walker(b).pump(Void,vector.set.fp1(ch.next())) });
vec.apply2('wrap([(a,b)]){ a.walker(b).pump(Void,vector.set.fp1(ch.next())) });
String("|",vector.concat("|"),"|");
String("|",vector.concat("|"),"|");
}</lang>
}</syntaxhighlight>
<lang zkl>foreach blocks,cells in (T( T(T(2,1),5), T(T,5), T(T(8),10), T(T(2,3,2,3),15),
<syntaxhighlight lang="zkl">foreach blocks,cells in (T( T(T(2,1),5), T(T,5), T(T(8),10), T(T(2,3,2,3),15),
T(T(2,3),5) )){
T(T(2,3),5) )){
println("\nConfiguration:\n %s # %d cells and %s blocks"
println("\nConfiguration:\n %s # %d cells and %s blocks"
Line 3,357: Line 3,357:
},0)
},0)
: println(" A total of %d possible configurations.".fmt(_));
: println(" A total of %d possible configurations.".fmt(_));
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>