Skip to content

Instantly share code, notes, and snippets.

@hungyiloo
hungyiloo / aoc-node-data-wrangling.js
Created December 4, 2021 11:14
How to quickly get AoC input data into an array of lines using Node.js
const fs = require('fs');
const data = fs.readFileSync('day-04.input.txt', 'utf8');
const lines = data.split(/\n/);
console.log(lines)

Keybase proof

I hereby claim:

  • I am hungyiloo on github.
  • I am hungyiloo (https://keybase.io/hungyiloo) on keybase.
  • I have a public key ASDksoUEzB0dHnQN72lXtnisoh7hFj9a5tOqiHtD5PR6two

To claim this, I am signing this object:

import websocket
try:
import thread
except ImportError:
import _thread as thread
import time
def on_message(ws, message):
print(message)
@hungyiloo
hungyiloo / ndlist_compare.py
Created February 26, 2018 14:43
Compare N-dimensional lists
def ndlist_compare(fn, x, y):
if type(x) is list and type(y) is list:
return [ndlist_compare(fn, x1, y1) for (x1, y1) in zip(x, y)] # recursion
elif not type(x) is list and not type(y) is list:
return fn(x, y)
else:
raise Exception("x and y are not the same shape")
A = [[1, 2, 3],
[4, [5, 5], 6],
@hungyiloo
hungyiloo / tic_tac_toe_ai.py
Last active December 23, 2017 06:51
Tic-tac-toe AI
import random
def main():
# Decide who goes first
print("You are X. Would you like to go first?")
go_first = choose_first_player()
player = [Board.X, Board.O] if go_first else [Board.O, Board.X]
# Start the game
turn_number = 0