Skip to content

Instantly share code, notes, and snippets.

@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))
@nolenroyalty
nolenroyalty / go-to-sleep.sh
Created November 23, 2023 05:47
A script I run via cron that prompts me to sleep at night
#!/usr/bin/env bash -x
# config file looks like
#START_TIME:0.16
#END_TIME:6.0
#HUSHED_UNTIL:2023-11-23T1:40:00
if [ "$1" = "-from-cron" ]
then
if ps aux | grep osascript | grep -q 'Time to Sleep'