reset password
Author Message
rabbott
Posts: 1649
Posted 14:07 Feb 04, 2014 |

  findAMultiple(Vector(1, 2, 1, 2, 1, 2, 1))    
                                                 //> res7: Option[(Int, Int, Vector[Int])] = Some((7,7,Vector(1, 2, 2, 2)))
  findAMultiple(Vector(1, 2, 1, 2, 1, 2, 1, 2, 1))
                                                 //> res8: Option[(Int, Int, Vector[Int])] = Some((9,9,Vector(1, 2, 2, 2, 2)))
  findAMultiple(Vector(1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1))
                                                 //> res9: Option[(Int, Int, Vector[Int])] = Some((11,11,Vector(1, 2, 2, 2, 2, 2) ))
  findAMultiple(Vector(1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1))
                                                 //> res10: Option[(Int, Int, Vector[Int])] = Some((13,13,Vector(1, 2, 2, 2, 2, 2, 2)))

As you continue adding (2, 1) to the end, more numbers will be needed.

It's even easier to see if the input is all 1's. You need all the numbers to get to a multiple of the length of the input.

This is not really a cheat. Think of the numbers mod the length of the input -- since that's all that matters as far as the problem is concerned. If all the numbers are 1 mod the length of the input, you need them all. For example, in the following all the numbers are 1 mod the length of the input, which is 7. So you need 7 of them to get to a multiple of 7.

findAMultiple(Vector(1, 8, 15, 22, 29, 36, 43)) //> Some((7,154,Vector(1, 8, 15, 22, 29, 36, 43)))