Puzzles/IndexOf
< Puzzles
Jump to navigation
Jump to search
It is not true in general that (x i. y) -: (~.x) i. y :
x=: 50 ?.@$ 10 y=: 20 ?.@$ 10 x i. y 0 1 2 3 4 2 6 7 6 4 0 11 12 11 14 3 11 6 6 3 (~.x) i. y 0 1 2 3 4 2 5 6 5 4 0 7 8 7 9 3 7 5 5 3
Under what conditions would (x i. y) -: (~.x) i. y be true?
Solutions
No Duplicates
The proposition holds if x -: ~.x .
x=: 50 ?.@$ 1e6 y=: (5 ?@$ #x){x x -: ~. x 1 x i. y 40 47 8 29 22 (~.x) i. y 40 47 8 29 22
0 Items
The proposition holds if y (or x) has 0 items.
x=: 50 ?.@$ 10 y=: i. 0 (x i. y) -: (~.x) i. y 1
Prefix
The proposition holds if all items of y occur in a prefix of x that has distinct items.
x=: (20?.20) , 100 ?.@$ 20 y=: 5 ?.@$ 20 x i. y 0 3 2 8 5 (~.x) i. y 0 3 2 8 5
See also
Contributed by Roger Hui. This text expands on the ideas discussed in the J Forum on 2007-10-12.