Skip to content

Instantly share code, notes, and snippets.

@DeepSky8
Last active April 21, 2016 17:41
Show Gist options
  • Save DeepSky8/66903a901c8dfecbe1c91644f0a5ef45 to your computer and use it in GitHub Desktop.
Save DeepSky8/66903a901c8dfecbe1c91644f0a5ef45 to your computer and use it in GitHub Desktop.
FizzBuzz Practice
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FizzBuzz
{
class Program
{
static void Main(string[] args)
{
var begin = new Controller();
begin.begin();
}
public class Controller
{
public void begin()
{
var ui = new UserInterface();
var b = new Business();
ui.Display(b.StringFuzz(ui.GetLimit()));
}
}
public class UserInterface
{
public int GetLimit()
{
int result=0;
var isDone = false;
while (!isDone)
{
Console.WriteLine("How many digits do you want to evaluate?");
var input = Console.ReadLine();
if (Int32.TryParse(input, out result))
{
isDone = true;
}
else
{
Console.WriteLine("I'm sorry, that answer doesn't parse.");
}
}
return result;
}
public void Display(List<string> listed)
{
foreach (var item in listed)
{
Console.WriteLine(item);
}
}
}
public class Business
{
public List<string> StringFuzz(int limit)
{
var pointer = 1;
var myList = new List<string>();
while (limit >= pointer)
{
myList.Add((pointer % 3 == 0 && pointer % 5 == 0) ? "fizzbuzz" : (pointer % 3 == 0) ? "fizz" : (pointer % 5 == 0) ? "buzz" : pointer.ToString());
pointer++;
}
return myList;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment