Skip to content

Instantly share code, notes, and snippets.

Avatar

Kotet kotet

View GitHub Profile
@kotet
kotet / test.bf
Created Jan 5, 2019
Stack and Heap in Brainfuck
View test.bf
stack and heap in brainfuck
result: 7 5 0 3 1 7
b1 == 5
b2 == 7
stack == [3 7]
>> allocate 2
>+++ push 3
push 5
>+
@kotet
kotet / skskprime1.d
Created Dec 9, 2018
シクシク素数列 Advent Calendar 2018
View skskprime1.d
#!/usr/bin/rdmd
// 自然数を返す無限レンジ。
// map等の関数を使うためにはinputrangeである必要があり、
// inputrangeの条件を満たすためには
// front,popFront,emptyという3つの関数を実装する必要がある
struct NaturalNumber
{
long n = 1;
@kotet
kotet / main.js
Created Nov 20, 2018
論理式を変形するやつ
View main.js
"use strict";
let variable_names = [];
function tokenize(s) {
function isNextToken(s, i, t) {
for (let j = 0; j < t.length; j++) {
if (s.substr(i, t[j].length) == t[j]) {
return j;
@kotet
kotet / javarun.sh
Created Oct 11, 2018
javacを省略するやつ
View javarun.sh
javarun() {
if [ -z "$1" ]; then
echo "usage: javarun Triangle"
return
fi
local bar="\n------------------------------------\n"
echo -e $bar
mkdir -p output
local c="javac -d output $1.java $HOME/Turtle.java"
echo -e "$c:\n"
@kotet
kotet / mkws.sh
Last active Oct 5, 2018
ディレクトリ整理
View mkws.sh
mkws() {
local dhome="$HOME"
local droot="workspace"
local ddate="$(date '+%Y/%m-%d')"
local dname="${1:-space}"
local dseparator="."
local dsalt="$(cat /dev/urandom | tr -dc 'a-z' | head -c 4)"
local d="$dhome/$droot/$ddate/$dname$dseparator$dsalt"
mkdir -p -v "$d"
View kotet.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kotet
kotet / cramer.hs
Last active Jul 5, 2018
クラーメルの公式 in Haskell
View cramer.hs
import Data.List
-- 行列式
det :: [[Rational]] -> Rational
det [[a]] = a
det (a:b) | sum (map abs a) == 0 = 0
| head a == 0 = negate $ det (map (\ (a:b) -> b ++ [a]) (a:b))
| otherwise = (head a) * (det $ sub a b)
where sub a bs = map (\b -> tail(zipWith (\x y -> y - x * ((head b) / (head a))) a b)) bs
@kotet
kotet / qm.d
Created Jul 1, 2018
Quine-McCluskey algorithm
View qm.d
// (a & b) + (¬a & c) → [[T,T,X],[N,X,T]]
enum Literal
{
T, // Term
N, // ¬Term
X // Null
}
alias Conjunction = Literal[];
alias DNF = Conjunction[]; // Disjunctive normal form
@kotet
kotet / binary.d
Created Jul 5, 2017
binary.h in D
View binary.d
mixin template binary(T)
{
mixin(() {
import std.conv : to;
import std.range : chain, only, iota;
import std.string : rightJustify, format;
string result = "";
foreach (n; iota(0, T.max).chain(T.max.only))
View report-generator.sh
json=$(curl -s --header "PRIVATE-TOKEN: $REPORT_GENERATOR_TOKEN" https://gitlab.com/api/v4/projects/$PROJECT_ID/issues?state=opened)
len=$(echo $json | jq length)
echo '<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body>'
echo "<h1>" $(date) "</h1>"
for i in $( seq 0 $(($len - 1)) ); do
item=$(echo $json | jq ".[$i]")