These are chat archives for Codewars/codewars.com/kata-solving-help

4th
Apr 2017
Ze-Marcos
@MarkSchemmer
Apr 04 2017 22:26
``````namespace myjinxin
{
using System;
using System.Linq;
using System.Collections.Generic;

public class Kata
{

public bool IsPrime(int number)
{
if (number < 2) return false;
if (number % 2 == 0) return (number == 2);
int root = (int)Math.Sqrt((double)number);
for (int i = 3; i <= root; i += 2)
{
if (number % i == 0) return false;
}
return true;
}

public IEnumerable<string> GroupSeparatorString(string source, int n)
{
for (int i = 0; i < source.Count() ; i += n)
{
yield return source.Substring(i, n);
}
}

public IEnumerable<int> ListOfDivisors(int number)
{
for (int i = 2; i < number; i++)
{
if (number % i == 0) yield return i;
}
}

public  bool PrimeString(string s)
{
Console.WriteLine(s.Count());

if (IsPrime(s.Count())) return true;

var divisors = ListOfDivisors(s.Count()).Select(x => Convert.ToInt32(x)).ToList();

foreach (var item in divisors)
{
Console.WriteLine("Divisor : "+item);
}

for (int i = 0; i < divisors.Count; i++)
{
var x = GroupSeparatorString(s, divisors[i]);
var first = x.First();
Console.WriteLine("first == " + first);
var test = x.All(c => c == first);
if (test) { Console.WriteLine(test); return false;}
}

Console.WriteLine(true);
return true;
}
}
}``````
I am getting an error on this problem I have solved all the tests but for last one and it does not really make any sense to me at all
Johnny
@JohnnyBizzel
Apr 04 2017 22:44

@MarkSchemmer I think it is failing on

Testing for:
s = "ccc"
String length = 3

Not sure why yet.

Also fails on:

Testing for:
s = "rrrrrrr"
String length = 7

And:

Testing for:
s = "yyyyy"
String length = 5

@MarkSchemmer I changed this and it passes:
``````
public IEnumerable<int> ListOfDivisors(int number)
{
for (int i = 1; i < number; i++) // changed to start from 1
{
if (number % i == 0) yield return i;
}
}

public  bool PrimeString(string s)
{
Console.WriteLine("String length = " + s.Count());

// if (IsPrime(s.Count())) return true; // removed``````
Ze-Marcos
@MarkSchemmer
Apr 04 2017 22:55
Thank you so much
@JohnnyBizzel
Johnny
@JohnnyBizzel
Apr 04 2017 22:56
@MarkSchemmer My pleasure. Nice solution to the problem. :+1:
Ze-Marcos
@MarkSchemmer
Apr 04 2017 23:00
I am going to refactor this a lot and when I am done refactoring I am going to post my solution again
Johnny
@JohnnyBizzel
Apr 04 2017 23:02
Ze-Marcos
@MarkSchemmer
Apr 04 2017 23:26
``````namespace myjinxin
{
using System;
using System.Linq;
using System.Collections.Generic;

public class Kata
{

public IEnumerable<string> GroupSeparatorString(string source, int n)
{
for (int i = 0; i < source.Count() ; i += n)
{
yield return source.Substring(i, n);
}
}

public IEnumerable<int> ListOfDivisors(int number)
{
for (int i = 1; i < number; i++)
{
if (number % i == 0) yield return i;
}
}

public  bool PrimeString(string s)
{
var divisors = ListOfDivisors(s.Count()).Select(x => Convert.ToInt32(x)).ToList();

for (int i = 0; i < divisors.Count; i++)
{
var x = GroupSeparatorString(s, divisors[i]);
var first = x.First();
var test = x.All(c => c == first);
if (test) return false;
}
return true;
}
}
}``````
Johnny
@JohnnyBizzel
Apr 04 2017 23:26
Much neater :clap:
Ze-Marcos
@MarkSchemmer
Apr 04 2017 23:27
yeah I like that I made extension methods in c# that is critical really
and It makes the code so much more easier to read
Johnny
@JohnnyBizzel
Apr 04 2017 23:28
Sure.
Ze-Marcos
@MarkSchemmer
Apr 04 2017 23:28
Is there to a better to learn how to code ?
I am really trying to find out how I can do this .. better
eventually I would like to get a Job
Johnny
@JohnnyBizzel
Apr 04 2017 23:29
@MarkSchemmer Well I take it you look at the other solutions?
Ze-Marcos
@MarkSchemmer
Apr 04 2017 23:29
but I mean I am not even near qualified I feel right now.
Johnny
@JohnnyBizzel
Apr 04 2017 23:29
I think you would be fine. You should see some people who actually get work!
Ze-Marcos
@MarkSchemmer
Apr 04 2017 23:36
They don't know how to code ?
Johnny
@JohnnyBizzel
Apr 04 2017 23:36
I have worked with a few. Maybe they know but just no much!