Dominion Strategy Forum

Please login or register.

Login with username, password and session length
Pages: [1]

Author Topic: More Maths That I Could Use Help With  (Read 6531 times)

0 Members and 1 Guest are viewing this topic.

Drab Emordnilap

  • Torturer
  • *****
  • Offline Offline
  • Posts: 1832
  • Shuffle iT Username: Drab Emordnilap
  • Luther Bell Hendricks V
  • Respect: +1887
    • View Profile
More Maths That I Could Use Help With
« on: March 16, 2015, 07:56:20 pm »
+1

Okay, so I'm working on a new game, and I'm trying to come up with a formula to figure out how to calculate the expected damage from an attack. The base engine is TacDice, if you've played Sentinel Tactics or Schlock Mercenary. Here's how it works:

The attack rolls a specified number of dice. The attack also lists which numbers automatically miss. For example, a Shotgun attack would roll 5 dice, and any 4s or 6s would "automiss". Then any dice showing less than the range the attack is being made at miss. Then the defender rolls a number of dice. Each defense die can make one attack die miss, if the defense die ties or beats it. Each attack die remaining after all this deals 1 damage.

I'd like to be able to fill in the variables and have something spit out the expected damage, and ideally the shape of the distribution curve. Is this something I can possibly write in Excel, or what would I need to put this together?

Logged

SwitchedFromStarcraft

  • Saboteur
  • *****
  • Offline Offline
  • Posts: 1088
  • Respect: +856
    • View Profile
Re: More Maths That I Could Use Help With
« Reply #1 on: March 16, 2015, 08:06:05 pm »
+1

Can't help with the excel question, but 1344/1344 = 1.00000000000
Logged
Quote from: Donald X.
Posting begets posting.

Quote from: Asper
Donald X made me a design snob.

There is a sucker born every minute.

DG

  • Governor
  • *****
  • Offline Offline
  • Posts: 4074
  • Respect: +2624
    • View Profile
Re: More Maths That I Could Use Help With
« Reply #2 on: March 16, 2015, 09:13:42 pm »
0

I did something vaguely similar once in Excel working out the probable demand in the game Automobile. So it is possible, but I wouldn't recommend it. The number of different possible dice outcomes will probably cause you problems no matter how you count them.
Logged

Kirian

  • Adventurer
  • ******
  • Offline Offline
  • Posts: 7096
  • Shuffle iT Username: Kirian
  • An Unbalanced Equation
  • Respect: +9413
    • View Profile
Re: More Maths That I Could Use Help With
« Reply #3 on: March 16, 2015, 09:41:29 pm »
0

I once spent a ton of time calculating a formula for the very, very common situation of nd6, drop the lowest.  It was a nightmarish formula involving nested sums, and it only worked for dropping the single lowest die (though it did work for other sizes of dice).

What you're describing is at least a couple more math steps up from there.  You're likely better off making a spreadsheet with all the possibilities in multiple rows. (252 unique rows, I think, for 5d6)
Logged
Kirian's Law of f.DS jokes:  Any sufficiently unexplained joke is indistinguishable from serious conversation.

heron

  • Saboteur
  • *****
  • Offline Offline
  • Posts: 1055
  • Shuffle iT Username: heron
  • Respect: +1184
    • View Profile
Re: More Maths That I Could Use Help With
« Reply #4 on: March 16, 2015, 09:50:35 pm »
0

I don't entirely understand what palindrome bard is saying, but Kirian I am pretty sure the formula isn't that complicated. Shouldn't it just be
3.5n - ((1 - (5/6)^n) + 2((5/6)^n - (4/6)^n) + 3((4/6)^n - (3/6)^n) + 4((3/6)^n - (2/6)^n) + 5((2/6)^n - (1/6)^n) + 6((1/6)^n))

= 3.5n - (1 + (5/6)^n + (4/6)^n + (3/6)^n + (2/6)^n + (1/6)^n) ?
Logged

mpsprs

  • Explorer
  • *****
  • Offline Offline
  • Posts: 332
  • Respect: +169
    • View Profile
