Skip to content

Instantly share code, notes, and snippets.

View jac18281828's full-sized avatar
🦌

John Cairns jac18281828

🦌
View GitHub Profile
@jac18281828
jac18281828 / acmteam.py
Created May 21, 2025 19:11
hackerrank acmTeam
from typing import List, Tuple
def bitstrToInt(bs: str) -> int:
"""Convert bitstring bs to an integer"""
return int(bs, 2)
def countBits(d: int) -> int:
"""Count the bits in d and return that value"""
@jac18281828
jac18281828 / timeinwords.py
Created May 21, 2025 16:37
hacker rank timeInWords
class TimeInWordsError(Exception):
pass
def numberToString(d: int) -> str:
"""Number to string"""
number_look = {
1: "one",
2: "two",
@jac18281828
jac18281828 / queensattackii.ts
Created May 20, 2025 19:47
queens attack hackerrank
const MOVES = [[1, 1], [1, 0], [1, -1], [0, 1], [0, -1], [-1, 1], [-1, 0], [-1, -1]]
function queensAttack(n: number, k: number, r_q: number, c_q: number, obstacles: number[][]): number {
// Write your code here
let spaces = 0
const obstacleSet = new Set(obstacles.map(o => `${o[0]},${o[1]}`))
const isvalidpos = (r: number, c: number) => {
return r > 0 && r <= n && c > 0 && c <= n
@jac18281828
jac18281828 / birds.ts
Created May 20, 2025 19:10
Migratory Birds Hackerrank
function migratoryBirds(arr: number[]): number {
// Write your code here
let birdCount: { [key: number]: number} = {}
let maxId = 0
let maxIdCount = 0
arr.forEach(bid => {
if (birdCount[bid] !== undefined) {
birdCount[bid]++
@jac18281828
jac18281828 / eightqueen.py
Created May 12, 2025 23:01
eight queens problem hacker rank
from typing import Tuple
class InvalidGame(Exception):
def __init__(self, message):
super().__init__(message)
class Board:
"""N x N chessboard"""
@jac18281828
jac18281828 / mergelists.py
Last active May 12, 2025 02:17
Hackerrank Merged two sorted linked lists
import sys
class SinglyLinkedListNode:
def __init__(self, node_data):
self.data = node_data
self.next = None
class SinglyLinkedList:
@jac18281828
jac18281828 / collatzchase.py
Created May 11, 2025 23:44
Collatz Chase a ChatGPT HackerRank prompt
from typing import Tuple
class CollatzChase:
"""
collatz sequence chase
"""
def __init__(self) -> None:
"""initialize"""
@jac18281828
jac18281828 / gridhopper.py
Last active May 11, 2025 21:20
Grid Hopper - Imaginary Hacker Rank from ChatGPT
from collections import deque
from typing import List, Tuple
class Board:
"""
grid hopper
starting at (1,1) must hope either down or right by the amount at grid 1,1
can you reach (size, size)?
answer yes or now
@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)]