This file contains hidden or 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
| //! https://projecteuler.net/problem=11 | |
| // In the 20×20 grid below, four numbers along a diagonal line have been marked in red. | |
| // 08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08 | |
| // 49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00 | |
| // 81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65 | |
| // 52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91 | |
| // 22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80 | |
| // 24 47 32 60 99 03 45 02 44 75 33 53 78 36 84 20 35 17 12 50 |
This file contains hidden or 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 tokio::time::{self, Duration}; | |
| use tokio::sync::Mutex; | |
| use std::sync::Arc; | |
| type FooFn = dyn Fn(u32) -> u32 + Send; | |
| #[tokio::main] | |
| async fn main() { | |
| let foo: Arc<Mutex<Option<Box<FooFn>>>> = Arc::new(Mutex::new(None)); |
This file contains hidden or 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::io::prelude::*; | |
| use std::io::{self, BufReader}; | |
| use std::fs::File; | |
| use std::error::Error; | |
| use std::path::Path; | |
| use std::collections::HashMap; | |
| /// Map describing which words have a character at a given index | |
| /// { letter: { letter_position: Vec<word_id> } } | |
| /// e.g. {'a': {0: [1]}} means "word 1 has an 'a' at position 0" |
This file contains hidden or 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
| from collections import defaultdict | |
| words_dict = defaultdict(lambda: defaultdict(list)) | |
| # load words | |
| with open('words.txt') as f: | |
| words = [line.rstrip() for line in f] | |
| # build a dict of keys of letter positions, and the letters | |
| # and their parent word: {pos: {letter: [word_index*]}} |
This file contains hidden or 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 cardinal_suffix(x: i64) -> &'static str { | |
| let last_digit = x % 10; | |
| let second_last_digit = x % 100 / 10; | |
| match (second_last_digit, last_digit) { | |
| (1, 1) => "th", // eleventh | |
| (_, 1) => "st", // first | |
| (1, 2) => "th", // twelfth | |
| (_, 2) => "nd", // second |
This file contains hidden or 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::ops::Range; | |
| #[derive(Debug)] | |
| pub struct Person { | |
| name: String, | |
| age: u64, | |
| } | |
| impl Person { | |
| fn new(name: String, age: u64) -> Person { |
This file contains hidden or 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
| trait ParseNext { | |
| fn parse_next<T: FromStr>(&mut self) -> T; | |
| } | |
| impl<'a, I: Iterator<Item=&'a str>> ParseNext for I { | |
| fn parse_next<T: FromStr>(&mut self) -> T { | |
| self.next().unwrap().parse().unwrap() | |
| } | |
| } |
This file contains hidden or 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::sync::mpsc::{channel, Sender, Receiver}; | |
| use std::thread::{self, JoinHandle}; | |
| #[derive(Debug, Clone, Copy, Eq, PartialEq)] | |
| enum Event { | |
| Wait, | |
| Work, | |
| Done, | |
| } |
This file contains hidden or 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
| #[derive(Debug)] | |
| struct StateMachine<S> { | |
| string: String, | |
| state: S, | |
| } | |
| #[derive(Debug)] | |
| struct Start; | |
| impl StateMachine<Start> { |
This file contains hidden or 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
| mod worker; | |
| use worker::Worker; | |
| fn main() { | |
| let worker = Worker::new() | |
| .initialize() | |
| .do_work() | |
| .reset(); | |
| println!("{:?}", worker); |