Skip to content

Instantly share code, notes, and snippets.

View doraneko94's full-sized avatar

Shuntaro Ohno doraneko94

View GitHub Profile
@doraneko94
doraneko94 / krypto.py
Last active July 12, 2019 05:55
Full search of the game "krypto".
lst = [11, 10, 22, 10, 25]
ans = 1
tolerance = 1e-4
size = len(lst)
def n_merge(N):
ans = N
for i in range(1, N):
ans *= i**2
return ans
@doraneko94
doraneko94 / ARC028D.cpp
Last active May 6, 2019 11:26
answer for ARC028 D
#include <iostream>
using namespace std;
int N, M, Q;
int a[2010];
long long dp[2010][2010] = {0};
long long rdp[2010][2010] = {0};
long long accum[2010];
const long long mod = 1000000007;
@doraneko94
doraneko94 / gamepad.py
Created March 23, 2019 04:11
Controlling a mouse with a gamepad. This code is optimized for "LOGICOOL gamepad F301r".
import pygame
from pygame.locals import *
import time, sys
import pyautogui
def main():
pyautogui.FAILSAFE = False
pygame.init()
while True:
@doraneko94
doraneko94 / roc_auc_ci.py
Last active January 4, 2025 08:56
Calculating confidence interval of ROC-AUC.
from sklearn.metrics import roc_auc_score
from math import sqrt
def roc_auc_ci(y_true, y_score, positive=1):
AUC = roc_auc_score(y_true, y_score)
N1 = sum(y_true == positive)
N2 = sum(y_true != positive)
Q1 = AUC / (2 - AUC)
Q2 = 2*AUC**2 / (1 + AUC)
SE_AUC = sqrt((AUC*(1 - AUC) + (N1 - 1)*(Q1 - AUC**2) + (N2 - 1)*(Q2 - AUC**2)) / (N1*N2))
@doraneko94
doraneko94 / partial_transposition.py
Created December 5, 2018 01:15
Calculating partial transposition.
import numpy as np
from math import sqrt
def partial_transposition(density_matrix: np.ndarray, basis_num_1: int=0, basis_num_2: int=0):
if basis_num_1 == 0 and basis_num_2 == 0:
basis_num_1 = int(sqrt(density_matrix.shape[0]))
basis_num_2 = basis_num_1
elif basis_num_1 == 0:
basis_num_1 = int((density_matrix.shape[0])/basis_num_2)
elif basis_num_2 == 0:
@doraneko94
doraneko94 / partial_dependence.py
Last active December 7, 2018 01:50
Calculating partial dependence of any classifier which has an attribute of "n_features_" and "n_classes_".
import numpy as np
from scipy.stats.mstats import mquantiles
from math import sqrt, ceil
from matplotlib import pyplot as plt
def _grid_from_X(X, percentiles=(0.05, 0.95), grid_resolution=100):
if len(percentiles) != 2:
raise ValueError('percentile must be tuple of len 2')
if not all(0. <= x <= 1. for x in percentiles):
@doraneko94
doraneko94 / myfish.py
Created November 25, 2018 22:04
"Hey, that's my fish!"-ish CUI game. Because this game is my study and not user-friendly, please buy this board game or official App if you want to really enjoy "Hey, that's my fish!"
import random
alpha = ["A", "B", "C", "D"]
fishes = [1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,
2,2,2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,2,2,
3,3,3,3,3,3,3,3,3,3]
f = random.sample(fishes, len(fishes))
@doraneko94
doraneko94 / caesar_dictionary.py
Last active November 6, 2018 06:54
The improved version of "caesar.py" using a list of 153,484 words. "dictionary.pkl" is available from http://ushitora.net/archives/456 .
import pickle
ALPHA = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
alpha = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
word = input("Please Enter Words: ")
def plus_i(i, w):
if w in alpha:
n = alpha.index(w) + i
@doraneko94
doraneko94 / double_pendulum.py
Created September 21, 2018 09:56
Double pendulum simulator.
import math, tkinter, time, sys
g = 9.8
m1 = 1
m2 = 1
l1 = 150
l2 = 150
dt = 0.1
theta1 = math.pi / 2
theta2 = math.pi / 2 #+ 0.02
@doraneko94
doraneko94 / caesar.py
Last active November 6, 2018 06:55
Descrambler for Caesar cipher.
ALPHA = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
alpha = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
word = input("Please Enter Words: ")
for i in range(len(alpha)):
process = ""
for w in word:
if w in alpha:
n = alpha.index(w) + i
if n > 25: