Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,25 @@
{def inject
{lambda {:x :a}
{if {A.empty? :a}
then {A.new {A.new :x}}
else {let { {:c {{lambda {:a :b} {A.cons {A.first :a} :b}} :a}}
{:d {inject :x {A.rest :a}}}
{:e {A.cons :x :a}}
} {A.cons :e {A.map :c :d}}}}}}
-> inject
{def permut
{lambda {:a}
{if {A.empty? :a}
then {A.new :a}
else {let { {:c {{lambda {:a :b} {inject {A.first :a} :b}} :a}}
{:d {permut {A.rest :a}}}
} {A.reduce A.concat {A.map :c :d}}}}}}
-> permut
{permut {A.new 1 2 3}}
-> [[1,2,3],[2,1,3],[2,3,1],[1,3,2],[3,1,2],[3,2,1]]
{permut {A.new 1 2 3 4}}
->
[[1,2,3,4],[2,1,3,4],[2,3,1,4],[2,3,4,1],[1,3,2,4],[3,1,2,4],[3,2,1,4],[3,2,4,1],[1,3,4,2],[3,1,4,2],[3,4,1,2],[3,4,2,1],[1,2,4,3],[2,1,4,3],[2,4,1,3],[2,4,3,1],[1,4,2,3],[4,1,2,3],[4,2,1,3],[4,2,3,1],[1,4,3,2],[4,1,3,2],[4,3,1,2],[4,3,2,1]]

View file

@ -0,0 +1,69 @@
1) permutations on sentences
{script
var S_perm = function(a) {
if (a.length < 2) return [a];
var b = [];
for (var c = 0; c < a.length; c++) {
var e = a.splice(c, 1), f = S_perm(a);
for (var d = 0; d < f.length; d++)
b.push( e.concat( f[d]) );
a.splice(c, 0, e[0])
}
return b
}
LAMBDATALK.DICT['S.perm'] = function() { // {S.perm 1 2 3}
return S_perm( arguments[0].trim()
.split(" ") )
.join(" ")
.replace(/\s/g,"{br}")
};
}
{S.perm 1 2 3}
->
1,2,3
1,3,2
2,1,3
2,3,1
3,1,2
3,2,1
{S.perm hello brave world}
->
hello,brave,world
hello,world,brave
brave,hello,world
brave,world,hello
world,hello,brave
world,brave,hello
2) permutations on words
{script
var W_perm = function(word) {
if (word.length === 1) return [word]
var results = [];
for (var i = 0; i < word.length; i++) {
var buti = W_perm( word.substring(0, i) + word.substring(i + 1) );
for (var j = 0; j < buti.length; j++)
results.push(word[i] + buti[j]);
}
return results;
};
LAMBDATALK.DICT['W.perm'] = function() { // {W.perm 123}
return W_perm( arguments[0].trim() ).join("{br}")
};
}
{W.perm 123}
->
123
132
213
231
312
321