Self-hatred

Project Euler Problem #8

I started here for clarification on the problem’s requirement. I had more problem correctly parsing the input than I did in crunching the highest product (three hours versus two minutes?). :/

using System;
using System.IO;

public class Eight
{
	static void Main()
	{
		int[] a = numIn();
		int   b = 0;
		int   c = 0;

		for (int i = 4; i < a.Length; i++)
		{
			b = a[i] * a[i-1] * a[i-2] * a[i-3] * a[i-4];

			if (b > c)
				c = b;
		}

		Console.WriteLine("n{0}n", c);
	}

	static int[] numIn()
	{
		string a = "";

		using (StreamReader z = new StreamReader("08.txt"))
			a = (z.ReadLine());

		int[] b = new int [a.Length];

		for (int i = 0; i < a.Length; i++)
			b[i] = a[i] - '0';

		return b;
	}
}

Categorised as: programming


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>