Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #lang racket
- (require syntax/parse/define)
- (define-simple-macro (recognizer ((n ...) ...))
- #:with (((x-offset y-offset) ...) ...) (for/list ([(foo i) (in-indexed (syntax->list #'((n ...) ...)))])
- (for/list ([(bar j) (in-indexed (syntax->list foo))])
- #`(#,j #,i)))
- (λ (arr x y)
- (and (and (eq? n (vector-ref (vector-ref arr (+ y y-offset))
- (+ x x-offset)))
- ...)
- ...)))
- (define recs
- (list (recognizer [[1 1 1] [1 0 1] [1 0 1] [1 0 1] [1 1 1]])
- (recognizer [[1 1 0] [0 1 0] [0 1 0] [0 1 0] [1 1 1]])
- (recognizer [[1 1 1] [0 0 1] [1 1 1] [1 0 0] [1 1 1]])
- (recognizer [[1 1 1] [0 0 1] [1 1 1] [0 0 1] [1 1 1]])
- (recognizer [[1 0 1] [1 0 1] [1 1 1] [0 0 1] [0 0 1]])
- (recognizer [[1 1 1] [1 0 0] [1 1 1] [0 0 1] [1 1 1]])
- (recognizer [[1 1 1] [1 0 0] [1 1 1] [1 0 1] [1 1 1]])
- (recognizer [[1 1 1] [0 0 1] [0 1 1] [0 1 0] [0 1 0]])
- (recognizer [[1 1 1] [1 0 1] [1 1 1] [1 0 1] [1 1 1]])
- (recognizer [[1 1 1] [1 0 1] [1 1 1] [0 0 1] [1 1 1]])))
- (define (to-bits str)
- (list->vector (map (compose string->number list->string list)
- (string->list str))))
- (define bits (list->vector (map to-bits (file->lines (command-line #:args (filename) filename)))))
- (define y-l (vector-length bits))
- (define x-l (vector-length (vector-ref bits 0)))
- (time (for/hash ([(r n) (in-indexed recs)])
- (values n (for*/list ([i (in-range 0 (- y-l 4))]
- [j (in-range 0 (- x-l 2))]
- #:when (r bits j i))
- (cons i j)))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement