Self-hatred

Posts Tagged ‘project euler’

Project Euler Problem #25

My submission was incorrect until I realized that my algorithm starts outputting Fibonacci numbers at the fourth Fibonacci term; it excludes the leading 0,1,1. I therefore set my counter to 3. using System; using System.Numerics; public class TwentyFive { static void Main() { BigInteger a = 1; BigInteger b = 2; BigInteger c = 0; [...]

Project Euler Problem #24

00:00:00.0716283 This one hurt my head, even after I was led onto Narayana Pandita’s algorithm. The algorithm depends on finding the largest integer that is smaller than another integer in the sequence/array; however, I’ve looked at several code solutions that just come in from the right and pick the first integer that is smaller than [...]

Project Euler Problem #23

This problem sucked. A benchmark for my solution is seemingly required for proper horn-tooting: 00:00:03.9170605 This problem, like Problem #19 threw me to the mental wolves. Keeping with the comparisons to #19, I also had to build up a supporting clade of methods to process the different elements of the problem. The core of the [...]

Project Euler Problem #22

My stroke of brilliance: c += ((b[i] – ’0′) + 10) % 26; Take b[i]. In this example make it the letter ‘A’. Subtract ’0′. You are left with. 17. Add 10. It becomes 27. Modulo 26. It returns 1. Works for every other letter (although you have to change the value of “z” to [...]

Project Euler Problem #20

using System; using System.Numerics; public class Twenty { static void Main() { BigInteger a = 100; string b; int c = 0; for (int i = 99; i >= 1; i–) a *= i; b = Convert.ToString(a); for (int i = 0; i < b.Length; i++) c += b[i] – ’0′; Console.WriteLine(“\n{0}\n”, c); } }

Project Euler Problem #19

Mark now knows more than Mark ever wished to know about leap years, months, days, and weeks – generally a whole lot of the Georgian calendar and calendar days versus solar days. using System; public class Nineteen { static void Main() { int a = 0; for (int i = 1901; i < = 2000; [...]

Problem #19 non-solution

I’ve been having way too much fun with these: using System; public class Nineteen { static void Main() { } // Days in one month. Assumes “1-12″ input. static int daysMonth(int year, int month) { int[] a = new int[13] {0,31,28,31,30,31,30,31,31,30,31,30,31}; int b = 0; if ((leap(year)) && (month == 2)) b = 29; else [...]