Clean up and get ready for two sum assignment

master
Felix Martin 2020-12-12 10:19:24 -05:00
parent e9d0620ab5
commit 99ef6d4d1c
10 changed files with 49 additions and 8 deletions

3
.gitignore vendored
View File

@ -13,3 +13,6 @@ Cargo.lock
# Sublime
algos.sublime-project
algos.sublime-workspace
# Data for the exercises. Some files are big so don't check them in.
data/c2a4.txt

16
misc/birthday_problem.py Normal file
View File

@ -0,0 +1,16 @@
def p_all_different(n):
p = 1
free_days = 365
days_year = 365
for i in range(0, n):
p = p * (free_days / days_year)
free_days -= 1
return p
if __name__ == "__main__":
for i in range(1, 30):
print(f"p_all_different({i})={p_all_different(i)}")
if p_all_different(i) < 0.5:
break

View File

Before

Width:  |  Height:  |  Size: 962 KiB

After

Width:  |  Height:  |  Size: 962 KiB

View File

Before

Width:  |  Height:  |  Size: 674 KiB

After

Width:  |  Height:  |  Size: 674 KiB

View File

Before

Width:  |  Height:  |  Size: 779 KiB

After

Width:  |  Height:  |  Size: 779 KiB

View File

@ -91,9 +91,9 @@ impl<T: std::cmp::PartialOrd> MinHeap<T> {
}
}
pub fn heap(v: &Vec<i32>) -> i32 {
let mut hl: MinHeap<i32> = MinHeap::new();
let mut hh: MinHeap<i32> = MinHeap::new();
pub fn heap(v: &Vec<i64>) -> i64 {
let mut hl: MinHeap<i64> = MinHeap::new();
let mut hh: MinHeap<i64> = MinHeap::new();
let mut iter = v.into_iter();
let mut current_median = *iter.next().unwrap();

View File

@ -5,15 +5,16 @@ mod min_cut;
mod quick_sort;
mod ssc;
mod util;
mod two_sum;
use std::cmp::min;
use crate::dijkstra::dijkstra;
use crate::heap::heap;
use crate::merge_sort::merge_sort_inversions;
use crate::min_cut::min_cut;
use crate::quick_sort::quick_sort;
use crate::ssc::ssc;
use crate::two_sum::find_two_sums;
#[allow(dead_code)]
fn c1a2() {
@ -70,16 +71,24 @@ fn c2a2() {
#[allow(dead_code)]
fn c2a3() {
let vec = util::read_to_vector("data/c2a3.txt").unwrap();
let r = heap(&vec);
let v = util::read_to_vector("data/c2a3.txt").unwrap();
let r = heap(&v);
println!("c2a3={:?}", r);
}
#[allow(dead_code)]
fn c2a4() {
let v = util::read_to_vector("data/c2a4.txt").unwrap();
let r = find_two_sums(v);
println!("c2a4={:?}", r);
}
fn main() {
// c1a2();
// c1a3();
// c1a4();
// c2a1();
// c2a2();
c2a3();
// c2a3();
c2a4();
}

13
src/two_sum.rs Normal file
View File

@ -0,0 +1,13 @@
fn two_sum(t: i64, xs_vec: &Vec<i64>) {
}
pub fn find_two_sums(xs: Vec<i64>) -> usize {
0
}

View File

@ -23,7 +23,7 @@ pub struct DirectedWeightedGraph {
pub distance: Vec<usize>,
}
pub fn read_to_vector(path: &str) -> Result<Vec<i32>, io::Error> {
pub fn read_to_vector(path: &str) -> Result<Vec<i64>, io::Error> {
let file = File::open(path)?;
let br = BufReader::new(file);
let mut v = Vec::new();