c# algorithms / c# puzzles

G

Guest

Hi,

1) I want to hone my problem solving skills and be good at logic. How do I
achieve
this?
2) Where can I find c# puzzles or c# algorithms.

3) How do I print the values of a N X N matrix using c#.
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16

How do I print 1 2 3 4 8 12 16 15 14 13 9 5 6 7 11 10.
 
M

MasterGaurav \(www.edujini-labs.com\)

1) I want to hone my problem solving skills and be good at logic. How do I
achieve
this?

Get the book "Inntroduction to Algorithms" by Cormen... :)
Will help you build the concepts around algorithms.
2) Where can I find c# puzzles or c# algorithms.

I don't think there's something like C# algorithms. Algorithms are
algorithms. Mostly mathematical... cannot and shouldn't be language
specific.
3) How do I print the values of a N X N matrix using c#.
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16

What's the problem in this?
How do I print 1 2 3 4 8 12 16 15 14 13 9 5 6 7 11 10.

And in this one...? Where are you stuck?


--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujini-labs.com
-----------------------------------------
 
K

Kevin Spencer

Presuming that you are studying programming, a desire to improve your
problem-solving skills and understand logic are excellent goals to have in
mind. Almost all of programming is problem-solving, and involves the use of
logic.

Problem-solving is more of a discipline than a skill, although there are
elements of skill involved in it. But the most important aspect is the
discipline, and this holds true for logic as well. The basis of
problem-solving is really fairly simple, but it requires a relentless
attention to detail to do it well.

The first aspect of problem-solving is to identify the problem, and while
this may seem obvious, it is not as obvious as it seems. Most problems are
not singular in nature; they are made up of many smaller problems. For
example, you might consider thirst to be a problem. But quenching the thirst
is likely to be problematic. First, you must identify a source of water, and
ensure that it is good to drink. Second, you must determine how to get to
the source of water. Third, you have to figure out how to drink it, whether
to cup your hands, use a glass, etc.

So, the first and perhaps most important aspect of problem-solving is
analysis. This is the breaking down of a problem into its component smaller
problems. Once each sub-problem has been identified, the solution to the
overall problem generally makes itself obvious, as it is the sum total of
all the solutions to the smaller problems that constitute the large one.

It is also useful to identify what constitutes a problem. Life is actually
full of problems, and it is helpful to learn to identify them and apply
problem-solving skills to them. Any need which is not yet fulfilled is a
problem to be solved.

In fact, it is not necessary to find C# algorithms or C# puzzles to develop
your problem-solving skills. Playing games can be helpful, as well as
solving various types of puzzles.

As for logic, there is a lot to be learned. Here are a couple of places to
start. Logic is useful in all sorts of situations, in fact, anything
involving reasoning:

http://www.philosophypages.com/lg/index.htm
http://plato.stanford.edu/entries/aristotle-logic/

As for your specific third question, there is no answer to it, because you
have not sufficiently identified the nature of the problem to solve it. What
do you mean by "print?" And what are the parameters for this so-called
"printing?" For example, you mentioned a "N X N matrix" and typed the
members of a matrix in a column/row arrangement. However, you did not
specify anything about how the members were to be organized, if at all.

To write an application that solves your matrix problem, you have to tell
the computer exactly what to do. This means that there is no room for
interpretation. When you say "print" you are being very non-specific. The
word actually has a few different definitions, several of which might be
applicable. Do you want to "print" these numbers on paper? Do you want to
"print" them in a Console application? Do you want to "print" them in a
windowed application? And again, you "printed" the matrix using columns and
rows, but your problem didn't mention anything about columns and rows. The
computer cannot and will not guess how to fill in the blanks in your
requirements.

But as I mentioned earlier, the first step to solving a problem is to
identify all of the aspects of it.

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
Networking Components, Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
 
A

aki buggi

Console.WriteLine("1 2 3 4");
Console.WriteLine("5 6 7 8");
Console.WriteLine("9 10 11 12");
Console.WriteLine("13 14 15 16");



CrmNewbi wrote:

c# algorithms / c# puzzles
29-Mar-07

Hi

1) I want to hone my problem solving skills and be good at logic. How do I
achieve
this
2) Where can I find c# puzzles or c# algorithms.

3) How do I print the values of a N X N matrix using c#
1 2 3
5 6 7
9 10 11 1
13 14 15 1

How do I print 1 2 3 4 8 12 16 15 14 13 9 5 6 7 11 10.

Previous Posts In This Thread:

c# algorithms / c# puzzles
Hi

1) I want to hone my problem solving skills and be good at logic. How do I
achieve
this
2) Where can I find c# puzzles or c# algorithms.

3) How do I print the values of a N X N matrix using c#
1 2 3
5 6 7
9 10 11 1
13 14 15 1

How do I print 1 2 3 4 8 12 16 15 14 13 9 5 6 7 11 10.

Get the book "Inntroduction to Algorithms" by Cormen...
Get the book "Inntroduction to Algorithms" by Cormen... :-
Will help you build the concepts around algorithms

