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 pydot | |
import sys | |
# This script checks whether the input buchi automaton given by a dot file is empty. | |
# Labels of initial states should be init. | |
# Labels of accepting states should be accept. | |
if len(sys.argv) != 2: | |
print("usuage: buchi_empty.py path_to_dotfile") | |
sys.exit() |
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
; toffoliのみを用いて可逆fulladderを作る | |
def not(x) = if x == 1 then 0 else 1 | |
def toffoli(x, y, z) = if x == 1 && y == 1 then not(z) else z | |
def or(x, y) = | |
let nx = toffoli(x, 1, 1) in | |
let ny = toffoli(y, 1, 1) in | |
toffoli(nx, ny, 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 Data.List | |
import Data.Maybe | |
-- 31 | |
isqrt :: Int -> Int | |
isqrt = floor . sqrt . fromIntegral | |
isprime :: Int -> Bool | |
isprime n | |
| n <= 1 = False |
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
rot :: Int -> [Char] -> [Char] | |
rot 0 a = a | |
rot n a = rot (n-1) [rotsucc x | x <- a] | |
rotsucc :: Char -> Char | |
rotsucc 'z' = 'a' | |
rotsucc 'Z' = 'A' | |
rotsucc a = if elem a (['a'..'z'] ++ ['A'..'Z']) then (succ a) else a | |
myzipWith :: (a -> b -> c) -> [a] -> [b] -> [c] |
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
max' :: Int -> Int -> Int | |
max' a b | |
| a <= b = b | |
| otherwise = a | |
replicate' :: Int -> a -> [a] | |
replicate' 0 a = [] | |
replicate' n a = a:(replicate' (n-1) a) | |
take' :: Int -> [a] -> [a] |
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 itertools | |
import random | |
def oneset(a,b,c): | |
for j in range(4): | |
if (a[j] + b[j] + c[j]) % 3 != 0: | |
return False | |
return True | |
def isnotset(field,card): |
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
-- 基本的な高階関数(chapter5) | |
applyPair :: (a -> b) -> (a, a) -> (b, b) | |
applyPair f t = ((f.fst) t, (f.snd) t) | |
applyN :: (a -> a) -> Int -> a -> a | |
applyN f 1 x = f x | |
applyN f n x = f $ applyN f (n-1) x | |
squares :: Int -> [Int] | |
squares n = takeWhile (<=n) $ map (^2) [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
-- 再帰(chapter4) | |
tri_number :: Int -> Int | |
tri_number n | |
| n == 0 = 0 | |
| otherwise = n + tri_number (n-1) | |
tetration :: Integer -> Integer -> Integer | |
tetration n m | |
| m == 0 = 1 | |
| otherwise = (n^) $ tetration n (m-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
-- マンハッタン距離(chapter1) | |
manlen :: (Int, Int) -> (Int, Int) -> Int | |
manlen p1 p2 = abs ((fst p1)-(fst p2)) + abs ((snd p1)-(snd p2)) | |
points :: Int -> [(Int, Int)] | |
points x = [(x1,x2) | x1 <- [-1*x..x], x2 <- [-1*x..x]] | |
mancircle :: Int -> [(Int, Int)] | |
mancircle x = [p | p <- points x, manlen p (0,0) == x] |
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
#多変数多項式の整序 (辞書式順序ver) | |
# ex) ((x**2)y+x(y**2)+y**2)÷(xy-1,y**2-1) -> [[2,1,1],[1,2,1],[0,2,1]] [[[1,1,1],[0,0,-1]],[[0,2,1],[0,0,-1]]] | |
def multikxver(): | |
f_in,g_in = input().split() | |
f = [] | |
g = [] | |
for i in f_in[2:-2].split("],["): | |
f.append(list(map(int,i.split(",")))) | |
for ii in g_in[3:-3].split("]],[["): |
NewerOlder