Re: More Maths That I Could Use Help With
« Reply #5 on: March 16, 2015, 09:53:18 pm »
+1

For the original problem, it would be easy to just simulate the scenario a bunch of times to approximate the answer?  The formula shouldn't be that difficult either, but takes at least some thought.

liopoil

  • Margrave
  • *****
  • Offline Offline
  • Posts: 2587
  • Respect: +2479
    • View Profile
Re: More Maths That I Could Use Help With
« Reply #6 on: March 16, 2015, 10:02:35 pm »
0

Sounds like the odds are stacked against the attacker.

the formula isn't that complicated. Shouldn't it just be
3.5n - ((1 - (5/6)^n) + 2((5/6)^n - (4/6)^n) + 3((4/6)^n - (3/6)^n) + 4((3/6)^n - (2/6)^n) + 5((2/6)^n - (1/6)^n) + 6((1/6)^n))

= 3.5n - (1 + (5/6)^n + (4/6)^n + (3/6)^n + (2/6)^n + (1/6)^n) ?
Sorry, this counts as complicated. But it seems correct to me at least.
Logged

Kirian

  • Adventurer
  • ******
  • Offline Offline
  • Posts: 7096
  • Shuffle iT Username: Kirian
  • An Unbalanced Equation
  • Respect: +9413
    • View Profile
Re: More Maths That I Could Use Help With
« Reply #7 on: March 16, 2015, 10:39:56 pm »
0

I don't entirely understand what palindrome bard is saying, but Kirian I am pretty sure the formula isn't that complicated. Shouldn't it just be
3.5n - ((1 - (5/6)^n) + 2((5/6)^n - (4/6)^n) + 3((4/6)^n - (3/6)^n) + 4((3/6)^n - (2/6)^n) + 5((2/6)^n - (1/6)^n) + 6((1/6)^n))

= 3.5n - (1 + (5/6)^n + (4/6)^n + (3/6)^n + (2/6)^n + (1/6)^n) ?

That gives the EV, but I was trying to compute the actual distribution.  I'm looking around my HD for the numbers, and have found several equations, but I can't tell what each particular equation is for... and all of this took place in 2003 in a discussion forum that has since been wiped at least once.
Logged
Kirian's Law of f.DS jokes:  Any sufficiently unexplained joke is indistinguishable from serious conversation.

ConMan

  • Saboteur
  • *****
  • Offline Offline
  • Posts: 1400
  • Respect: +1706
    • View Profile
Re: More Maths That I Could Use Help With
« Reply #8 on: March 16, 2015, 10:45:06 pm »
+1

With a bit of work, you could probably emulate it in AnyDice.
Logged

heron

  • Saboteur
  • *****
  • Offline Offline
  • Posts: 1055
  • Shuffle iT Username: heron
  • Respect: +1184
    • View Profile
Re: More Maths That I Could Use Help With
« Reply #9 on: March 16, 2015, 10:53:18 pm »
0

I don't entirely understand what palindrome bard is saying, but Kirian I am pretty sure the formula isn't that complicated. Shouldn't it just be
3.5n - ((1 - (5/6)^n) + 2((5/6)^n - (4/6)^n) + 3((4/6)^n - (3/6)^n) + 4((3/6)^n - (2/6)^n) + 5((2/6)^n - (1/6)^n) + 6((1/6)^n))

= 3.5n - (1 + (5/6)^n + (4/6)^n + (3/6)^n + (2/6)^n + (1/6)^n) ?

That gives the EV, but I was trying to compute the actual distribution.  I'm looking around my HD for the numbers, and have found several equations, but I can't tell what each particular equation is for... and all of this took place in 2003 in a discussion forum that has since been wiped at least once.

Oh, calculating the full distribution would be a lot more work, yea.
Logged

Kirian

  • Adventurer
  • ******
  • Offline Offline
  • Posts: 7096
  • Shuffle iT Username: Kirian
  • An Unbalanced Equation
  • Respect: +9413
    • View Profile
Re: More Maths That I Could Use Help With
« Reply #10 on: March 16, 2015, 11:25:45 pm »
0

