Skip to content

Instantly share code, notes, and snippets.

@johnchen902
johnchen902 / main.py
Last active March 11, 2019 13:38
Girls Frontline Chip Calculator
#!/usr/bin/env python3
from dataclasses import dataclass
from ortools.sat.python import cp_model
from functools import reduce
### PARAMETERS
def get_available_area():
# This is 5-star AGS-30, change it for different HOC/stars.
return Mask("""
..xx....
@johnchen902
johnchen902 / 10-problem.pdf
Last active January 9, 2019 11:05
NTU PK 2018 -- A. f(Graph)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@johnchen902
johnchen902 / 10-description.txt
Last active December 25, 2021 06:02
$O(n\log n)$ Matrix Chain Multiplication
Description
---
Just matrix chain multiplication.
Input format
---
There may be multiple test cases.
Each test case consists of two lines.
On the first line is an integer, $n$, the number of matrices.
On the second line are $n + 1$ integers, the dimension of the matrices.
@johnchen902
johnchen902 / unshare.sh
Created June 25, 2017 16:56
Network namespace timing
#!/usr/bin/env bash
TIMEFORMAT="%R"
sumt1=0
sumt2=0
for ((i=1; i<=10; i++)); do
echo -ne $i\\r
sumt1=$(bc <<< "$sumt1 + $(time (unshare -n true) 2>&1)")
sumt2=$(bc <<< "$sumt2 + $(time (unshare -n true) 2>&1)")
sleep $(bc <<< "scale=3; ($sumt1 + $sumt2) / $i * 2")
done
@johnchen902
johnchen902 / os-project-4.11.6.patch
Created June 23, 2017 14:29
Operation System Project 2 (Kernel Patch)
diff -Nur linux-4.11-copy/drivers/char/Kconfig linux-4.11/drivers/char/Kconfig
--- linux-4.11-copy/drivers/char/Kconfig 2017-05-01 10:47:48.000000000 +0800
+++ linux-4.11/drivers/char/Kconfig 2017-06-23 20:07:55.645195892 +0800
@@ -548,6 +548,18 @@
The mmtimer device allows direct userspace access to the
Altix system timer.
+config SOCKET_SERVER
+ tristate "Character-device that listen and write to a socket"
+ default m
@johnchen902
johnchen902 / 10-README
Last active May 26, 2017 17:14
Problem Template
$ tree
.
├── allsolution
│   ├── ac1.cpp
│   ├── tle1.cpp
│   └── wa1.cpp
├── generator.py
├── Makefile
├── solution.cpp
├── testdata
@johnchen902
johnchen902 / 01-test.c
Last active April 4, 2017 15:48
Network namespace performance
#define _GNU_SOURCE
#include <math.h>
#include <sched.h>
#include <signal.h>
#include <stdio.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
#define CHILD_STACK_SIZE (1 << 15)
static int child_main(void *param) { (void) param; return 0; }
@johnchen902
johnchen902 / coselect.cpp
Created November 21, 2016 14:08
boost::coroutine2 + ::select = ???
#include <stdio.h>
#include <boost/coroutine2/coroutine.hpp>
#include <sys/select.h>
#include <list>
#include <utility>
namespace coselect {
struct tri_fd_set {
fd_set read, write, except;
@johnchen902
johnchen902 / a.txt
Last active October 12, 2016 04:23
journalctl -b -3
-- Logs begin at Fri 2016-05-27 13:25:50 CST, end at Wed 2016-10-12 12:21:03 CST. --
Oct 12 11:24:12 johnchen902-arch-4 systemd-journald[227]: Runtime journal (/run/log/journal/) is 8.0M, max 597.1M, 589.1M free.
Oct 12 11:24:13 johnchen902-arch-4 systemd-journald[227]: System journal (/var/log/journal/) is 1.0G, max 4.0G, 2.9G free.
Oct 12 11:24:13 johnchen902-arch-4 systemd-journald[227]: Time spent on flushing to /var is 886us for 2 entries.
Oct 12 11:24:13 johnchen902-arch-4 kernel: microcode: microcode updated early to revision 0x20, date = 2016-03-16
Oct 12 11:24:13 johnchen902-arch-4 kernel: Linux version 4.7.6-1-ARCH (builduser@tobias) (gcc version 6.2.1 20160830 (GCC) ) #1 SMP PREEMPT Fri Sep 30 19:28:42 CEST 2016
Oct 12 11:24:13 johnchen902-arch-4 kernel: Command line: BOOT_IMAGE=/vmlinuz-linux root=UUID=cea23e03-0fb9-4965-9e31-35fb06578423 rw verbose initcall_debug no_console_suspend
Oct 12 11:24:13 johnchen902-arch-4 kernel: x86/fpu: xstate_offset[2]: 576, xstate_sizes[2]: 256
Oct 12 11:24:13 jo
#include <stdio.h>
enum { unknown, is_false, is_true } dp[1 << 25];
bool solve(int x, int mod, int mask) {
if(dp[mask] != unknown)
return dp[mask] == is_true;
if((x ^ mask) % mod == 0) {
dp[mask] = is_false;
return false;
}
for(int m = mask; m; m ^= m & -m)