Project Euler

Project Euler Problem 52

steloflute 2012. 6. 9. 00:33

Problem 52

12 September 2003

It can be seen that the number, 125874, and its double, 251748, contain exactly the same digits, but in a different order.

Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, contain the same digits.


Answer:
142857

 

 

C#

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;

namespace Euler {
    static class Program {
        static void Main(string[] args) {
            for (var i = 1; ; i++) {
                var set1 = new List<char>(i.ToString());
                set1.Sort();
                var set2 = new List<char>((i * 2).ToString());
                set2.Sort();                
                if (set2.SequenceEqual(set1)) {
                    var set3 = new List<char>((i * 3).ToString());
                    set3.Sort();
                    if (set3.SequenceEqual(set1)) {
                        var set4 = new List<char>((i * 4).ToString());
                        set4.Sort();
                        if (set4.SequenceEqual(set1)) {
                            var set5 = new List<char>((i * 5).ToString());
                            set5.Sort();
                            if (set5.SequenceEqual(set1)) {
                                var set6 = new List<char>((i * 6).ToString());
                                set6.Sort();
                                if (set6.SequenceEqual(set1)) {
                                    Console.WriteLine(i);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}



'Project Euler' 카테고리의 다른 글

(Haskell) Project Euler Solutions  (0) 2012.06.12
Project Euler Problem 54  (0) 2012.06.09
Project Euler Problem 51  (0) 2012.06.09
Project Euler Problem 50  (0) 2012.06.09
Project Euler Problem 49  (0) 2012.06.09