2014-04-01から1ヶ月間の記事一覧

Project Euler 13

PE

Problem 13 System.Numerics.BigInteger を使う。 部分文字列は、Substring() メソッドを使う。 using System; using System.IO; using System.Numerics; public class PE013 { public static void Main() { var x = new BigInteger(0); foreach (string s i…

Project Euler 12

PE

Problem 12 約数の個数は、4 約数の個数 - Wikipedia のように求める。 Python の itertools.groupby が欲しい。素因数分解したあとのグループ化で使う。Enumerable.GroupBy でできるかな? using System; using System.IO; using System.Collections.Generic…

三角数を求める(コルーチンの練習)

三角数 - Wikipediaを求めるプログラム。C# のコルーチンの練習。 using System; using System.Collections.Generic; using System.Linq; public class TestTriangles { static IEnumerable<int> Triangles() { int x = 0; for (int i = 1; /* none */; i++) { x </int>…

Project Euler 11

C# PE

Problem 11 C# ポケットリファレンス を読みながら、ファイル読み込みや、文字列処理を書いています。 File.ReadAllText, File.ReadAllLinesで一括でテキストを読み込む String.Split で文字列を分割 int best = 0 を var best = 0 と書いたら内部ではどう扱…

Project Euler 10

PE C#

Problem 10 配列の練習 答えは int だとオーバーフローする using System; using System.IO; using System.Collections.Generic; public class P010 { static List<int> sieve(int n) { bool[] xs = new bool[n+1]; for (int i = 0; i <= n; i++) { xs[i] = true;</int>…