The verb isInCantorSet tells whether real numbers are in the Cantor ternary set.
isInCantorSet=: refine^:unknown^:_ prepare
refine=: low`in`out`in`high @. (locate section)
prepare=: (out`in`]`in`out @. locate)& 0 1
unknown=: 1 < #@]
out =: 0:
in =: 1:
low =: ( ,&{. section )@]
high=: ( ,~&{: section )@]
locate=: [ resolve compare
section=: ( + &{. , - &{: ) 3 %~ -~/
compare=: ( < , = , > )"0 _
Possible=: (i.5) compare 1 3
resolve=: ,/ @ I. @ (Possible -:"_1 _ ])Examples:
isInCantorSet 0.25 1 ([,:isInCantorSet"0) (%~ i.@>:) 18x 0 1r18 1r9 1r6 2r9 5r18 1r3 7r18 4r9 1r2 5r9 11r18 2r3 13r18 7r9 5r6 8r9 17r18 1 1 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 1
