Skip to content

Instantly share code, notes, and snippets.

@TheCreatorAMA
TheCreatorAMA / match.c
Last active January 15, 2025 17:10 — forked from ianmackinnon/match.c
C Regex multiple matches and groups example (with explanation)
#include <errno.h>
#include <regex.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
* Advent of Code 2024 Day 3 Part 1
*/
@TheCreatorAMA
TheCreatorAMA / main.rs
Created August 23, 2022 16:05
Rust chapter 8 exercise, add employee names to a department in a company (hashmaps and vectors)
use std::collections::HashMap;
use itertools::Itertools;
use std::io;
fn main() {
// command must be in format of "add <name> to <department>" or "get <department>". Command
// must start with add or get. For the "get" command, "get all" will get all employees from
// each department sorted in alphabetical order by department.
let mut employee_data = HashMap::new();
@TheCreatorAMA
TheCreatorAMA / main.rs
Created August 19, 2022 14:57
Rust convert string to pig latin(Rust lang book chapter 8 exercise)
fn main() {
let normal_str = String::from("first apple");
let pig_latin = convert_to_pig_latin(&normal_str);
println!("Input: {}\nOutput: {}", normal_str, pig_latin);
}
fn convert_to_pig_latin(input_str: &String) -> String {
let mut str_array = vec![];
@TheCreatorAMA
TheCreatorAMA / main.rs
Last active August 18, 2022 18:06
Finding Mean, Median and Mode in Rust (chapter 8 exercise from rust-lang book)
use std::collections::HashMap;
fn main() {
let mut x: Vec<i32> = vec![6,3,2,2,5,7,9,9,8,6,4,10,11,11,11,11,12,13,14];
println!("Inputted vector: {:?}", x);
println!("Mean: {}", mean(&x));
println!("Median: {}", median(&mut x));
let y = mode(&x);
println!("Mode: value {} occurs {} times", y.0, y.1);
}