Determine if a string has all unique characters: Difference between revisions
Content added Content deleted
Line 999: | Line 999: | ||
(i, c), rest = xs[0], xs[1:] |
(i, c), rest = xs[0], xs[1:] |
||
return maybe(go(rest))( |
return maybe(go(rest))( |
||
compose(Just, first(cons(i))) |
compose(Just, swap, first(cons(i))) |
||
)(find(compose(eq(c), snd))(rest)) |
)(find(compose(eq(c), snd))(rest)) |
||
else: |
else: |
||
Line 1,014: | Line 1,014: | ||
return repr(s) + ' (' + str(len(s)) + ')' |
return repr(s) + ' (' + str(len(s)) + ')' |
||
def showDuplicate( |
def showDuplicate(cix): |
||
c, ix = cix |
|||
return repr(c) + ( |
return repr(c) + ( |
||
' (' + hex(ord(c)) + ') at ' + repr(ix) |
' (' + hex(ord(c)) + ') at ' + repr(ix) |
||
Line 1,131: | Line 1,131: | ||
'''Second member of a pair.''' |
'''Second member of a pair.''' |
||
return tpl[1] |
return tpl[1] |
||
# swap :: (a, b) -> (b, a) |
|||
def swap(tpl): |
|||
'''The swapped components of a pair.''' |
|||
return (tpl[1], tpl[0]) |
|||