Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Jason Huang Pagliacii

🎯
Focusing
View GitHub Profile
@Pagliacii
Pagliacii / game.py
Last active Nov 7, 2021
An easy action adventure game based on text.
View game.py
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
"""An easy action adventure game based on text."""
import random
import time
import uuid
from typing import Dict, Generator, List, Protocol
@Pagliacii
Pagliacii / query.py
Created Oct 24, 2021
Query IP location based on QQWry.dat file
View query.py
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import mmap
import struct
import socket
import pathlib
from typing import Tuple
@Pagliacii
Pagliacii / 24-game.py
Last active Oct 24, 2021
Solutions to the 24 Game
View 24-game.py
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import itertools
from typing import Optional
from expression import Expr
from fraction import Frac
@Pagliacii
Pagliacii / number.py
Last active Sep 23, 2021
A Number class
View number.py
#!/usr/bin/env python3
# _*_ coding:utf-8 _*_
import re
def str_to_int(s: str) -> int:
if not s:
return 0
i = ord(s[0]) - ord("0")
@Pagliacii
Pagliacii / stream.py
Last active Oct 24, 2021
Representing a stream in Python. The idea is came from the MIT 6.001 Lec6B.
View stream.py
#!/usr/bin/env python3
def cons_stream(head, tail):
return (head, delay(tail))
def head(s):
return s[0]
@Pagliacii
Pagliacii / value.rs
Last active Oct 24, 2021
Performing procedures dynamically
View value.rs
use std::collections::HashMap;
use std::fmt;
use std::ops::Add;
use std::sync::Arc;
struct Procedure {
name: String,
inner_proc: Arc<dyn Fn(Vec<Value>) -> Value>,
}
View vigenere_cipher.py
#!/usr/bin/env python
import string
import textwrap
import functools
def filter_not_upper(text: str) -> str:
return "".join(filter(lambda c: c in string.ascii_uppercase, text))
@Pagliacii
Pagliacii / father-puzzle.pl
Created Jun 2, 2021
Who is Lorna’s father? Use Prolog to solve a logic puzzle.
View father-puzzle.pl
/* Who is Lorna's father?
*
* Mary Ann Moore’s father has a yacht and so has each of his four friends: Colonel Downing, Mr. Hall, Sir Barnacle Hood, and Dr. Parker.
* 1. Each of the five also has one daughter and each has named his yacht after a daughter of one of the others.
* 2. Sir Barnacle’s yacht is the Gabrielle.
* 3. Mr. Moore owns the Lorna.
* 4. Mr. Hall the Rosalind.
* 5. The Melissa, owned by Colonel Downing, is named after Sir Barnacle’s daughter.
* 6. Gabrielle’s father owns the yacht that is named after Dr. Parker’s daughter.
*/
@Pagliacii
Pagliacii / liars-puzzle.pl
Last active Jun 2, 2021
Solve the following “Liars” puzzle from The Sphinx Problem Book by Phillips Hubert in 1934.
View liars-puzzle.pl
/* What in fact was the order in which the five girls were placed?
*
* Five schoolgirls sat for an examination. Their parents--so they thought--showed an undue degree of interest
* in the result. They therefore agreed that, in writing home about the examination, each girl should make one
* true statement and one untrue one. The following are the relevant passages from their letters:
*
* 1. Betty: "Kitty was second in the examination. I was only third."
* 2. Ethel: "You'll be glad to hear that I was on top. Joan was 2nd."
* 3. Joan: "I was third, and poor old Ethel was bottom."
* 4. Kitty: I came out second. Mary was only fourth."
@Pagliacii
Pagliacii / floors_puzzle.pl
Created Jun 1, 2021
The following puzzle takes from Dinesman's Superior Mathematical Puzzles in 1968.
View floors_puzzle.pl
/* Where does everyone live?
*
* 1. Baker, Cooper, Fletcher, Miller, and Smith live on different floors of an apartment house that contains only five floors.
* 2. Baker does not live on the top floor.
* 3. Cooper does not live on the bottom floor.
* 4. Fletcher does not live on either the top or the bottom floor.
* 5. Miller lives on a higher floor than does Cooper.
* 6. Smith does not live on a floor adjacent to Fletcher's.
* 7. Fletcher does not live on a floor adjacent to Cooper's.
*/