Skip to content

Instantly share code, notes, and snippets.

@imanyu
imanyu / FixedSizeQueue.cs
Created February 11, 2014 02:35
固定長Queue
public class FixedSizeQueue<T> : Queue<T>
{
private Queue<T> queue;
private int size = 50;
public FixedSizeQueue()
{
queue = new Queue<T>();
}
@imanyu
imanyu / FileIO.cs
Created February 2, 2014 14:00
WinRTでのファイルの読み書き
using Windows.Storage;
using Windows.Storage.Streams;
using System.Text;
// ファイルの読出し
private async string FileRead(string filename)
{
// ローカルフォルダの指定
StorageFolder installedStorageFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
@imanyu
imanyu / MainPage.xaml.cs
Created August 2, 2013 06:49
StreamSocket@WinRT 【C#】
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
@imanyu
imanyu / MainPage.xaml
Created August 2, 2013 05:55
StreamSocket@WinRT 【XAML】
<Page
x:Class="SocketConnectionApp01.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:SocketConnectionApp01"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="DarkOrchid">
/*
* 10以下の素数の和は 2 + 3 + 5 + 7 = 17 である.
* 200万以下の全ての素数の和を求めよ.
*/
public class Problem010 {
public static void main(String[] args) {
long sum = 0;
/*
* ピタゴラス数(ピタゴラスの定理を満たす自然数)とは a < b < c で以下の式を満たす数の組である.
* a^2 + b^2 = c^2
* 例えば, 3^2 + 4^2 = 9 + 16 = 25 = 5^2 である.
* a + b + c = 1000 となるピタゴラスの三つ組が一つだけ存在する.
* これらの積 abc を計算しなさい.
*/
public class Problem009 {
/*
* 以下の1000桁の数字から5つの連続する数字を取り出して その積を計算する. そのような積の中で最大のものの値はいくらか.
73167176531330624919225119674426574742355349194934
96983520312774506326239578318016984801869478851843
85861560789112949495459501737958331952853208805511
12540698747158523863050715693290963295227443043557
66896648950445244523161731856403098711121722383113
62229893423380308135336276614282806444486645238749
30358907296290491560440772390713810515859307960866
/*
* 素数を小さい方から6つ並べると 2, 3, 5, 7, 11, 13 であり, 6番目の素数は 13 である.
* 10001 番目の素数を求めよ.
*/
public class Problem007 {
public static void main(String[] args) {
int cnt = 0;
int num = 2;
/*
* 最初の10個の自然数について, その二乗の和は,
* 1^2 + 2^2 + ... + 10^2 = 385
* 最初の10個の自然数について, その和の二乗は,
* (1 + 2 + ... + 10)^2 = 3025
* これらの数の差は 3025 - 385 = 2640 となる.
* 同様にして, 最初の100個の自然数について二乗の和と和の二乗の差を求めよ.
*/
/*
* 2520 は 1 から 10 の数字の全ての整数で割り切れる数字であり, そのような数字の中では最小の値である.
* では, 1 から 20 までの整数全てで割り切れる数字の中で最小の正の数はいくらになるか.
*/
public class Problem005 {
public static void main(String[] args) {
long sum = 1;
for(int i = 2; i <= 20; i++)