This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::fmt::Debug; | |
pub trait State: Debug { | |
fn execute(&self) -> Transition; | |
} | |
pub trait TransitionTo<S: State + 'static>: State { | |
fn transition_to(&self, to: &'static S) -> Transition { | |
Transition { to } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Print the number of bytes unread in a fifo. | |
# David Coles <coles.david@gmail.com> | |
import argparse | |
import ctypes | |
import fcntl | |
import os | |
import sys | |
import termios |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# POSIX Alarm Timer example using Python ctypes | |
# | |
# Author: David Coles <coles.david@gmail.com> | |
# Date: 2012-03-19 | |
# | |
# To the extent possible under law, the author(s) have dedicated all copyright | |
# and related and neighboring rights to this software to the public domain | |
# worldwide. This software is distributed without any warranty. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let input = read_input_from_file("day01/input.txt").unwrap(); | |
// Part 1 | |
let mut count = 0; | |
let mut last = -1; | |
for &n in &input { | |
if n > last { | |
count += 1; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
By only adding + - * into the string 452874 (in that order), | |
how many way can you get to -18? | |
""" | |
N = "452874" | |
M = -18 | |
OPERATIONS = [None, '+', '-', '*'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ctypes | |
import sys | |
import os | |
import errno | |
FUNC = ctypes.CFUNCTYPE(None) | |
PROT_NONE = 0 | |
PROT_READ = 1 | |
PROT_WRITE = 2 |
OlderNewer