: prep-hashtable ( sum seq -- hashtable sum seq ) tuck [ H{ } [ spin [ set-at ] keep ] reduce-index ] 2dip ; : complements ( sum seq -- seq' ) [ - ] with map ; : find-indices ( key assoc -- index/f index/f ) [ [ ?of nip ] with find ] keepd at ; : result/empty ( index/f index/f -- pair ) 2dup and [ 2array ] [ 2drop { } ] if ; : two-sum ( sum seq -- pair ) prep-hashtable complements find-indices result/empty ;