Created
December 18, 2017 13:36
-
-
Save anonymous/8ea4da67de568db61f3dfd93877b35c5 to your computer and use it in GitHub Desktop.
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
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