Skip to content

Instantly share code, notes, and snippets.

View alan23273850's full-sized avatar

Wei-Lun Tsai alan23273850

  • Academia Sinica
  • Taipei, Taiwan
View GitHub Profile
@alan23273850
alan23273850 / Shor.py
Last active April 1, 2024 14:57
An example of Shor's algorithm to show that a lot of feasible states cannot be measured.
#!/usr/bin/python3
import cmath, math
a = 7; print('a =', a)
N = 15; print('N =', N)
for ord in range(1, N):
if (a ** ord) % N == 1:
break
print('ord =', ord)
m = 2 ** math.ceil(math.log2(N*N))
filetype indent on
set nu
set ai
set bg=dark
set expandtab
set tabstop=4
set shiftwidth=4
set incsearch
set backspace=2
set autoindent
alias rm='rm -i'
alias ps='pipenv shell'
alias pi='pipenv install'
alias dc='deactivate'
alias bwt='cd content && bash insert_title_and_tags.sh && cd .. && hugo server --disableFastRender'
alias bw='git commit -m "commit" && git push && cd content && bash insert_title_and_tags.sh && cd .. && hugo && cd public && git add . && git commit -m "commit" && git push && cd ..'
alias new='f(){ hugo new zerojudge/$1.md; touch static/zerojudge/$1.cpp; unset -f f; }; f'
alias z='cd ..'
alias ga='git add'
MODULENAME := hideproc
obj-m += $(MODULENAME).o
$(MODULENAME)-y += main.o
KERNELDIR ?= /lib/modules/`uname -r`/build
PWD := $(shell pwd)
all:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
clean:
#include <linux/cdev.h>
#include <linux/ftrace.h>
#include <linux/kallsyms.h>
#include <linux/list.h>
#include <linux/module.h>
#include <linux/proc_fs.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("National Cheng Kung University, Taiwan");
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
const int N = 1000, C = 8; // N: 全部可能的卡片數量,C: 全部可能的顏色數量
int arr[N], n, mid; // arr: 每張卡片的顏色,n: 卡片總數量,mid: 所取每個顏色卡片的最低數量下限 (用 mid 是為了要配合 binary search)
int dp[N][1 << C]; // DP memoization
bool visit[N][1 << C]; // visit memoization
int times[N]; // 記錄每張卡片是第幾次出現自己這個顏色
vector<int> pos[C]; // 記錄每個顏色自己出現的所有位置
-- Problem 1)
myFst :: (a, b) -> a
myFst (a, b) = a -- Method 1 (man-made function)
--myFst = fst -- Method 2 (built-in function)
-- Problem 2)
myOdd :: Int -> Bool
myOdd(x) = (x `mod` 2) == 1 -- Method 1 (man-made function)
--myOdd x = odd x -- Method 2 (built-in function)