This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int[] prime_list; | |
| void generate_prime_list(int N) { | |
| prime_list = [2]; | |
| bool not_prime = false; | |
| foreach(i; 3..N+1) { | |
| foreach(j; prime_list) { | |
| if(i % j == 0) { | |
| not_prime = true; | |
| break; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import std.stdio; | |
| import std.bigint; | |
| import std.algorithm; | |
| import std.range; | |
| void main() | |
| { | |
| //iota(1, 11).map!(x => fibonacci(x) / (2 ^^ x)).each!writeln; | |
| //iota(1, 9).map!(x => nCr(8, x)).writeln; | |
| //iota(1, 10).map!(x => factorial(x)).writeln; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import std.stdio; | |
| import std.conv; | |
| import std.math; | |
| void main(string[] args) | |
| { | |
| /* | |
| n → ∞においてF_{n+1} = φF_nであることを利用して近似をとる | |
| */ | |
| auto phi = (1+sqrt(5.))/2; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import std.stdio, std.conv, std.random, std.range, std.string; | |
| const USAGE_MESSAGE = | |
| r" The player opens cells that don't contain mine. | |
| If you open the mine cell, you lose. | |
| [Cell] | |
| - x: not opened yet | |
| - F: flag | |
| - number: showing how many mines in the nearby 8 cells. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import std.stdio; | |
| import std.range; | |
| import std.conv; | |
| import std.algorithm; | |
| void main() | |
| { | |
| iota(1, 100).map!(x => x % 15 == 0 ? "FizzBuzz": x % 3 == 0 ? "Fizz": x % 5 == 0 ? "Buzz": x.to!string).each!writeln; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import std.stdio; | |
| import std.conv; | |
| import std.range; | |
| import std.bigint; | |
| import std.datetime; | |
| import std.math; | |
| import std.algorithm; | |
| import std.datetime.stopwatch: benchmark, StopWatch; | |
| void main(string[] args) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import std.stdio; | |
| import std.json; | |
| import std.net.curl; | |
| import std.conv; | |
| import std.regex; | |
| import std.file; | |
| import std.string; | |
| import std.algorithm; | |
| import std.parallelism: parallel; | |
| import std.range; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class MonteCarlo { | |
| static public final long POINT_AMOUNT = 10000; | |
| public static void main(String[] args) { | |
| long count = 0; | |
| for (long i = 0; i <= POINT_AMOUNT; i++) { | |
| Point p = new Point(Math.random(), Math.random()); | |
| if(p.isInCircle()) count++; | |
| } | |
| System.out.println((double)4*(double)count / (double)POINT_AMOUNT); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import std.stdio, std.net.curl, std.file, std.windows.charset, std.conv, std.regex; | |
| void main() | |
| { | |
| auto content = get("yahoo.co.jp"); | |
| writeln(to!(string)(toMBSz(content))); | |
| auto r = ctRegex!("\\<img.*?src\\s*?=\\s*?[\"|\'](.*?(png|jpeg|jpg|gif))[\"|\'].*?\\>"); | |
| foreach(c; matchAll(content, r)) | |
| { | |
| writeln(to!(string)(toMBSz(c[1]))); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| class EuclidSolver { | |
| static func solveGCD(_ a: Int, _ b: Int) -> Int { | |
| if a == 0 || b == 0 { | |
| fatalError("Fount zero value in the arguments") | |
| } | |
| var i = a, j = b | |
| if i < j { |