Amb: Difference between revisions
→{{header|langur}}
(→Insitux: improvement) |
Langurmonkey (talk | contribs) |
||
(10 intermediate revisions by 6 users not shown) | |||
Line 910:
</pre>
<syntaxhighlight lang="c++">
#include <functional>
Line 920:
std::string join(const std::string& delimiter, const std::vector<std::string>& list) {
return list.empty() ? "" : std::accumulate(++list.begin(), list.end(), list[0],
}
Line 1,414:
=={{header|Elena}}==
ELENA
<syntaxhighlight lang="elena">import system'routines;
import extensions;
import extensions'routines;
// --- Joinable --
joinable(former,later) = (former[former.Length - 1] == later[0]);
Line 1,443 ⟶ 1,445:
}
};
// --- AmbValueCollection ---
class AmbValueCollection
{
object
constructor new(params object[] args)
{
}
seek(cond)
{
}
do(f)
{
var result :=
if (nil != result)
{
Line 1,473 ⟶ 1,477:
}
}
// --- ambOperator ---
singleton ambOperator
Line 1,479 ⟶ 1,485:
= AmbValueCollection.new(params args);
}
// --- Program ---
public program()
Line 1,490 ⟶ 1,498:
new object[]{"walked", "treaded", "grows"},
new object[]{"slowly", "quickly"})
.seek::(a,b,c,d => joinable(a,b) && joinable(b,c) && joinable(c,d) )
.do::(a,b,c,d) { console.printLine(a," ",b," ",c," ",d) }
}
catch(Exception e)
{
console.printLine
};
Line 2,440 ⟶ 2,448:
=={{header|langur}}==
This would build every valid set, but for the sample data, there's only one.
<syntaxhighlight lang="langur">val .wordsets = [
]
val .alljoin =
if last(.words[.i]) != first(.words[.i+1]): break = false
}}
# .amb expects 2 or more arguments
val .amb =
writeln join "\n", filter
</syntaxhighlight>
{{out}}
Line 5,280 ⟶ 5,288:
uBasic/4tH has limited support for arrays, so some workarounds are required to make this work.
<syntaxhighlight lang="text"> ' set up the arrays
Push
Push
Push
Push
' we'll reuse variable f ;-)
Proc _Ambassert (_Connect) ' now assert the function required
Line 5,319 ⟶ 5,327:
0 OK, 0:772
</pre>
=={{header|VBScript}}==
=====Implementation=====
Line 5,399 ⟶ 5,408:
{{trans|Go}}
Based on the 'alternative' version.
<syntaxhighlight lang="
var amb // recursive closure
Line 5,424 ⟶ 5,433:
[ "walked", "treaded", "grows" ],
[ "slowly", "quickly" ]
]
if (amb.call(wordsets, [])) {
|