Skip to content

Instantly share code, notes, and snippets.

View jac18281828's full-sized avatar
🦌

John Cairns jac18281828

🦌
View GitHub Profile
@jac18281828
jac18281828 / knitsonboard.py
Created May 8, 2025 19:26
hackerrank knights on a chessboard
""" we are the knits of the round table ... """
from typing import Tuple
class ChessBoard:
"""
simple hackerrank style chessboard game with mulitple knights
- approach use Sprague Grundy Theorem to determine the winner of a
@jac18281828
jac18281828 / chessboard.py
Created May 8, 2025 00:43
a chessboard game - hacker rank
class Board:
"""
given a coin a position
determine if it is a winner or a loser
"""
N=15
MOVES = [(-2, +1), (-2, -1), (+1, -2), (-1, -2)]
def __init__(self):
self.grundy = [[-1 for _ in range(self.N + 1)] for _ in range(self.N + 1)]
@jac18281828
jac18281828 / nim_n_pile.py
Last active May 8, 2025 00:14
Multi-Pile Nim Solution
"""nim for several piles"""
def calculate_mex(s):
"""minimum excludant"""
mex = 0
while mex in s:
mex += 1
return mex
@jac18281828
jac18281828 / superdigit.py
Created May 7, 2025 00:07
Super Digit Hackerrank
def superdigit(n: str, k: int):
p = n * k
lp = list(p)
psum = sum([ int(d) for d in lp ])
if psum < 10:
return psum
return superdigit(str(psum), 1)
if __name__ == '__main__':
maxidigit = '9875'
@jac18281828
jac18281828 / ccypher.py
Last active May 6, 2025 22:59
Caesar Cipher Hacker Rank
alpha_wheel = [c for c in "abcdefghijklmnopqrstuvwxyz"]
def rotate_wheel(wheel, n):
"""Rotate the wheel by n positions."""
n = n % len(wheel) # Normalize the rotation
return wheel[n:] + wheel[:n]
def caesarcipher(text: str, n: int) -> str:
@jac18281828
jac18281828 / knightl.py
Last active May 8, 2025 19:51
KnightL optimal BFS approach
from collections import deque
from typing import Tuple
class ChessBoardFindError(Exception):
"""error on failure"""
pass
@jac18281828
jac18281828 / tokens.yaml
Created April 9, 2025 19:13
Two get tokens
- blockchain: MegaETH
network: megaeth-testnet
name: Wrapped Ether
symbol: WETH
address: "0x776401b9bc8aae31a685731b7147d4445fd9fb19"
decimals: 18
atom: 1000000000000000000
- blockchain: MegaETH
network: megaeth-testnet
name: AWE
@jac18281828
jac18281828 / GTELauncher.sol
Last active April 9, 2025 17:01
GTERouter.sol – what I know so far
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
interface GTELauncher {
function BASE_SCALING() external view returns (uint256);
function BONDING_SUPPLY() external view returns (uint256);
function LAUNCH_FEE() external view returns (uint256);
function QUOTE_SCALING() external view returns (uint256);
function TOTAL_SUPPLY() external view returns (uint256);
function bondingCurve() external view returns (address);
@jac18281828
jac18281828 / Dockerfile
Created April 2, 2025 15:37
Dockerimage to build a Python 3.11.9 optimized binary using manual build and compilation
# Stage 1: Build yamlfmt
FROM golang:1 AS go-builder
# defined from build kit
# DOCKER_BUILDKIT=1 docker build . -t ...
ARG TARGETARCH
# Install yamlfmt
WORKDIR /yamlfmt
RUN go install github.com/google/yamlfmt/cmd/[email protected] && \
strip $(which yamlfmt) && \
@jac18281828
jac18281828 / jinja_perf.py
Created March 13, 2025 15:51
Jinja performance test
""" simple jinja performance sanity check """
from jinja2 import Template
import time
query = """
-- fetch token from db
-- param
-- 1: user_id