Skip to main content
deleted 44 characters in body
Source Link
rnso
  • 1.7k
  • 10
  • 8

Racket 301292 bytes

(let*((s(number->string n))(sn string->number)(st string)(lr list-ref)(sl(string->list s))(g(λ(i)(-(sn(st(lr sl(add1 i))))
(sn(st(lr sl i)))))))(cond[(even?(string-length s))#f][(not(equal? s(list->string(reverse sl))))#f][(andmap identity
(for/list((i(floor(/(length sl)2))))(if(= 1(g i))#t #f)))]))

Ungolfed:

(define(f n)
  (let* ((s (number->string n))
         (sn string->number)
         (st string)
         (lr list-ref)
         (sl (string->list s))
         (g (λ (i) (- (sn(st(lr sl (add1 i))))
                      (sn(st(lr sl i)))))))
    (cond
      [(even? (string-length s))
       #f]
      [(not(equal? s (list->string (reverse sl))))
       #f]
      [else
       (andmap identity
               (for/list ((i (floor(/(length sl)2))))
                 (if (= 1 (g i) )
                     #t #f)))]
      )))

Testing:

(f 12321) 
(f 123321)  ; only this should be false; 

(f 9)
(f 787)
(f 67876)
(f 4567654)
(f 123454321)
(f 12345654321)
(f 1234567654321)
(f 123456787654321)
(f 12345678987654321)

Output:

#t
#f
#t
#t
#t
#t
#t
#t
#t
#t
#t

Racket 301 bytes

(let*((s(number->string n))(sn string->number)(st string)(lr list-ref)(sl(string->list s))(g(λ(i)(-(sn(st(lr sl(add1 i))))
(sn(st(lr sl i)))))))(cond[(even?(string-length s))#f][(not(equal? s(list->string(reverse sl))))#f][(andmap identity
(for/list((i(floor(/(length sl)2))))(if(= 1(g i))#t #f)))]))

Ungolfed:

(define(f n)
  (let* ((s (number->string n))
         (sn string->number)
         (st string)
         (lr list-ref)
         (sl (string->list s))
         (g (λ (i) (- (sn(st(lr sl (add1 i))))
                      (sn(st(lr sl i)))))))
    (cond
      [(even? (string-length s))
       #f]
      [(not(equal? s (list->string (reverse sl))))
       #f]
      [else
       (andmap identity
               (for/list ((i (floor(/(length sl)2))))
                 (if (= 1 (g i) )
                     #t #f)))]
      )))

Testing:

(f 12321) 
(f 123321)  ; only this should be false; 

(f 9)
(f 787)
(f 67876)
(f 4567654)
(f 123454321)
(f 12345654321)
(f 1234567654321)
(f 123456787654321)
(f 12345678987654321)

Output:

#t
#f
#t
#t
#t
#t
#t
#t
#t
#t
#t

Racket 292 bytes

(let*((s(number->string n))(sn string->number)(st string)(lr list-ref)(sl(string->list s))(g(λ(i)(-(sn(st(lr sl(add1 i))))
(sn(st(lr sl i)))))))(cond[(even?(string-length s))#f][(not(equal? s(list->string(reverse sl))))#f][(andmap identity
(for/list((i(floor(/(length sl)2))))(= 1(g i))))]))

Ungolfed:

(define(f n)
  (let* ((s (number->string n))
         (sn string->number)
         (st string)
         (lr list-ref)
         (sl (string->list s))
         (g (λ (i) (- (sn(st(lr sl (add1 i))))
                      (sn(st(lr sl i)))))))
    (cond
      [(even? (string-length s))
       #f]
      [(not(equal? s (list->string (reverse sl))))
       #f]
      [else
       (andmap identity
               (for/list ((i (floor(/(length sl)2))))
                 (= 1 (g i))))]
      )))

Testing:

(f 12321) 
(f 123321)  ; only this should be false; 

(f 9)
(f 787)
(f 67876)
(f 4567654)
(f 123454321)
(f 12345654321)
(f 1234567654321)
(f 123456787654321)
(f 12345678987654321)

Output:

#t
#f
#t
#t
#t
#t
#t
#t
#t
#t
#t
Source Link
rnso
  • 1.7k
  • 10
  • 8

Racket 301 bytes

(let*((s(number->string n))(sn string->number)(st string)(lr list-ref)(sl(string->list s))(g(λ(i)(-(sn(st(lr sl(add1 i))))
(sn(st(lr sl i)))))))(cond[(even?(string-length s))#f][(not(equal? s(list->string(reverse sl))))#f][(andmap identity
(for/list((i(floor(/(length sl)2))))(if(= 1(g i))#t #f)))]))

Ungolfed:

(define(f n)
  (let* ((s (number->string n))
         (sn string->number)
         (st string)
         (lr list-ref)
         (sl (string->list s))
         (g (λ (i) (- (sn(st(lr sl (add1 i))))
                      (sn(st(lr sl i)))))))
    (cond
      [(even? (string-length s))
       #f]
      [(not(equal? s (list->string (reverse sl))))
       #f]
      [else
       (andmap identity
               (for/list ((i (floor(/(length sl)2))))
                 (if (= 1 (g i) )
                     #t #f)))]
      )))

Testing:

(f 12321) 
(f 123321)  ; only this should be false; 

(f 9)
(f 787)
(f 67876)
(f 4567654)
(f 123454321)
(f 12345654321)
(f 1234567654321)
(f 123456787654321)
(f 12345678987654321)

Output:

#t
#f
#t
#t
#t
#t
#t
#t
#t
#t
#t