Skip to content

Instantly share code, notes, and snippets.

@progheal
progheal / KingChicken.md
Last active June 18, 2016 13:14
Proper solution of the challenge `KingChicken`: https://codefights.com/challenge/3vZaAk4SrnfoHgr9C

For odd number of students, it's easy to construct a situation that all of them are king chicken:
Label them from 1 to n, every one pecks the (n-1)/2 students numbered after him (labels wrap around from n to 1).
In this case, for every people, those (n-1)/2 students pecked him is pecked by the last people he pecked.
For example, for 7 students (Test 4),
Student 1 pecks Student 2,3,4, and Student 4 pecks Student 5,6,7, make Student 1 king chicken;
Student 2 pecks Student 3,4,5, and Student 5 pecks Student 6,7,1, make Student 2 king chicken;
etc.

For even number of students, things get interesting:
n=2 is impossible for both of them to be king; one must peck the other.

@progheal
progheal / colouringThePlane.md
Last active June 15, 2016 16:58
Proof of the challenge `colouringThePlane`

We'll prove that the number of color needed for input n is ceiling((n-1)^2/2), ie. this OEIS sequence with offset 1.

First we prove that this number is needed. To satisfy the condition, a square color should be different from all other squares in a specific range related to n. This range is the union of all retangles containing the initial square, and is a diamond shape centered at this square. For example, n=5 corresponding to this diamond shape:

@progheal
progheal / MCIMEpatch.py
Last active October 21, 2015 16:47
Minecraft CJK-IME patchfile generator
#!/usr/bin/env python3
# encoding=UTF-8
# Minecraft CJK-IME patchfile generator (Minecraft 中文輸入更新檔產生程式) by LPH66 @ PTT (Minecraft IGN: proghealer)
#
# Version 0.6 probably final (2015/10/22)
#
# 適用範圍:Minecraft 1.6.4 ~ 1.8.8;但 snapshot/prerelease 版本不一定適用。
#
# 系統需求: python 3.x 執行環境。(關於 python 環境安裝等事項可至 python 官方網站查詢:https://www.python.org/ )