langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
|
|
@ -0,0 +1,18 @@
|
|||
(* insert x at all positions into li and return the list of results *)
|
||||
let rec insert x = function
|
||||
| [] -> [[x]]
|
||||
| a::m as li -> (x::li) :: (List.map (fun y -> a::y) (insert x m))
|
||||
|
||||
(* list of all permutations of li *)
|
||||
let permutations li =
|
||||
List.fold_right (fun a z -> List.concat (List.map (insert a) z)) li [[]]
|
||||
|
||||
(* convert a string to a char list *)
|
||||
let chars_of_string s =
|
||||
let cl = ref [] in
|
||||
String.iter (fun c -> cl := c :: !cl) s;
|
||||
(List.rev !cl)
|
||||
|
||||
(* convert a char list to a string *)
|
||||
let string_of_chars cl =
|
||||
String.concat "" (List.map (String.make 1) cl)
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
let deficient_perms = [
|
||||
"ABCD";"CABD";"ACDB";"DACB";
|
||||
"BCDA";"ACBD";"ADCB";"CDAB";
|
||||
"DABC";"BCAD";"CADB";"CDBA";
|
||||
"CBAD";"ABDC";"ADBC";"BDCA";
|
||||
"DCBA";"BACD";"BADC";"BDAC";
|
||||
"CBDA";"DBCA";"DCAB";
|
||||
]
|
||||
|
||||
let it = chars_of_string (List.hd deficient_perms)
|
||||
|
||||
let perms = List.map string_of_chars (permutations it)
|
||||
|
||||
let results = List.filter (fun v -> not(List.mem v deficient_perms)) perms
|
||||
|
||||
let () = List.iter print_endline results
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
let array_of_perm s =
|
||||
let n = String.length s in
|
||||
Array.init n (fun i -> int_of_char s.[i] - 65);;
|
||||
|
||||
let perm_of_array a =
|
||||
let n = Array.length a in
|
||||
let s = String.create n in
|
||||
Array.iteri (fun i x ->
|
||||
s.[i] <- char_of_int (x + 65)
|
||||
) a;
|
||||
s;;
|
||||
|
||||
let find_missing v =
|
||||
let n = String.length (List.hd v) in
|
||||
let a = Array.make_matrix n n 0
|
||||
and r = ref v in
|
||||
List.iter (fun s ->
|
||||
let u = array_of_perm s in
|
||||
Array.iteri (fun i x -> x.(u.(i)) <- x.(u.(i)) + 1) a
|
||||
) v;
|
||||
let q = Array.make n 0 in
|
||||
Array.iteri (fun i x ->
|
||||
Array.iteri (fun j y ->
|
||||
if y mod 2 != 0 then q.(i) <- j
|
||||
) x
|
||||
) a;
|
||||
perm_of_array q;;
|
||||
|
||||
find_missing deficient_perms;;
|
||||
(* - : string = "DBAC" *)
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
declare
|
||||
GivenPermutations =
|
||||
["ABCD" "CABD" "ACDB" "DACB" "BCDA" "ACBD" "ADCB" "CDAB" "DABC" "BCAD" "CADB" "CDBA"
|
||||
"CBAD" "ABDC" "ADBC" "BDCA" "DCBA" "BACD" "BADC" "BDAC" "CBDA" "DBCA" "DCAB"]
|
||||
|
||||
%% four distinct variables between "A" and "D":
|
||||
proc {Description Root}
|
||||
Root = {FD.list 4 &A#&D}
|
||||
{FD.distinct Root}
|
||||
{FD.distribute naiv Root}
|
||||
end
|
||||
|
||||
AllPermutations = {SearchAll Description}
|
||||
in
|
||||
for P in AllPermutations do
|
||||
if {Not {Member P GivenPermutations}} then
|
||||
{System.showInfo "Missing: "#P}
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
# The givens from Rosetta Code:
|
||||
my @givens = <ABCD CABD ACDB DACB BCDA ACBD ADCB CDAB DABC BCAD CADB CDBA CBAD ABDC ADBC BDCA DCBA BACD BADC BDAC CBDA DBCA DCAB>;
|
||||
|
||||
# Get all the unique permutations of ABCD
|
||||
my @letters = <A B C D>;
|
||||
my @perms = (@letters X~ @letters X~ @letters X~ @letters).grep: {
|
||||
.chars == .split('').uniq.elems
|
||||
};
|
||||
# Print out the missing value:
|
||||
.say for grep none(@givens), @perms;
|
||||
|
|
@ -0,0 +1 @@
|
|||
say [~^] @givens;
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
Procedure in_List(in.s)
|
||||
Define.i i, j
|
||||
Define.s a
|
||||
Restore data_to_test
|
||||
For i=1 To 3*8-1
|
||||
Read.s a
|
||||
If in=a
|
||||
ProcedureReturn #True
|
||||
EndIf
|
||||
Next i
|
||||
ProcedureReturn #False
|
||||
EndProcedure
|
||||
|
||||
Define.c z, x, c, v
|
||||
If OpenConsole()
|
||||
For z='A' To 'D'
|
||||
For x='A' To 'D'
|
||||
If z=x:Continue:EndIf
|
||||
For c='A' To 'D'
|
||||
If c=x Or c=z:Continue:EndIf
|
||||
For v='A' To 'D'
|
||||
If v=c Or v=x Or v=z:Continue:EndIf
|
||||
Define.s test=Chr(z)+Chr(x)+Chr(c)+Chr(v)
|
||||
If Not in_List(test)
|
||||
PrintN(test+" is missing.")
|
||||
EndIf
|
||||
Next
|
||||
Next
|
||||
Next
|
||||
Next
|
||||
PrintN("Press Enter to exit"):Input()
|
||||
EndIf
|
||||
|
||||
DataSection
|
||||
data_to_test:
|
||||
Data.s "ABCD","CABD","ACDB","DACB","BCDA","ACBD","ADCB","CDAB"
|
||||
Data.s "DABC","BCAD","CADB","CDBA","CBAD","ABDC","ADBC","BDCA"
|
||||
Data.s "DCBA","BACD","BADC","BDAC","CBDA","DBCA","DCAB"
|
||||
EndDataSection
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
If OpenConsole()
|
||||
NewList a.s()
|
||||
findPermutations(a(), "ABCD", 4)
|
||||
ForEach a()
|
||||
Select a()
|
||||
Case "ABCD","CABD","ACDB","DACB","BCDA","ACBD","ADCB","CDAB","DABC"
|
||||
Case "BCAD","CADB","CDBA","CBAD","ABDC","ADBC","BDCA","DCBA","BACD"
|
||||
Case "BADC","BDAC","CBDA","DBCA","DCAB"
|
||||
Default
|
||||
PrintN(A()+" is missing.")
|
||||
EndSelect
|
||||
Next
|
||||
|
||||
Print(#CRLF$ + "Press ENTER to exit"): Input()
|
||||
EndIf
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
list$ = "ABCD CABD ACDB DACB BCDA ACBD ADCB CDAB DABC BCAD CADB CDBA CBAD ABDC ADBC BDCA DCBA BACD BADC BDAC CBDA DBCA DCAB"
|
||||
|
||||
for a = asc("A") to asc("D")
|
||||
for b = asc("A") to asc("D")
|
||||
for c = asc("A") to asc("D")
|
||||
for d = asc("A") to asc("D")
|
||||
x$ = chr$(a) + chr$(b) + chr$(c)+ chr$(d)
|
||||
for i = 1 to 4 ' make sure each letter is unique
|
||||
j = instr(x$,mid$(x$,i,1))
|
||||
if instr(x$,mid$(x$,i,1),j + 1) <> 0 then goto [nxt]
|
||||
next i
|
||||
if instr(list$,x$) = 0 then print x$;" missing" ' found missing permutation
|
||||
[nxt] next d
|
||||
next c
|
||||
next b
|
||||
next a
|
||||
|
|
@ -0,0 +1 @@
|
|||
permutations = ~&itB^?a\~&aNC *=ahPfatPRD refer ^C/~&a ~&ar&& ~&arh2falrtPXPRD
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
#import std
|
||||
#show+
|
||||
|
||||
main =
|
||||
|
||||
~&j/permutations'ABCD' -[
|
||||
ABCD
|
||||
CABD
|
||||
ACDB
|
||||
DACB
|
||||
BCDA
|
||||
ACBD
|
||||
ADCB
|
||||
CDAB
|
||||
DABC
|
||||
BCAD
|
||||
CADB
|
||||
CDBA
|
||||
CBAD
|
||||
ABDC
|
||||
ADBC
|
||||
BDCA
|
||||
DCBA
|
||||
BACD
|
||||
BADC
|
||||
BDAC
|
||||
CBDA
|
||||
DBCA
|
||||
DCAB]-
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
code HexIn=26, HexOut=27;
|
||||
int P, I;
|
||||
[P:= 0;
|
||||
for I:= 1 to 24-1 do P:= P xor HexIn(1);
|
||||
HexOut(0, P);
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue