Self-hatred

Project Euler Problem #16

/twitch

Anything to avoid using VS, right? For my pain, I learned that Bash, while being excellent for fast big arithmetic operations (compared to C#), doesn’t enjoy working with large multiples or exponents.

using System;
using System.Numerics;

class Program
{
    static void Main()
    {
        BigInteger	a;
        string		b;
        int		c = 0;

        a = BigInteger.Pow(2, 1000);
        b = Convert.ToString(a);

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

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

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>