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
const kaaten = document.createElement('div'); | |
kaaten.style = 'display: none; position: fixed; inset: 0; background: black; z-index: 2147483647;'; | |
document.body.append(kaaten); | |
let kaatenOn = false; | |
function orosu(e) { | |
if (e.ctrlKey && e.shiftKey && e.key === 'B') { | |
kaaten.style.display = kaatenOn ? 'none' : 'block'; |
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
// Without using a library... | |
pub fn nth(n: u32) -> u32 { | |
let mut primes = vec![2, 3, 5, 7]; | |
if n == 0 || n == 1 || n == 2 || n == 3 { | |
return primes[n as usize]; | |
} | |
let mut count = 3; | |
let mut potential = 11; | |
while count != n { |
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
#[derive(Debug, PartialEq)] | |
pub enum Comparison { | |
Equal, | |
Sublist, | |
Superlist, | |
Unequal, | |
} | |
pub fn sublist<T: PartialEq>(_first_list: &[T], _second_list: &[T]) -> Comparison { | |
let len1 = _first_list.len(); |
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
type NestedVec = Vec<Elt>; | |
#[derive(Debug)] | |
enum Elt { | |
Num(i32), | |
Nest(NestedVec), | |
} | |
fn main() { | |
let array = vec![Elt::Num(1), Elt::Nest(vec![Elt::Num(2), Elt::Num(3)])]; |
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
// The code below is a stub. Just enough to satisfy the compiler. | |
// In order to pass the tests you can add-to or change any of this code. | |
#[derive(Debug)] | |
pub struct Duration { | |
seconds: f64, | |
} | |
impl From<u64> for Duration { | |
fn from(s: u64) -> Self { |
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::collections::HashSet; | |
fn main() { | |
// let mut hs = HashSet::new(); | |
let hello = "hello"; | |
let mut v: Vec<char> = hello.chars().collect(); | |
println!("{:?}", v); | |
let index = v.iter().position(|x| *x == 'l').unwrap(); |
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; | |
#[derive(Debug, PartialEq)] | |
pub struct Clock { | |
hours: i32, | |
minutes: i32, | |
} | |
fn convert_minutes_to_time(time_in_minutes: i32) -> Clock { | |
let mut actual_hours = 0; |
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::collections::HashSet; | |
pub fn anagrams_for<'a>(word: &str, possible_anagrams: &[&'a str]) -> HashSet<&'a str> { | |
let mut output: HashSet<&'a str> = HashSet::new(); | |
for anagram in possible_anagrams { | |
if check_length(word, anagram) && word.to_lowercase() != anagram.to_lowercase() { | |
let mut split_word: Vec<char> = word.to_lowercase().chars().collect(); | |
for c in anagram.to_lowercase().chars() { | |
if split_word.iter().any(|&i| i == c) { |
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::collections::HashMap; | |
fn main() { | |
let mut hm = HashMap::new(); | |
hm.insert("a", 1); | |
hm.insert("b", 1); | |
hm.insert("c", 1); | |
println!("Before:"); | |
for (key, val) in hm.iter() { |