Skip to content

Instantly share code, notes, and snippets.

@314maro
314maro / main.cpp
Created April 15, 2014 09:57
C++でvmっぽいやつとその上で動くbrainfuckもどきを書いた
#include <iostream>
#include <vector>
#include "vm.hpp"
int main() {
const unsigned char offset = 0x03, loopend = 0x27;
// 0x00:ptr, 0x01:pc, 0x02:len
std::vector<unsigned char> inst =
{ 0x02, 0x00, 0x02, 0x00, 0x10 // store
, 0x02, 0x01, 0x02, offset, 0x10 // store
@314maro
314maro / 3.v
Last active August 29, 2015 13:59
Module Q11.
Require Import Arith.
Fixpoint sum_odd(n:nat) : nat :=
match n with
| O => O
| S m => 1 + m + m + sum_odd m
end.
Goal forall n, sum_odd n = n * n.
Proof.
@314maro
314maro / 2.v
Last active August 29, 2015 13:59
Module Q6.
Require Import Arith.
Goal forall x y, x < y -> x + 10 < y + 10.
Proof.
intros.
apply plus_lt_compat_r.
assumption.
Qed.
End Q6.
Module Q0_2.
Theorem tautology : forall P : Prop, P -> P.
Proof.
intros P H.
assumption.
Qed.
(*
Theorem wrong : forall P : Prop, P.
Proof.
intros P.
@314maro
314maro / shuntingYard.hs
Created April 8, 2014 16:21
操車場アルゴリズム 状態付きのパーサ 同じことの繰り返しが多い…
import Control.Applicative
import Control.Monad.State
import Data.Char
data Op = Add | Sub | Mul | Div | LParens
deriving (Show)
priority :: Op -> Int
priority Add = 2
priority Sub = 2
priority Mul = 3
@314maro
314maro / shunting_yard.c
Created April 4, 2014 03:39
操車場アルゴリズム
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
enum oper { lparens, add, sub, mul, div_op };
int pri(enum oper op) {
switch (op) {
case lparens:
return 0;
@314maro
314maro / monoid.hs
Created March 24, 2014 16:16
スタンピングモナド
{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, FlexibleContexts #-}
{-# LANGUAGE FunctionalDependencies, ScopedTypeVariables #-}
import Data.Void
import Data.Bifunctor
import Control.Comonad
import qualified Data.Monoid as M
-- i -> f はよくないかもしれない
class Bifunctor f => Monoidal i f | i -> f, f -> i where
midL1 :: a -> f i a
@314maro
314maro / language.c
Created March 23, 2014 13:03
クソコードかきました
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
// TODO: 値を返すところで NULL のかわりをしたい
typedef long long int_val;
@314maro
314maro / monoid.hs
Created March 19, 2014 07:21
ApplicativeでMonoidをくるむとMonoid 最大値や最小値とMonoid
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
import Data.Monoid
import Control.Applicative
newtype AppMon f m = AppMon { getAppMon :: f m }
deriving (Functor, Applicative)
instance (Applicative f, Monoid m) => Monoid (AppMon f m) where
mempty = pure mempty
mappend = liftA2 mappend
### ラムダ
🐫 変数👉 式
### 括弧
🌜 式🌛
### コメント
🌝 コメ🌝 ネストできる🌞 ント🌞
### 例
🐫 🐭 👉 🐫 🐮 👉 🐫 🐯 👉 🐭 🐯 🌜 🐮 🐯 🌛 🌝 Sコンビネータ🌞
### バグ
変数まわりにバグがある