Skip to content

Instantly share code, notes, and snippets.

Created December 18, 2017 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/8ea4da67de568db61f3dfd93877b35c5 to your computer and use it in GitHub Desktop.
Save anonymous/8ea4da67de568db61f3dfd93877b35c5 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BaumSweet_Sequence
{
class Program
{
static void Main(string[] args)
{
int n;
bool temp;
do
{
Console.WriteLine("n?");
temp = Int32.TryParse(Console.ReadLine(), out n);
if (!temp)
{
Console.WriteLine("That's not an int, dummy!");
}
}
while (!temp);
List<int> BaumSweet = new List<int>();
for(int i = 0; i <= n; i++)
{
string base2 = HelperMethods.ToBase2(i);
List<int> zeroSequences = new List<int>();
int currentSequenceLength = 0;
foreach(char c in base2)
{
if(c == '0')
{
currentSequenceLength++;
}
else
{
if (currentSequenceLength != 0)
{
zeroSequences.Add(currentSequenceLength);
currentSequenceLength = 0;
}
}
}
zeroSequences.Add(currentSequenceLength);
int BaumSweetNumber = 1;
foreach(int j in zeroSequences)
{
if (!(j%2 == 0))
{
BaumSweetNumber = 0;
}
}
BaumSweet.Add(BaumSweetNumber);
}
Console.WriteLine(HelperMethods.ListToString(BaumSweet, ','));
Console.ReadLine();
}
}
class HelperMethods
{
public static string ToBase2(int n)
{
string base2 = "";
/*if(n == 0)
{
base2 = "0";
}*/
for(int i = (int)Math.Floor(Math.Log(n, 2)); i >= 0; i--)
{
int pow = (int)Math.Pow(2, i);
if (!(n - pow < 0))
{
n = n - pow;
base2 += "1";
}
else
{
base2 += "0";
}
}
return base2;
}
public static string ListToString<T>(List<T> list, char seperator)
{
string result = String.Empty;
foreach(T t in list)
{
result += t;
result += seperator;
}
if(result.Length > 0)
{
result = result.Remove(result.Length - 1);
}
return result;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment