Thread: math riddle
View Single Post
Old 07-16-2008, 03:33 PM   #11
faulkner132
Come in Ray...
 
faulkner132's Avatar
 
Join Date: Sep 2004
Posts: 1,668
1) 8! = 40320

2) Pseudo code (C/Java/VB syntax mix):
Code:
function Div13Sum(integer ValueToTest) returns integer {
  //does the value have 8 digits?
  if ( ValueToTest < 9999999 ) {
    //value has less than 8 digits, do not evaluate at this level

    //append 1 through 8 onto the end and test again
    for ( i = 1 to 8 ) {
      total = total + Div13Sum( (ValueToTest * 10) + i )
    }
    //return the accumulated total
    return total

  } else {
    //value has 8 digits, is it divisible by 13?

    if ( ValueToTest MOD 13 = 0 ) {
      //yes it is, return the value
      return ValueToTest
    } else {
      //no it is not, ignore this value
      return 0
    }
  }
}

answer = Div13Sum(0)
faulkner132 is offline   Reply With Quote