B ( P Q R S -- n )


Vocabulary
project-euler.508

Inputs
Pan object
Qan object
Ran object
San object


Outputs
nan object


Definition


MEMO:: B ( P Q R S -- n )
Q P - S R - * 5000 < [
P Q [a..b] R S [a..b] [ fab ] cartesian-map
[ sum ] map-sum
] [
S 2 / floor neg R 2 / ceiling neg P 2 / ceiling Q 2 /
floor B S 2 / floor neg R 2 / ceiling neg P 1 - 2 /
ceiling Q 1 - 2 / floor 4dup [ swap - 1 + ] 2bi@ *
[ B ] dip + S 1 - 2 / floor neg R 1 - 2 /
ceiling neg P 2 / ceiling Q 2 / floor 4dup
[ swap - 1 + ] 2bi@ * 2 * [ B ] dip + S 1 - 2 /
floor neg R 1 - 2 / ceiling neg P 1 + 2 /
ceiling ~16 more~
] if ;