RosettaCodeData/Task/Remove-duplicate-elements/Bracmat/remove-duplicate-elements.b...

64 lines
1.1 KiB
Plaintext

2 3 5 7 11 13 17 19 cats 222 (-100.2) "+11" (1.1) "+7" (7.) 7 5 5 3 2 0 (4.4) 2:?LIST
(A=
( Hashing
= h elm list
. new$hash:?h
& whl
' ( !arg:%?elm ?arg
& ( (h..find)$str$!elm
| (h..insert)$(str$!elm.!elm)
)
)
& :?list
& (h..forall)
$ (
= .!arg:(?.?arg)&!arg !list:?list
)
& !list
)
& put$("Solution A:" Hashing$!LIST \n,LIN)
);
(B=
( backtracking
= answr elm
. :?answr
& !arg
: ?
( %?`elm
?
( !elm ?
| &!answr !elm:?answr
)
& ~
)
| !answr
)
& put$("Solution B:" backtracking$!LIST \n,LIN)
);
(C=
( summing
= sum car LIST
. !arg:?LIST
& 0:?sum
& whl
' ( !LIST:%?car ?LIST
& (.!car)+!sum:?sum
)
& whl
' ( !sum:#*(.?el)+?sum
& !el !LIST:?LIST
)
& !LIST
)
& put$("Solution C:" summing$!LIST \n,LIN)
);
( !A
& !B
& !C
&
)