Skip to content

Instantly share code, notes, and snippets.

@fornext1119
Created December 28, 2012 22:27
Show Gist options
  • Save fornext1119/4402542 to your computer and use it in GitHub Desktop.
Save fornext1119/4402542 to your computer and use it in GitHub Desktop.
Project Euler Problem 1 VBScript Version
Option Explicit
'単純に加算
Dim sum: sum = 0
Dim i
For i = 1 To 999
If i Mod 3 = 0 Then
sum = sum + i
ElseIf i Mod 5 = 0 Then
sum = sum + i
End If
Next
WScript.Echo sum
'等差数列の和
sum = 0
'初項, 公差
Dim a_list: a_list = Array(3, 5, 15)
Dim a
For Each a in a_list
Dim n: n = 999 \ a '項数
Dim l: l = n * a '末項 a+(n-1)d
Select Case a
Case 3, 5: sum = sum + ((a + l) * n / 2)
Case Else: sum = sum - ((a + l) * n / 2)
End Select
Next
WScript.Echo sum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment