Problem of the Day
A new programming or logic puzzle every Mon-Fri

PIe

Welcome back to Monday. Hope everyone enjoyed the first week of Sunday football!

Today's problem is to create a function that takes in a number and outputs that digit of pi. For example, if the function received 2 it would output 4.

Permalink: http://problemotd.com/problem/pie/

Comments:

  • Anonymous - 10 years, 3 months ago

    today as lambda:

    \x -> mod (pi * 10x) 10

    reply permalink

  • malboy - 10 years, 3 months ago

    This is what I came up with in C#. Probably not the fastest/most efficient method, but whatevs.

            int numUserInput;
            string strUserInput,
                strPiDigits;
            char[] charArrayPiDigits;
    
            Console.WriteLine("Today's problem is to create a function that \n" +
                "takes in a number and outputs that digit of pi. For example, \n" +
                "if the function received 2 it would output 4.");
    
            strUserInput = Console.ReadLine();
            numUserInput = Convert.ToInt32(strUserInput);
    
            strPiDigits = (Math.PI).ToString();
    
            charArrayPiDigits = strPiDigits.ToCharArray();
            Console.WriteLine(charArrayPiDigits[numUserInput + 1]);
    
            Console.ReadLine();
    

    reply permalink

  • Anonymous - 10 years, 3 months ago

    int x = int.Parse(Console.ReadLine());
    Console.WriteLine(Math.PI.ToString().Replace(".", "").ToCharArray()[x]);
    

    reply permalink

Content curated by @MaxBurstein