names => exponents
init
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | Cargo.toml | 13 | ||||
| -rw-r--r-- | LICENSE | 21 | ||||
| -rw-r--r-- | README.md | 7 | ||||
| -rw-r--r-- | src/main.rs | 41 |
5 files changed, 83 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ffa3bbd --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +Cargo.lock
\ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..fbe8462 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "beeg" +version = "0.1.0" +edition = "2021" +license = "MIT" +description = "easy big number conversion" +repository = "https://github.com/bend-n/beeg" +authors = ["bendn <[email protected]>"] + +[dependencies] +comat = "0.1.3" +phf = { version = "0.11.2", features = ["macros"] } +regex = "1.10.3" @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 bendn + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..fcaa592 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# beeg number conversion + +ever been confused when somebody says `1 vigintillion` and you have no idea how many zeroes there are? +```bash +$ beeg 1 vigintillion +1e+63 +```
\ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..c65fa7c --- /dev/null +++ b/src/main.rs @@ -0,0 +1,41 @@ +use std::process::ExitCode; + +static TAB: phf::Map<&str, u16> = phf::phf_map! { + "m" => 6, + "b" => 9, + "tr" => 12, + "quad" => 15, + "quint" => 18, + "sext" => 21, + "sept" => 24, + "oct" => 27, + "non" => 30, + "dec" => 33, + "undec" => 36, + "duodec" => 39, + "tredec" => 42, + "quattourdec" => 45, + "quindec" => 48, + "sexdec" => 51, + "septendec" => 54, + "octodec" => 57, + "novemdec" => 60, + "vigint" => 63, + "cent" => 303, +}; + +fn main() -> ExitCode { + let re = regex::Regex::new(r"([0-9]+(?:\.[0-9]+)?)[^\S]*(m|b|tr|quad|quint|sext|sept|oct|non|dec|undec|duodec|tredec|quattourdec|quindec|sexdec|septendec|octodecc|novemdec|vigint|cent)illion").unwrap(); + let Some(x) = std::env::args().skip(1).reduce(|acc, x| acc + &x) else { + comat::cprintln!("{red}require argument{reset}"); + return ExitCode::FAILURE; + }; + + let Some(mat) = re.captures(&x) else { + comat::cprintln!("{red}wher num?{reset}"); + return ExitCode::SUCCESS; + }; + let exponent = TAB[mat.get(2).unwrap().into()]; + println!("{}e+{exponent}", mat.get(1).unwrap().as_str()); + ExitCode::SUCCESS +} |