3 ms·
This is in Racket, but it has an arbitrary subjective threshold of 1%: (Online version: http://pasterack.org/pastes/94321 http://pasterack.org/pastes/94321 )
by gus_massa 11y ago
This is in Racket, but it has an arbitrary subjective threshold of 1%: (Online version: http://pasterack.org/pastes/94321 http://pasterack.org/pastes/94321 )
#lang racket
(define (~=~? x y)
(and (= (length x) (length y))
(for/and ([vx (in-list x)]
[vy (in-list y)])
(define avg (/ (+ (abs vx) (abs vy)) 2))
(define diff (abs (- vx vy)))
(< diff (/ avg 100)))))
(~=~? '(1047072 1047216 1047441 1047521 1047682 59102 59361 59583 59818)
'(1047085 1047276 1047471 1047754 1047938 59128 59364 59732 59945)) ; ==> #t
(~=~? '(1047072 1047216 1047441 1047521 1047682 59102 59361 59583 59818)
'(1047085 1047276 1017471 1047754 1047938 59128 59364 59732 59945)) ; ==> #f
- JoelJacobson 11y agoThen it's disqualified. 1% is just an arbitrary constant and if it's suitable or not depends on the input. The operator must not have any constants, otherwise it won't work in the general case.
- nardii 11y agoThen how would you define what is "suitable" in the general case?
- JoelJacobson 11y agoThat depends on the input, and that's what it must be able to tell, unbiased without any pre-defined constants.
- deleted 11y ago[deleted]