This commit is contained in:
Sangeeth Sudheer 2022-08-16 01:03:04 +05:30
commit 1f75203146
3 changed files with 127 additions and 0 deletions

94
.gitignore vendored Normal file
View File

@ -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

8
gcd/Cargo.toml Normal file
View File

@ -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]

25
gcd/src/main.rs Normal file
View File

@ -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));
}