I don't think there's something like C# algorithms. Algorithms are
algorithms. Mostly mathematical... cannot and shouldn't be language
specific

What's the problem in this

And in this one...? Where are you stuck

--
Happy Hacking
Gaurav Vaish | www.mastergaurav.co
www.edujini-labs.co
http://eduzine.edujini-labs.co
-----------------------------------------

Presuming that you are studying programming, a desire to improve your
Presuming that you are studying programming, a desire to improve your
problem-solving skills and understand logic are excellent goals to have in
mind. Almost all of programming is problem-solving, and involves the use of
logic

Problem-solving is more of a discipline than a skill, although there are
elements of skill involved in it. But the most important aspect is the
discipline, and this holds true for logic as well. The basis of
problem-solving is really fairly simple, but it requires a relentless
attention to detail to do it well

The first aspect of problem-solving is to identify the problem, and while
this may seem obvious, it is not as obvious as it seems. Most problems are
not singular in nature; they are made up of many smaller problems. For
example, you might consider thirst to be a problem. But quenching the thirst
is likely to be problematic. First, you must identify a source of water, and
ensure that it is good to drink. Second, you must determine how to get to
the source of water. Third, you have to figure out how to drink it, whether
to cup your hands, use a glass, etc

So, the first and perhaps most important aspect of problem-solving is
analysis. This is the breaking down of a problem into its component smaller
problems. Once each sub-problem has been identified, the solution to the
overall problem generally makes itself obvious, as it is the sum total of
all the solutions to the smaller problems that constitute the large one

It is also useful to identify what constitutes a problem. Life is actually
full of problems, and it is helpful to learn to identify them and apply
problem-solving skills to them. Any need which is not yet fulfilled is a
problem to be solved

In fact, it is not necessary to find C# algorithms or C# puzzles to develop
your problem-solving skills. Playing games can be helpful, as well as
solving various types of puzzles

As for logic, there is a lot to be learned. Here are a couple of places to
start. Logic is useful in all sorts of situations, in fact, anything
involving reasoning

http://www.philosophypages.com/lg/index.ht
http://plato.stanford.edu/entries/aristotle-logic

As for your specific third question, there is no answer to it, because you
have not sufficiently identified the nature of the problem to solve it. What
do you mean by "print?" And what are the parameters for this so-called
"printing?" For example, you mentioned a "N X N matrix" and typed the
members of a matrix in a column/row arrangement. However, you did not
specify anything about how the members were to be organized, if at all.

To write an application that solves your matrix problem, you have to tell
the computer exactly what to do. This means that there is no room for
interpretation. When you say "print" you are being very non-specific. The
word actually has a few different definitions, several of which might be
applicable. Do you want to "print" these numbers on paper? Do you want to
"print" them in a Console application? Do you want to "print" them in a
windowed application? And again, you "printed" the matrix using columns and
rows, but your problem didn't mention anything about columns and rows. The
computer cannot and will not guess how to fill in the blanks in your
requirements.

But as I mentioned earlier, the first step to solving a problem is to
identify all of the aspects of it.

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
Networking Components, Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net



Submitted via EggHeadCafe - Software Developer Portal of Choice
Free Online Courses Available for Eggheadcafe.com Users
http://www.eggheadcafe.com/tutorial...8-fc3cf6855293/free-online-courses-avail.aspx
 
A

Arne Vajhøj

c# algorithms / c# puzzles
29-Mar-07
Console.WriteLine("1 2 3 4");
Console.WriteLine("5 6 7 8");
Console.WriteLine("9 10 11 12");
Console.WriteLine("13 14 15 16");

That print 4 strings not a matrix.

And I don't think the original poster AFTER 3 YEARS is
still waiting for a solution for this problem.

Arne
 
J

Jackie

That print 4 strings not a matrix.

And I don't think the original poster AFTER 3 YEARS is
still waiting for a solution for this problem.

Arne

That's funny. I wrote a little something now to get the same result. I
don't think the OP will ever see it though but I don't mind. Actually, I
doubt it would be useful to *anyone*. I had nothing better to do.

------------------------
static void Main(string[] args)
{
const int maxPadding = 4;
const int numCols = 4;
string numbersLine = "1 2 3 4 8 12 16 15 14 13 9 5 6 7 11 10";
string[] numbersStrArray = numbersLine.Split(' ');

// Convert string array to int array
List<int> numbers = new List<int>();
foreach (string s in numbersStrArray)
{
int r; // Result from TryParse
if (!int.TryParse(s.Trim(), out r))
{
continue; // Or fail or whatever
}

numbers.Add(r);
}

// Sort it
numbers.Sort();

// Print it all
int x = 0;
foreach (int number in numbers)
{
// Take away padding at the end of the row
int padding = ((x == (numCols - 1)) ? 0 : maxPadding);
string fmtStr = String.Format("{0}{1}{2}", "{0,-", padding, ":D}");
string str = String.Format(fmtStr, number);

Console.Write(str);

x = (x + 1) % numCols;
if (x == 0)
{
Console.WriteLine();
}
}
}
------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top