Skip to content

Instantly share code, notes, and snippets.

View TonyMooori's full-sized avatar

TonyMooori TonyMooori

  • Japan
View GitHub Profile
@TonyMooori
TonyMooori / search_eq_logic.py
Created June 19, 2020 17:08
限られた真理関数のみで特定の真理関数と意味論的に同値なものを構成するプログラム
from typing import List, Callable, Union, Dict
from copy import deepcopy
def make_logical_op(n: int, f) \
-> Callable[[List[bool]], bool]:
def __retfunc(stack: List[bool]):
if len(stack) < n:
raise RuntimeError("Lack of arguments")
@TonyMooori
TonyMooori / detect_color_position.py
Last active June 24, 2024 08:21
特定の色の座標を抽出するプログラム
import cv2
import numpy as np
# 0 <= h <= 179 (色相) OpenCVではmax=179なのでR:0(180),G:60,B:120となる
# 0 <= s <= 255 (彩度) 黒や白の値が抽出されるときはこの閾値を大きくする
# 0 <= v <= 255 (明度) これが大きいと明るく,小さいと暗い
# ここでは青色を抽出するので120±20を閾値とした
LOW_COLOR = np.array([100, 75, 75])
HIGH_COLOR = np.array([140, 255, 255])
@TonyMooori
TonyMooori / algorithm_puzzle_7.rs
Created July 25, 2018 11:51
アルゴリズムパズル7実装例
// アルゴリズムパズル 7. 真夜中の橋渡り
use std::io;
use std::cmp::{max,min};
use std::collections::BinaryHeap;
fn read_line() -> String{
let mut s = String::new();
io::stdin().read_line(&mut s).unwrap();
s.trim().to_string()
}
@TonyMooori
TonyMooori / algorithm_puzzle_6.cl
Created July 25, 2018 11:51
アルゴリズムパズル6実装例
; 6. 指数え
(defparameter *fingers*
(list
"index finger" "thumb" "index finger" "middle finger"
"ring finger" "little finger" "ring finger" "middle finger"))
(defun solve-6 (n)
(nth (mod n 8) *fingers*))
@TonyMooori
TonyMooori / algorithm_puzzle_5.rs
Created July 24, 2018 00:33
アルゴリズムパズル 5. 行と列の入れ替え 実装例
// アルゴリズムパズル 5. 行と列の入れ替え
use std::io;
use std::process;
fn read_line() -> String{
let mut s = String::new();
io::stdin().read_line(&mut s).unwrap();
s.trim().to_string()
}
@TonyMooori
TonyMooori / algorithm_puzzle_4.lisp
Created July 23, 2018 02:07
アルゴリズムパズル 4 兵士の輸送
(defun solve-4 (n-soldier n)
(if (= n-soldier 0)
(print (format nil "~{~A~}" (list "it takes " (write-to-string n) " steps.")))
(progn
(print "2 young man go to left.")
(print "1 young man go to right")
(print "1 soldier go to left.")
(print "1 young man go to right.")
(solve-4 (1- n-soldier) (+ 4 n)))))
@TonyMooori
TonyMooori / algorithm_puzzle_3.pde
Created July 23, 2018 02:03
アルゴリズムパズル3 長方形の分割
void setup() {
size(640, 480);
}
void draw() {
background(0);
make_triangle(millis()/100);
}
void make_triangle(int n) {
@TonyMooori
TonyMooori / algorithm_puzzle_2.lisp
Created July 23, 2018 02:02
アルゴリズムパズル 2 手袋選び
; アルゴリズムパズル 2
(defun solve-2-a (xs)
(1+ (apply #'+ xs)))
(defun solve-2-b (xs)
(let*(
(ys (sort xs #'<))
(min-val (first ys))
(rest-ys (rest ys)))
@TonyMooori
TonyMooori / wolf_goat_cabbage.rs
Created July 16, 2018 13:11
アルゴリズムパズル 1. 狼と山羊とキャベツ
use std::collections::HashSet;
#[derive(Hash, Eq, PartialEq, Debug, Clone)]
enum Kind{
None,
Cabbage,
Wolf,
Goat,
}
@TonyMooori
TonyMooori / main.py
Created April 29, 2018 15:52
Pythonによる操車場アルゴリズムの実装例
import re
import math
from inspect import signature
import sys
import traceback
LEFT = True
RIGHT = False
# トークンに分割する際に使う正規表現関係