Skip to content

Instantly share code, notes, and snippets.

View nolenroyalty's full-sized avatar

nolen (eieio) nolenroyalty

View GitHub Profile
@nolenroyalty
nolenroyalty / go-to-sleep.sh
Last active January 2, 2025 21:09
A script I run via cron that prompts me to sleep at night
#!/usr/bin/env bash -x
# TO USE:
# 1. MAKE A CONFIG FILE AT ~/.go-to-bed
# it should look like this (don't include hashes in file, this will nag you starting at 12:16 AM until 6:00 AM)
# START_TIME:0.16
# END_TIME:6.0
# HUSHED_UNTIL:2023-11-23T1:40:00
#
# 2. SAVE THIS SCRIPT SOMEWHERE, maybe ~/bin/go-to-bed
@nolenroyalty
nolenroyalty / queen_problem.py
Created July 17, 2012 10:16
Solving the N-Queen problem
def get_candidate_boards(board):
boards = []
queen_locations = [(x, y) for x in range(len(board)) for y in range(len(board)) if board[x][y] == "Q"]
left_diagonals = [(x-y, 0) for (x, y) in queen_locations]
right_diagonals = [(x+y, 0) for (x, y) in queen_locations]
for x, y in ((x, y) for x in range(len(board)) for y in range(len(board)) if board[x][y] != "Q"):
temp_board = board[:x] + [board[x][:y] + ["Q"] + board[x][y+1:]] + board[x+1:]
valid_cols = all(col.count("Q") < 2 for col in temp_board)
valid_rows = all(row.count("Q") < 2 for row in zip(*temp_board))