With a bit of work, you could probably emulate it in AnyDice.

Ooooooo shiny.
Logged
Kirian's Law of f.DS jokes:  Any sufficiently unexplained joke is indistinguishable from serious conversation.

qmech

  • Torturer
  • *****
  • Offline Offline
  • Posts: 1918
  • Shuffle iT Username: qmech
  • What year is it?
  • Respect: +2320
    • View Profile
Re: More Maths That I Could Use Help With
« Reply #11 on: March 17, 2015, 04:01:06 am »
+1

I don't know about excel, but this would be easy to program in any sort of scripting language: just loop through all the possible dice rolls and record how often each outcome appears.
Logged

Drab Emordnilap

  • Torturer
  • *****
  • Offline Offline
  • Posts: 1832
  • Shuffle iT Username: Drab Emordnilap
  • Luther Bell Hendricks V
  • Respect: +1887
    • View Profile
Re: More Maths That I Could Use Help With
« Reply #12 on: March 17, 2015, 10:23:08 am »
+1

Sounds like the odds are stacked against the attacker.

If the attack and defense quantities of dice are the same, then yes, this is true. Most attacks roll more than 3 dice, though, and very few characters have more than 3 defense.
Logged

SwitchedFromStarcraft

  • Saboteur
  • *****
  • Offline Offline
  • Posts: 1088
  • Respect: +856
    • View Profile
Re: More Maths That I Could Use Help With
« Reply #13 on: March 17, 2015, 11:37:48 am »
+2

