commit 1f752031463d51fbedbf00f2a7a4ea3739702724 Author: Sangeeth Sudheer Date: Tue Aug 16 01:03:04 2022 +0530 gcd p1 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d9e883f --- /dev/null +++ b/.gitignore @@ -0,0 +1,94 @@ +# Created by https://www.toptal.com/developers/gitignore/api/rust,windows,linux,macos +# Edit at https://www.toptal.com/developers/gitignore?templates=rust,windows,linux,macos + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### macOS Patch ### +# iCloud generated files +*.icloud + +### Rust ### +# Generated by Cargo +# will have compiled files and executables +debug/ +target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information +*.pdb + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# End of https://www.toptal.com/developers/gitignore/api/rust,windows,linux,macos +n \ No newline at end of file diff --git a/gcd/Cargo.toml b/gcd/Cargo.toml new file mode 100644 index 0000000..5ae5c4d --- /dev/null +++ b/gcd/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "gcd" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/gcd/src/main.rs b/gcd/src/main.rs new file mode 100644 index 0000000..5a323aa --- /dev/null +++ b/gcd/src/main.rs @@ -0,0 +1,25 @@ +fn gcd(mut a: u64, mut b: u64) -> u64 { + while a > 0 { + if a < b { + let temp = b; + b = a; + a = temp; + } + + a = a % b + } + b +} + +#[test] +fn test_gcd() { + assert_eq!(gcd(3, 7), 1); + assert_eq!(gcd(16, 128), 16); +} + +fn main() { + println!("gcd(4, 6) is {}", gcd(4, 6)); + println!("gcd(7, 49) is {}", gcd(7, 49)); + println!("gcd(3, 7) is {}", gcd(3, 7)); + println!("gcd(128, 16) is {}", gcd(128, 16)); +}