Skip to content

Instantly share code, notes, and snippets.

@harms
Created May 21, 2012 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harms/2762380 to your computer and use it in GitHub Desktop.
Save harms/2762380 to your computer and use it in GitHub Desktop.
Example J solution to (Ruby) question asked by Bill Tozier
unshared=: (-. , -.~) &. setForm
setForm=: convert :. revert
convert=: [: ; (<@(j. i.@#))/.~
revert=: /:~ @ {. @ |: @: +.
A=. 1 2 2 3 3 4 5
B=. 2 3 3 3 3 4 5 6
A unshared B
1 2 3 3 6
NB. Main concept is prominent: each set less the other, unioned. (-. , -.~)
NB. Inspired by https://twitter.com/#!/Vaguery/status/204003580422782976
NB. The version presented above was refactored from the following code, which was originally published in this gist. This is an example of how refactoring often occurs by algebraic reduction.
setForm=: convert :. revert
convert=: (<@(j. i.@#))/.~
revert=: (/:~) @ {. @ |: @: +.
DyadicSets=: 1 :' ;@>@{. u ;@}. '
unshared=: ((-. , -.~)DyadicSets @: ;) &. setForm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment