AFTER A BRIEF HIATUS, I’m going to continue my study of C#, and I’ve decided that I needed some small projects to work on to practice with C#. For now, at least, I’m going to work my way through Project Euler. Project Euler is described, on its website as “a series of challenging mathematical/computer programming problems that will require more than just mathematical insights to solve. Although mathematics will help you arrive at elegant and efficient methods, the use of a computer and programming skills will be required to solve most problems.”
I’m not entirely concerned with finding the most elegant, efficient method for each problem, but I do plan to write and share code to work each problem, until I a.) get stumped, b.) get bored, or c.) find another project to practice programming on.
Before I get started working the actual problems, though, a quick glance at the project list shows that a lot of the problems are related to prime numbers. I don’t think C# has a function specifically for determining if a number is prime, so I’ve decided to write one. I did a quick search to see if there was a built-in function, and all I found were custom-written ones. I tried not to look at those, specifically for the purposes of writing my own here.
Here’s what I came up with:
public class transformer
{
public string name;
public string transformMode;
public string affiliation;
public string state;
public bool hasMatrixOfLeadership;
public transformer(string name, string transformMode,
string affiliation, string state = "Robot",
bool hasMatrixOfLeadership = false )
{
this.name = name;
this.transformMode = transformMode;
this.affiliation = affiliation;
this.state = state;
this.hasMatrixOfLeadership = hasMatrixOfLeadership;
}
public void transform()
{
if (this.state == "Robot")
{
this.state = transformMode;
}
else
{
this.state = "Robot";
}
}
public bool isPrime()
{
return hasMatrixOfLeadership;
}
}