In honor of something, (St. Paddy's Day?) I am determined to keep you at 1.0000000
Logged
Quote from: Donald X.
Posting begets posting.

Quote from: Asper
Donald X made me a design snob.

There is a sucker born every minute.

GeoLib

  • Jester
  • *****
  • Offline Offline
  • Posts: 965
  • Respect: +1265
    • View Profile
Re: More Maths That I Could Use Help With
« Reply #14 on: March 17, 2015, 11:59:55 am »
0

I don't know about excel, but this would be easy to program in any sort of scripting language: just loop through all the possible dice rolls and record how often each outcome appears.

Yeah, this seems like way more trouble than it's worth in excel. I would use python.
Logged
"All advice is awful"
 —Count Grishnakh

Ozle

  • Cartographer
  • *****
  • Offline Offline
  • Posts: 3625
  • Sorry, this text is personal.
  • Respect: +3360
    • View Profile
Re: More Maths That I Could Use Help With
« Reply #15 on: March 17, 2015, 12:52:57 pm »
+2

Is the answer 6?
Logged
Try the Ozle Google Map Challenge!
http://forum.dominionstrategy.com/index.php?topic=7466.0

Sullying players Enjoyment of Innovation since 2013 Apparently!

ConMan

  • Saboteur
  • *****
  • Offline Offline
  • Posts: 1400
  • Respect: +1706
    • View Profile
Re: More Maths That I Could Use Help With
« Reply #16 on: March 17, 2015, 06:16:12 pm »
0

With a bit of work, you could probably emulate it in AnyDice.
Oh, or of course there's R, which is a pretty good way of doing user-defined functions involving sequences and sets and stuff.
Logged

Kuildeous

  • Cartographer
  • *****
  • Offline Offline
  • Posts: 3840
  • Respect: +2221
    • View Profile
Re: More Maths That I Could Use Help With
« Reply #17 on: March 20, 2015, 10:43:07 am »
+3

One really handy thing about Microsoft Office is that it's fairly ubiquitous, and it comes with its own programming language. I don't have to package anything up. I can just share the code with you and have you insert it into a Word module. I don't know how much experience you have with Word macros. A quick search should help, but I can also walk you through the steps of putting this into Word. It's a fast-and-dirty code job. I couldn't be bothered with designing my own sort, so I Googled one and tacked it on there. It works for what is needed here. Just copy this code and put it into your VBA Editor. Run the macro named "DrabTest".

You may want to start off with a small number of iterations just to get an idea of how long each process will take. The more iterations you have, the closer your average damage will be to the real mean.

For your convenience and confidence, the code outputs into Word the die results so that you can confirm that the code is doing what it should. At the very end is the average damage over all iterations.

And I welcome any other coders to review my work. As I said, it's fast and dirty, so it's a little embarrassing.

Code: [Select]
Option Explicit

Public Sub Drab_Test()

Dim strAtt() As String
Dim strDef() As String

Dim docNew As Document
Dim intAttCount As Integer
Dim intDefCount As Integer
Dim intIterations As Single
Dim intRange As Integer
Dim intHit As Integer
Dim intHitCount As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer


'If you don't want to be asked each time, replace the InputBox with hard numbers
intIterations = InputBox("How many iterations do you wish to run?")
intAttCount = InputBox("How many attacks?")
intDefCount = InputBox("How many defenses?")
intRange = InputBox("What is the range?")

intHitCount = 0

ReDim strAtt(1 To intAttCount)
ReDim strDef(1 To intDefCount)

'Initialize arrays
For i = 1 To UBound(strAtt)
    strAtt(i) = ""
Next i
For i = 1 To UBound(strDef)
    strDef(i) = ""
Next i

Set docNew = Documents.Add
docNew.Range.InsertAfter "Number of iterations: " + CStr(intIterations) + vbCr + vbCr

For i = 1 To intIterations
    intHit = 0
    docNew.Range.InsertAfter "Att rolls:"
    For j = 1 To UBound(strAtt)
        strAtt(j) = Int(Rnd() * 6 + 1)
    Next j
    strAtt = BubbleSrt(strAtt, True)
    For j = 1 To UBound(strAtt)
        docNew.Range.InsertAfter " " + strAtt(j)
    Next j
   
    docNew.Range.InsertAfter " Def rolls:"
    For j = 1 To UBound(strDef)
        strDef(j) = Int(Rnd() * 6 + 1)
    Next j
    strDef = BubbleSrt(strDef, True)
    For j = 1 To UBound(strDef)
        docNew.Range.InsertAfter " " + strDef(j)
    Next j
    docNew.Range.InsertAfter vbCr
   
'Drop att out of range
    For j = 1 To UBound(strAtt)
        If CInt(strAtt(j)) < intRange Then strAtt(j) = ""
    Next j

'Compare def to att
    For j = 1 To UBound(strDef)
        For k = 1 To UBound(strAtt)
            If strDef(j) <> "" And strAtt(k) <> "" Then
                If CInt(strDef(j)) >= CInt(strAtt(k)) Then
                    strDef(j) = ""
                    strAtt(k) = ""
                End If
            End If
        Next k
    Next j
   
    docNew.Range.InsertAfter "Unblocked att:"
    For j = 1 To UBound(strAtt)
        docNew.Range.InsertAfter " " + strAtt(j)
        If strAtt(j) <> "" Then intHit = intHit + 1
    Next j
   
    docNew.Range.InsertAfter " Unused def:"
    For j = 1 To UBound(strDef)
        docNew.Range.InsertAfter " " + strDef(j)
    Next j
   
    docNew.Range.InsertAfter vbCr
    docNew.Range.InsertAfter "# Hits: " + CStr(intHit) + vbCr + "==========" + vbCr
   
   
    intHitCount = intHitCount + intHit


Next i

docNew.Range.InsertAfter vbCr + "Average hit: " + CStr(intHitCount / intIterations)

End Sub


Public Function BubbleSrt(ArrayIn, Ascending As Boolean)

Dim SrtTemp As Variant
Dim i As Long
Dim j As Long


If Ascending = True Then
    For i = LBound(ArrayIn) To UBound(ArrayIn)
         For j = i + 1 To UBound(ArrayIn)
             If ArrayIn(i) > ArrayIn(j) Then
                 SrtTemp = ArrayIn(j)
                 ArrayIn(j) = ArrayIn(i)
                 ArrayIn(i) = SrtTemp
             End If
         Next j
     Next i
Else
    For i = LBound(ArrayIn) To UBound(ArrayIn)
         For j = i + 1 To UBound(ArrayIn)
             If ArrayIn(i) < ArrayIn(j) Then
                 SrtTemp = ArrayIn(j)
                 ArrayIn(j) = ArrayIn(i)
                 ArrayIn(i) = SrtTemp
             End If
         Next j
     Next i
End If

BubbleSrt = ArrayIn

End Function
Logged
A man has no signature

Kuildeous

  • Cartographer
  • *****
  • Offline Offline
  • Posts: 3840
  • Respect: +2221
    • View Profile
Re: More Maths That I Could Use Help With
« Reply #18 on: March 20, 2015, 04:24:27 pm »
+1

D'oh, I forgot to include insta-misses.

If I get some time, I'll tweak the code to account for insta-misses. Right now, every attacking die that is equal to or greater than the range is going to hit if it's not blocked. It does not take your shotgun example into account.
Logged
A man has no signature

Kuildeous

  • Cartographer
  • *****
  • Offline Offline
  • Posts: 3840
  • Respect: +2221
    • View Profile
Re: More Maths That I Could Use Help With
« Reply #19 on: March 20, 2015, 04:31:33 pm »
+2

Gotta run, but I'll check this code later. See if it does what you need in the meantime.

Code: [Select]
Option Explicit

Public Sub Drab_Test()

Dim strAtt() As String
Dim strDef() As String

Dim docNew As Document
Dim intAttCount As Integer
Dim intDefCount As Integer
Dim intIterations As Single
Dim intRange As Integer
Dim intHit As Integer
Dim intHitCount As Integer
Dim strValidNumbers As String
Dim i As Integer
Dim j As Integer
Dim k As Integer


'If you don't want to be asked each time, replace the InputBox with hard numbers
intIterations = InputBox("How many iterations do you wish to run?")
intAttCount = InputBox("How many attacks?")
strValidNumbers = InputBox("Which numbers succeed? E.g., 1235")
intDefCount = InputBox("How many defenses?")
intRange = InputBox("What is the range?")

intHitCount = 0

ReDim strAtt(1 To intAttCount)
ReDim strDef(1 To intDefCount)

'Initialize arrays
For i = 1 To UBound(strAtt)
    strAtt(i) = ""
Next i
For i = 1 To UBound(strDef)
    strDef(i) = ""
Next i

Set docNew = Documents.Add
docNew.Range.InsertAfter "Number of iterations: " + CStr(intIterations) + vbCr + vbCr

For i = 1 To intIterations
    intHit = 0
    docNew.Range.InsertAfter "Att rolls:"
    For j = 1 To UBound(strAtt)
        strAtt(j) = Int(Rnd() * 6 + 1)
    Next j
    strAtt = BubbleSrt(strAtt, True)
    For j = 1 To UBound(strAtt)
        docNew.Range.InsertAfter " " + strAtt(j)
    Next j
   
    docNew.Range.InsertAfter " Def rolls:"
    For j = 1 To UBound(strDef)
        strDef(j) = Int(Rnd() * 6 + 1)
    Next j
    strDef = BubbleSrt(strDef, True)
    For j = 1 To UBound(strDef)
        docNew.Range.InsertAfter " " + strDef(j)
    Next j
    docNew.Range.InsertAfter vbCr
   
'Drop att out of range and misses
    For j = 1 To UBound(strAtt)
        If CInt(strAtt(j)) < intRange Or InStr(1, strValidNumbers, CInt(strAtt(j))) = 0 Then
            strAtt(j) = ""
        End If
       
    Next j


'Compare def to att
    For j = 1 To UBound(strDef)
        For k = 1 To UBound(strAtt)
            If strDef(j) <> "" And strAtt(k) <> "" Then
                If CInt(strDef(j)) >= CInt(strAtt(k)) Then
                    strDef(j) = ""
                    strAtt(k) = ""
                End If
            End If
        Next k
    Next j
   
    docNew.Range.InsertAfter "Unblocked att:"
    For j = 1 To UBound(strAtt)
        docNew.Range.InsertAfter " " + strAtt(j)
        If strAtt(j) <> "" Then intHit = intHit + 1
    Next j
   
    docNew.Range.InsertAfter " Unused def:"
    For j = 1 To UBound(strDef)
        docNew.Range.InsertAfter " " + strDef(j)
    Next j
   
    docNew.Range.InsertAfter vbCr
    docNew.Range.InsertAfter "# Hits: " + CStr(intHit) + vbCr + "==========" + vbCr
   
   
    intHitCount = intHitCount + intHit


Next i

docNew.Range.InsertAfter vbCr + "Average hit: " + CStr(intHitCount / intIterations)

End Sub


Public Function BubbleSrt(ArrayIn, Ascending As Boolean)

Dim SrtTemp As Variant
Dim i As Long
Dim j As Long


If Ascending = True Then
    For i = LBound(ArrayIn) To UBound(ArrayIn)
         For j = i + 1 To UBound(ArrayIn)
             If ArrayIn(i) > ArrayIn(j) Then
                 SrtTemp = ArrayIn(j)
                 ArrayIn(j) = ArrayIn(i)
                 ArrayIn(i) = SrtTemp
             End If
         Next j
     Next i
Else
    For i = LBound(ArrayIn) To UBound(ArrayIn)
         For j = i + 1 To UBound(ArrayIn)
             If ArrayIn(i) < ArrayIn(j) Then
                 SrtTemp = ArrayIn(j)
                 ArrayIn(j) = ArrayIn(i)
                 ArrayIn(i) = SrtTemp
             End If
         Next j
     Next i
End If

BubbleSrt = ArrayIn

End Function
Logged
A man has no signature

Drab Emordnilap

  • Torturer
  • *****
  • Offline Offline
  • Posts: 1832
  • Shuffle iT Username: Drab Emordnilap
  • Luther Bell Hendricks V
  • Respect: +1887
    • View Profile
Re: More Maths That I Could Use Help With
« Reply #20 on: March 20, 2015, 06:56:00 pm »
0

This looks amazing. I'll need to come back to it when I'm in front of a computer though.
Logged

Drab Emordnilap

  • Torturer
  • *****
  • Offline Offline
  • Posts: 1832
  • Shuffle iT Username: Drab Emordnilap
  • Luther Bell Hendricks V
  • Respect: +1887
    • View Profile
Re: More Maths That I Could Use Help With
« Reply #21 on: May 13, 2015, 03:59:24 pm »
0

Gotta run, but I'll check this code later. See if it does what you need in the meantime.

Code: [Select]
Option Explicit

Public Sub Drab_Test()

Dim strAtt() As String
Dim strDef() As String

Dim docNew As Document
Dim intAttCount As Integer
Dim intDefCount As Integer
Dim intIterations As Single
Dim intRange As Integer
Dim intHit As Integer
Dim intHitCount As Integer
Dim strValidNumbers As String
Dim i As Integer
Dim j As Integer
Dim k As Integer


'If you don't want to be asked each time, replace the InputBox with hard numbers
intIterations = InputBox("How many iterations do you wish to run?")
intAttCount = InputBox("How many attacks?")
strValidNumbers = InputBox("Which numbers succeed? E.g., 1235")
intDefCount = InputBox("How many defenses?")
intRange = InputBox("What is the range?")

intHitCount = 0

ReDim strAtt(1 To intAttCount)
ReDim strDef(1 To intDefCount)

'Initialize arrays
For i = 1 To UBound(strAtt)
    strAtt(i) = ""
Next i
For i = 1 To UBound(strDef)
    strDef(i) = ""
Next i

Set docNew = Documents.Add
docNew.Range.InsertAfter "Number of iterations: " + CStr(intIterations) + vbCr + vbCr

For i = 1 To intIterations
    intHit = 0
    docNew.Range.InsertAfter "Att rolls:"
    For j = 1 To UBound(strAtt)
        strAtt(j) = Int(Rnd() * 6 + 1)
    Next j
    strAtt = BubbleSrt(strAtt, True)
    For j = 1 To UBound(strAtt)
        docNew.Range.InsertAfter " " + strAtt(j)
    Next j
   
    docNew.Range.InsertAfter " Def rolls:"
    For j = 1 To UBound(strDef)
        strDef(j) = Int(Rnd() * 6 + 1)
    Next j
    strDef = BubbleSrt(strDef, True)
    For j = 1 To UBound(strDef)
        docNew.Range.InsertAfter " " + strDef(j)
    Next j
    docNew.Range.InsertAfter vbCr
   
'Drop att out of range and misses
    For j = 1 To UBound(strAtt)
        If CInt(strAtt(j)) < intRange Or InStr(1, strValidNumbers, CInt(strAtt(j))) = 0 Then
            strAtt(j) = ""
        End If
       
    Next j


'Compare def to att
    For j = 1 To UBound(strDef)
        For k = 1 To UBound(strAtt)
            If strDef(j) <> "" And strAtt(k) <> "" Then
                If CInt(strDef(j)) >= CInt(strAtt(k)) Then
                    strDef(j) = ""
                    strAtt(k) = ""
                End If
            End If
        Next k
    Next j
   
    docNew.Range.InsertAfter "Unblocked att:"
    For j = 1 To UBound(strAtt)
        docNew.Range.InsertAfter " " + strAtt(j)
        If strAtt(j) <> "" Then intHit = intHit + 1
    Next j
   
    docNew.Range.InsertAfter " Unused def:"
    For j = 1 To UBound(strDef)
        docNew.Range.InsertAfter " " + strDef(j)
    Next j
   
    docNew.Range.InsertAfter vbCr
    docNew.Range.InsertAfter "# Hits: " + CStr(intHit) + vbCr + "==========" + vbCr
   
   
    intHitCount = intHitCount + intHit


Next i

docNew.Range.InsertAfter vbCr + "Average hit: " + CStr(intHitCount / intIterations)

End Sub


Public Function BubbleSrt(ArrayIn, Ascending As Boolean)

Dim SrtTemp As Variant
Dim i As Long
Dim j As Long


If Ascending = True Then
    For i = LBound(ArrayIn) To UBound(ArrayIn)
         For j = i + 1 To UBound(ArrayIn)
             If ArrayIn(i) > ArrayIn(j) Then
                 SrtTemp = ArrayIn(j)
                 ArrayIn(j) = ArrayIn(i)
                 ArrayIn(i) = SrtTemp
             End If
         Next j
     Next i
Else
    For i = LBound(ArrayIn) To UBound(ArrayIn)
         For j = i + 1 To UBound(ArrayIn)
             If ArrayIn(i) < ArrayIn(j) Then
                 SrtTemp = ArrayIn(j)
                 ArrayIn(j) = ArrayIn(i)
                 ArrayIn(i) = SrtTemp
             End If
         Next j
     Next i
End If

BubbleSrt = ArrayIn

End Function

So I finally got back around to this, and I'm trying to figure out how to use it. Is this something that's Office specific, or can I potentially use this in Google Docs? Do they use different languages? If it's Office only, I can get it onto an Office computer, but that one's not this one.
Logged

DStu

  • Margrave
  • *****
  • Offline Offline
  • Posts: 2627
  • Respect: +1490
    • View Profile
Re: More Maths That I Could Use Help With
« Reply #22 on: May 13, 2015, 04:50:43 pm »
+2

The pain in the the back of my brain tells me this must be vba, and afaik Google docs does not support vba. So you need office
« Last Edit: May 13, 2015, 04:52:05 pm by DStu »
Logged

Kuildeous

  • Cartographer
  • *****
  • Offline Offline
  • Posts: 3840
  • Respect: +2221
    • View Profile
Re: More Maths That I Could Use Help With
« Reply #23 on: May 14, 2015, 11:03:51 am »
+1

Yeah, sorry. It's convenient to use on most computers. I suppose I could make it a web page for even more portability, but I'm not touching that one.
Logged
A man has no signature
Pages: [1]
 

Page created in 0.05 seconds with 21 queries.