View Full Version : math riddle
Kasturi
07-10-2008, 12:22 PM
you are asked you to find out how many eight digit numbers there are that contain all numbers one to eight.
( I know the answer to this part)
(what I need to know is this next part)
Now with the number you generated, you need to do the following.
Find the sum of all the values that are divisable by 13
I am confused as to what this question is asking.
HAL9000
07-10-2008, 12:36 PM
Simple... you know the first part.. creating the 8 digit number containing all numbers 1 to 8... now you find which ones of those are divisible by 13, obviously, not all of them will be... then, create the sum of only those numbers... the first part is easy enough.. there are 40,320 combinations... but for the life of me right now, I don't remember how to figure out the second part.
Kasturi
07-10-2008, 01:01 PM
ok,
Lets say that there are two numbers out of the 40320 that are divisible by 13
would the sum be 2 or would it be these 2 numbers added together?
for example
12345678 + 23456781 = 35,802,459
HAL9000
07-10-2008, 01:14 PM
It would be the sum added together as per your example.
Kasturi
07-11-2008, 12:25 PM
I have solved the problem!
With a little help from Excel and a couple of macros it was no problem.
Anikara
07-11-2008, 12:49 PM
I have solved the problem!
With a little help from Excel and a couple of macros it was no problem.
Could you elaborate on the macros. I am curious how you worked it?
m3rl1n
07-12-2008, 03:14 PM
well what was the solution u came up with?
joe17857
07-13-2008, 04:27 PM
hell i didnt even get the first part much less the second.
joe17857
07-14-2008, 04:01 AM
yay. i finaly managed to get the 4320 that everyone else got long ago!!!
ok so now how do you do the second part please explain.
alpaca9000
07-16-2008, 04:10 PM
Hey kasturi, I have a list of numbers but I've found over 100 answers, When I add them in Excel i get a number in scientific notation, how many digits was ur answer?
faulkner132
07-16-2008, 04:33 PM
1) 8! = 40320
2) Pseudo code (C/Java/VB syntax mix):
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)
alpaca9000
07-16-2008, 05:17 PM
How do you run that code? If u can use notepad then what file extention?
faulkner132
07-17-2008, 11:08 AM
How do you run that code? If u can use notepad then what file extention?
It's pseudo-code, so it can't be run as is. You would need to translate it to your language of choice.
I just posted it because others were asking how to calculate the value. The algorithm I posted is just to show an example of how the code would look if you were to write a program.
Kasturi
07-17-2008, 11:39 AM
Here's the macro and a fomula that I used
Macro
Dim CurrentRow
Sub GetString()
Dim InString As String
InString = InputBox("Enter text to permute:")
If Len(InString) < 2 Then Exit Sub
If Len(InString) >= 9 Then
MsgBox "Too many permutations!"
Exit Sub
Else
ActiveSheet.Columns(1).Clear
CurrentRow = 1
Call GetPermutation("", InString)
End If
End Sub
Sub GetPermutation(x As String, y As String)
' The source of this algorithm is unknown
Dim i As Integer, j As Integer
j = Len(y)
If j < 2 Then
Cells(CurrentRow, 1) = x & y
CurrentRow = CurrentRow + 1
Else
For i = 1 To j
Call GetPermutation(x + Mid(y, i, 1), _
Left(y, i - 1) + Right(y, j - i))
Next
End If
End Sub
formula
=IF(MOD(A1,b1)=0,"Divisible","Non-Divisible")
faulkner132
07-17-2008, 03:02 PM
Hey kasturi, I have a list of numbers but I've found over 100 answers, When I add them in Excel i get a number in scientific notation, how many digits was ur answer?
There are actually over 32,000 answers... the sum of them is 806546892372
You can paste this code into an Excel macro/VB window and run it to get the answer (this is the VBA "translation" for the pseudo-code I posted earlier):
Sub GetAnswer()
Cells(1, 1).Value = Div13Sum(0)
End Sub
Function Div13Sum(ByVal ValueToTest As Long) As Double
If ValueToTest < 999999 Then
For i = 1 To 8
Div13Sum = Div13Sum + Div13Sum((ValueToTest * 10) + i)
Next
Else
If ValueToTest Mod 13 = 0 Then
Div13Sum = ValueToTest
Else
Div13Sum = 0
End If
End If
End Function
Oxidoreductase
07-18-2008, 03:15 PM
Faulkner, your answer makes no sense, there is no way there are over 32,000 answers. What did it give you katsuri?
Kasturi
07-18-2008, 03:20 PM
there are 40320 different combinations of 12345678
Out of those there are 3112 that are divisible by 13.
faulkner132
07-18-2008, 03:49 PM
there are 40320 different combinations of 12345678
Out of those there are 3112 that are divisible by 13.
Ahh, I was counting values where 1-8 could appear more than once. This answer is correct.
Oxidoreductase
07-18-2008, 03:57 PM
I figured it was something of the like... do you know how to fix it? I'm pretty curious about this thing and I'm not too good with VB.
vBulletin® v3.7.0, Copyright ©2000-2008, Jelsoft Enterprises Ltd.