From 08096ad94c208e3d97ebd1c5b966b2e207ae20d3 Mon Sep 17 00:00:00 2001 From: LailaTheElf Date: Fri, 22 Aug 2025 16:32:55 +0200 Subject: [PATCH] inital commit --- .gitignore | 1 + Cargo.lock | 25 +++++++++++++++++ Cargo.toml | 7 +++++ plot.svg | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 27 +++++++++++++++++++ 5 files changed, 137 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 plot.svg create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..ff91c27 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,25 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "birthday_colision" +version = "0.1.0" +dependencies = [ + "poloto", +] + +[[package]] +name = "poloto" +version = "19.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "164dbd541c9832e92fa34452e9c2e98b515a548a3f8549fb2402fe1cd5e46b96" +dependencies = [ + "tagu", +] + +[[package]] +name = "tagu" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eddb6b06d20fba9ed21fca3d696ee1b6e870bca0bcf9fa2971f6ae2436de576a" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..d2880eb --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "birthday_colision" +version = "0.1.0" +edition = "2024" + +[dependencies] +poloto = "19.1.2" diff --git a/plot.svg b/plot.svg new file mode 100644 index 0000000..594201b --- /dev/null +++ b/plot.svg @@ -0,0 +1,77 @@ + + + + + + + birthday colision + group size + change + + 0.2 + 0.4 + 0.6 + 0.8 + + + + + + + + + 10 + 20 + 30 + 40 + 50 + 60 + 70 + + + + + + + + + + + + + diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..1449e4f --- /dev/null +++ b/src/main.rs @@ -0,0 +1,27 @@ + +use poloto; + +fn get_next(last: f64, step: u16) -> f64 { + let c: f64 = f64::from(step - 1) / 365f64; + c * (1.0-last) + last +} + +fn main() { + let mut i: u16 = 2; + let mut chance: f64 = 0.0; + let mut chances: Vec<[f64; 2]> = Vec::new(); + while i <= 70 { + chance = get_next(chance, i); + chances.push([f64::from(i), chance]); + println!("{}: {}", i, chance); + i += 1; + } + + let plot = poloto::build::plot("").line(chances); + let file = std::fs::File::create("./plot.svg").unwrap(); + let _ = poloto::frame_build() + .data(plot) + .build_and_label(("birthday colision", "group size", "change")) + .append_to(poloto::header().dark_theme()) + .render_io_write(file); +}