DEV Community

Discussion on: Can you solve this math problem? (The long Math night: an embarrassing tale.)

Collapse
 
nickholmesde profile image
Nick Holmes

Well, all the solutions are given by the integer solution to

 5a + 3 = 7b + 2 = 9c + 1= 11d

Which is

 a = 693 n + 347     
 b = 495 n + 248
 c = 385 n + 193
 d = 315 n + 158

where n is an integer

As we know these are sequential, we only really need to know the inequality

11 * (315 n + 158) < cap

As n needs to be an integer, we can write that like this:

n = ⌊(cap-1738)/3465)⌋

So if we want a function that returns the lowest of the 4 number that satisfies the condition,

lowest = 5 * (693 * ⌊(cap-1738)/3465)⌋ + 347)

       = 3465 * ⌊(cap-1738)/3465)⌋ + 1735

or in F#;

let lowest cap = 3465. * Math.Floor((cap-1738.) / 3465.) + 1735.
Collapse
 
dvddpl profile image
Davide de Paolis • Edited

math
i guess i need some time to digest this..

Collapse
 
amnemonic profile image
Adam Mnemonic

I like this approach. Maybe it's only me but it still seems to sophisticated for 12 years old kids 😁