View list_deepcopy.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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
typedef struct node { | |
int val; | |
struct node *next; | |
struct node *random; | |
} node; |
View longestword.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
#include <stdio.h> | |
int count_letters(char *str, char *word) { | |
char c; | |
int letters = 0; | |
while ((c = *str++) && *word) { | |
if (c == *word) { | |
letters++; | |
word++; |
View longtext.py
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 argparse | |
import shutil | |
import subprocess | |
def main(): | |
parser = argparse.ArgumentParser(description="Multiplies the vowels.") | |
parser.add_argument("string", metavar="STRING", type=str, help="a string") | |
parser.add_argument("n", metavar="N", type=int, help="an integer") | |
parser.add_argument( |
View coin_combo.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
#include <limits.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#define DEBUG 0 | |
#define IMPOSSIBLE (INT_MAX >> 1) | |
int main(int argc, char **argv) { | |
int num_coins, amount; |
View main.rs
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::env; | |
use std::ops::RangeInclusive; | |
trait RangeInclusiveExt { | |
fn len(&self) -> usize; | |
} | |
impl RangeInclusiveExt for RangeInclusive<usize> { | |
fn len(&self) -> usize { | |
*self.end() - *self.start() + 1 |
View case_permutations.rs
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
pub fn case_permutations(s: String) -> Vec<String> { | |
let mut stack: Vec<String> = vec![String::with_capacity(s.capacity())]; | |
for c in s.chars() { | |
if c.is_ascii_alphabetic() { | |
let mut new_stack: Vec<String> = vec![]; | |
for p in stack { | |
let mut lower = p.clone(); | |
lower.push(c.to_ascii_lowercase()); | |
new_stack.push(lower); |
View phone_letter.rs
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
#![allow(unused)] | |
extern crate itertools; | |
use itertools::Itertools; | |
fn phone_letter(number: &str) -> Vec<String> { | |
number | |
.chars() | |
.filter_map(|digit| match digit { | |
'2' => Some(vec!['a', 'b', 'c']), |
View group_anagrams.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
#include <stdio.h> | |
#include <stdlib.h> | |
static int FACTORS[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, | |
43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101}; | |
struct map_entry { | |
int sort_key; | |
int arg_index; | |
}; |
View scan_secrets.js
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 fs = require("fs"); | |
const parser = require("@babel/parser"); | |
const traverse = require("@babel/traverse").default; | |
PATTERNS = [ | |
/BEGIN ((EC|PGP|DSA|RSA|OPENSSH) )?PRIVATE KEY/, | |
/AIza[A-Za-z0-9_-]{35}/, | |
/sk_live_[A-Za-z0-9]{24}/, | |
]; |
View peaks.rs
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
#![allow(unused)] | |
fn peaks<T: std::cmp::PartialOrd>(values: Vec<T>) -> Vec<usize> { | |
values | |
.windows(3) | |
.enumerate() | |
.filter_map(|(i, window)| { | |
if window[0] < window[1] && window[1] > window[2] { | |
Some(i + 1) | |
} else { |
NewerOlder