This file contains 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.string, std.conv; | |
import std.algorithm; | |
import std.array; | |
auto readArray(T)() | |
{ | |
return array(map!(a => to!T(a))(stdin.readln().split())); | |
} | |
void main() |
This file contains 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.array; | |
import std.algorithm; | |
import std.conv; | |
import std.container; | |
import std.stdio; | |
import std.string; | |
import std.typecons; | |
import std.typetuple; | |
This file contains 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
module brainfuck; | |
import std.algorithm; | |
import std.conv; | |
import std.container; | |
import std.file; | |
import std.stdio; | |
enum DATA_SIZE = 1024; |
This file contains 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
def is_balanced(msg, pos = 0, stack = 0): | |
for i in range(pos, len(msg)): | |
c = msg[i] | |
if c == '(': stack += 1 | |
elif c == ')': | |
stack -= 1 | |
if stack < 0: return False | |
elif c == ':': | |
if i < len(msg)-1: | |
if msg[i + 1] == '(': |
This file contains 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.traits; | |
import std.stdio; | |
// A custom attribute: | |
struct Test | |
{ | |
bool enabled = true; | |
int timeout = 5000; | |
} |
This file contains 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
/** | |
* data structure with: | |
* O(1) random access | |
* O(1) insertion | |
* O(1) deletion | |
* O(1) containment | |
*/ | |
class RandomAccessSet(T) | |
{ | |
private { |
This file contains 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 core.thread; | |
import core.sync.condition; | |
import core.time; | |
import std.random; | |
class Buffer(T) { | |
private { |
This file contains 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; | |
auto isLittleEndian() { | |
int i = 0x11223344; | |
byte* b = cast(byte*)&i; | |
return b[0] == 0x44; | |
} | |
void main() { | |
if (isLittleEndian()) writeln("little endian"); |
This file contains 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; | |
auto rotate(T)(T[][] array) { | |
foreach(i; 0 .. array.length/2) { | |
foreach(j; i .. array.length-i-1) { | |
T temp = array[i][j]; | |
array[i][j] = array[array.length-j-1][i]; | |
array[array.length-j-1][i] = array[array.length-i-1][array.length-j-1]; | |
array[array.length-i-1][array.length-j-1] = array[j][array.length-i-1]; |
This file contains 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.array; | |
struct MinStack(T) | |
{ | |
private { | |
Appender!(T[],T) items; | |
Appender!(T[],T) mins; | |
} | |
auto pop() { |
OlderNewer