Created
August 11, 2012 14:15
-
-
Save fantasticswallow/3324774 to your computer and use it in GitHub Desktop.
Fizzbuzz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Module Module1 | |
Sub Main() | |
For i As Integer = 1 To 1000 | |
Dim tagint As Integer = NumberGenerater.GetInteger(Integer.MaxValue) | |
Console.WriteLine(tagint.ToString + " : " + GetFizzBuzzStr(tagint.ToString)) | |
Threading.Thread.Sleep(1000) | |
Next | |
End Sub | |
Private numberRef As Char() = "0123456789".ToCharArray | |
Public Function GetFizzBuzzStr(target As String) As String | |
Dim retStr As String = "" | |
Dim targetArray As Integer() = target.ToCharArray.Where(Function(x) numberRef.Contains(x)).Select(Function(xa) CInt(xa.ToString)).ToArray | |
If IsFizz(targetArray) Then retStr += "Fizz" | |
If IsBuzz(targetArray) Then retStr += "Buzz" | |
Return retStr | |
End Function | |
Private Function IsFizz(target As Integer()) As Boolean | |
Return target.Sum() Mod 3 = 0 | |
End Function | |
Private buzzRef As Integer() = {0, 5} | |
Private Function IsBuzz(target As Integer()) As Boolean | |
Return buzzRef.Contains(target.Last) | |
End Function | |
End Module |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment