Skip to content

Instantly share code, notes, and snippets.

In this document, "cycle" means North-West-South-East move once, and "loop" means the repeating pattern after some amount of cycles are run. "Loop length" the number of cycles needed to obtain the loop, and call a pattern "length X loop" meaning it will repeat the end state after every X cycles.

So, here's my basic item. Call it Q0.

.##.
#.O#
#..#
.##.
@progheal
progheal / 000Guestbook.md
Created November 30, 2023 08:03
留言板

開這裡當做一個暫時的留言板好了。如果沒有其他方法聯絡得到我但正好有 github 帳號的話可以在這裡留言。 我會不定時上來巡一下,所以不保證我什麼時候會看得到。

TODO: 弄個好一點不用登入 github 的接收訊息處


This is a temporary guestbook. If you have no other way of contacting me but happened to have a github account,

@progheal
progheal / tally.js
Created October 8, 2023 14:56
《西瓜遊戲得分裡的數學》(https://blog.cruciferslab.net/?p=1535) 的模擬程式
function randomFruit()
{
return Math.floor(Math.random() * 5);
}
const FruitInfo = [
{apple: 1/32, point: 3.09375}, // 櫻桃
{apple: 1/16, point: 5.1875}, // 草莓
{apple: 1/8, point: 7.375}, // 葡萄
@progheal
progheal / CubeFolding.md
Last active December 22, 2022 20:03
Advent of Code 2022 Day 22: Monkey Maps, cube folding algorithm

Let's start from our designated starting point, the "top left" of the first cube face, going right. This means we are going clockwise along the edge of the net.

We want to trace the edge and trying to match the "edge cells", which is represented by a cell, and its direction when we traversed them clockwisely. Using the sample as example, the first edge is (1,9,>). If the current edge does not match other edge, we simply push that into a stack.

We go along the edge, stopping every N times to determine which turn do we take on the net. This is done by going one step out and check myself and my left.

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
struct Op
{
int xm, xM, ym, yM, zm, zM, sw;
};
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <iterator>
#include <algorithm>
using namespace std;
@progheal
progheal / 2021_AprilFool_dragoncoin.txt
Last active April 2, 2021 21:05
龍窩 2021 魚人節挖幣 (?) 活動
為了讓 gist 的標題有點意義所以加的檔案
@progheal
progheal / factsqrt.cpp
Created January 10, 2021 13:59
Timc 2021 新年題 Q3
#include <iostream>
#include <cmath>
#include <map>
#include <queue>
#include <tuple>
using namespace std;
// switch the comment below to see log printed to stderr
//#define LOGERR(x) x
#define LOGERR(x)

Let's analyze all these digits. We classify the appearing position within the number it begins, with the rightmost being 1. For example, the 111 in 41118 is said to be at position 4, while the cross-number 777 between 72977 and 72978 is said to be at position 2. The input size is n.

000

Because 000 cannot cross number (no number starts with 0), the position of 000 is at least 3. For position p, the other digits of the number can be combined to count them; for example, numbers for n=5 and p=4 are 10000, 10001, 10002, ..., 90009, 100000; there are 100 - 10 + 1 = 91 of them.

It is easy to deduct that there's 10^{n-3}-10^{p-3}+1 ways to have 000 in position p. Adds up all of these for p from 3 to n, we have
![(n-2)\times10^{n-3}-\sum_{p=3}^n 10^{p-3}+(n-2)=(n-2)\times10^{n-3}-\underset{n-2}{\underbrace{111\dots1}}+(n-2)](http://latex.codecogs.com/gif.latex?%28n-2%29%5

Let's classify all the possible equilateral triangles of interest. As there are more equilateral triangles in the proof, let's call those we want to count the counting triangles.

For each of the counting triangle asked, define its enclosing triangle be the minimal upright equilateral triangle that goes alone the network. Here, upright means the triangle has one side being horizontal, and the third vertex is above the horizontal side. Later in the text, the term upside-down will appear, meaning the opposite of upright, ie. one side being horizontal but the third vertex is below the horizontal side.

For example, here are some counting triangles (red) and their enclosing triangle (blue). The second counting triangle is upside-down.

Image1

We classify counting triangles by the side length of its enclosing triangle, as this directly related to how many these triangles are there in the original network. If the network has side N, we can find the number of ways