You are viewing a single comment's thread. Return to all comments →
Not my favorite problem.
Had the idea quite quickly, but it took me disproportionately longer to come up with the implementation (did it in Python first and translated it to Racket afterwards).
(define (sierpinsky s y x)
(let ([m (- (arithmetic-shift 1 s) 1)])
(and (m . > . (+ (bitwise-and m (- x y)) (bitwise-and m (* y 2))))
(= 0 (arithmetic-shift (bitwise-and (- x y) (* y 2)) (- s))))))
(define n (read))
(for ([y (in-range 31 -1 -1)])
(for ([x 63])
(display (if (sierpinsky (- 6 n) y x) "1" "_")))
Brilliant. This is without recursion.