Unique characters: Difference between revisions

Content deleted Content added
Myrmidon (talk | contribs)
Add two StandardML versions
Wherrera (talk | contribs)
 
(9 intermediate revisions by 5 users not shown)
Line 717:
</pre>
 
 
=={{header|EasyLang}}==
{{trans|11l}}
<syntaxhighlight lang=text>
len d[] 255
for s$ in [ "133252abcdeeffd" "a6789798st" "yxcdfgxcyz" ]
for c$ in strchars s$
d[strcode c$] += 1
.
.
for i to 255
if d[i] = 1
write strchar i
.
.
</syntaxhighlight>
{{out}}
<pre>
156bgstz
</pre>
 
=={{header|ed}}==
 
<syntaxhighlight lang="sed">
# by Artyom Bologov
H
g/.*/s/$/|/
,j
# Remove duplicate chars, across the string boundary
s/([^|])([^|]*)\|(.*)\1/\2|\3/g
s/([^|])([^|]*)\|(.*)\1/\2|\3/g
s/([^|])([^|]*)\|(.*)\1/\2|\3/g
s/([^|])([^|]*)\|(.*)\1/\2|\3/g
s/([^|])([^|]*)\|(.*)\1/\2|\3/g
s/([^|])([^|]*)\|(.*)\1/\2|\3/g
s/([^|])([^|]*)\|(.*)\1/\2|\3/g
s/([^|])([^|]*)\|(.*)\1/\2|\3/g
s/([^|])([^|]*)\|(.*)\1/\2|\3/g
s/([^|])([^|]*)\|(.*)\1/\2|\3/g
# Remove duplicate chars, inside strings
s/([^|])([^|]*)\1/\2/g
s/([^|])([^|]*)\1/\2/g
s/([^|])([^|]*)\1/\2/g
s/([^|])([^|]*)\1/\2/g
s/([^|])([^|]*)\1/\2/g
s/\|/\
/g
d
,p
Q
</syntaxhighlight>
 
{{out}}
 
<pre>$ cat unique-chars.ed | ed -lEGs unique-chars.input
15bfd
6st
cgz</pre>
 
Notice the "c" in the last part—due to the algorithm first deduplicating things across strings, some chars are left over in individual strings. Still, the algo is pretty good overall. No alphabetical sorting either—to save space.
 
=={{header|Factor}}==
Line 728 ⟶ 788:
156bgstz
</pre>
 
 
=={{header|FreeBASIC}}==
Line 1,067 ⟶ 1,126:
{{out}}
<pre>{"1", "5", "6", "b", "g", "s", "t", "z"}</pre>
 
=={{header|newLISP}}==
 
Let's first create a useful general purpose function.
 
<syntaxhighlight lang="newlisp">
;; Since newLISP has dynamic scope, use a namespace or context
;; to avoid variable capture.
(context 'monotonic-slices)
(define (monotonic-slices:monotonic-slices lst (key-func or) (cmp =))
(let (result '() tmp '() old-key 0 new-key 0)
(dolist (x lst)
(set 'new-key (key-func x))
(cond ((empty? tmp) (push x tmp -1))
((cmp new-key old-key) (push x tmp -1))
(true (push tmp result) (set 'tmp (list x))))
(set 'old-key new-key))
(unless (empty? tmp) (push tmp result))
(reverse result)))
(context MAIN)
 
(monotonic-slices
(sort (explode (string "133252abcdeeffd" "a6789798st" "yxcdfgxcyz"))))
 
(("1") ("2" "2") ("3" "3") ("5") ("6") ("7" "7") ("8" "8") ("9" "9")
("a" "a") ("b") ("c" "c" "c") ("d" "d" "d") ("e" "e") ("f" "f" "f")
("g") ("s") ("t") ("x" "x") ("y" "y") ("z"))
 
(join (flat (clean 1
(monotonic-slices
(sort (explode (string "133252abcdeeffd" "a6789798st" "yxcdfgxcyz")))))))
 
"156bgstz"
</syntaxhighlight>
 
=={{header|Nim}}==
Line 1,086 ⟶ 1,179:
{{out}}
<pre>@['1', '5', '6', 'b', 'g', 's', 't', 'z']</pre>
 
=={{header|Nu}}==
{{works with|Nushell|0.97.1}}
<syntaxhighlight lang="nu">['133252abcdeeffd' 'a6789798st' 'yxcdfgxcyz'] | str join | split chars | uniq -u | sort</syntaxhighlight>
{{out}}
<pre>
╭───┬───╮
│ 0 │ 1 │
│ 1 │ 5 │
│ 2 │ 6 │
│ 3 │ b │
│ 4 │ g │
│ 5 │ s │
│ 6 │ t │
│ 7 │ z │
╰───┴───╯
</pre>
 
=={{header|Pascal}}==
Line 1,548 ⟶ 1,658:
156bgstz
</pre>
 
=={{header|Rust}}==
{{trans|Julia}}
<syntaxhighlight lang="rust">fn uniquein2(a: Vec<&str>) -> Vec<char> {
let mut s: Vec<char> = a.join("").chars().into_iter().collect();
s.sort();
let n = s.len();
return s
.iter()
.enumerate()
.filter(|(i, c)| (*i == 0_usize || **c != s[i - 1]) && (*i == n - 1 || **c != s[i + 1]))
.map(|(_i, c)| *c)
.collect();
}
 
fn main() {
let list = ["133252abcdeeffd", "a6789798st", "yxcdfgxcyz"].to_vec();
println!("{:?}", uniquein2(list));
}
</syntaxhighlight>{{out}}<pre>['1', '5', '6', 'b', 'g', 's', 't', 'z']</pre>
 
=={{header|Transd}}==
<syntaxhighlight lang="Scheme">#lang transd