From 94e83c042bf65b0c8d67443c4aae4c366bb32255 Mon Sep 17 00:00:00 2001 From: Hyperling Date: Sat, 30 Mar 2024 12:18:46 -0700 Subject: [PATCH 1/2] Add files for Kotlin. Both are working successfully. --- .gitignore | 1 + README.md | 2 +- kotlin_compiled.sh | 15 +++++++++++++ kotlin_scripted.sh | 10 +++++++++ spare_change.kt | 54 ++++++++++++++++++++++++++++++++++++++++++++++ spare_change.kts | 51 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 .gitignore mode change 100644 => 100755 README.md create mode 100755 kotlin_compiled.sh create mode 100755 kotlin_scripted.sh create mode 100755 spare_change.kt create mode 100755 spare_change.kts diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d392f0e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.jar diff --git a/README.md b/README.md old mode 100644 new mode 100755 index c1994de..dd2ab47 --- a/README.md +++ b/README.md @@ -14,10 +14,10 @@ Project only takes into consideration the USA's cent system. Completed: - PHP +- Kotlin Planned: -- Kotlin - Bash - Python - Node.js diff --git a/kotlin_compiled.sh b/kotlin_compiled.sh new file mode 100755 index 0000000..000a448 --- /dev/null +++ b/kotlin_compiled.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +# 2024-03-30 Hyperling +# Compile the .kt file and run the compiled binary. + +# Move to the file location. +DIR="$(dirname -- "${BASH_SOURCE[0]}")" +cd $DIR + +# Compile the script. +kotlinc spare_change.kt -include-runtime -d spare_change.kt.jar + +# Run the executable. +chmod 755 ./spare_change.kt.jar +java -jar spare_change.kt.jar +rm -rfv ./spare_change.kt.jar diff --git a/kotlin_scripted.sh b/kotlin_scripted.sh new file mode 100755 index 0000000..6075a5e --- /dev/null +++ b/kotlin_scripted.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +# 2024-03-30 Hyperling +# Run the program as a shell language. + +# Move to the file location. +DIR="$(dirname -- "${BASH_SOURCE[0]}")" +cd $DIR + +# Run the program. +kotlinc -script ./spare_change.kts diff --git a/spare_change.kt b/spare_change.kt new file mode 100755 index 0000000..428211b --- /dev/null +++ b/spare_change.kt @@ -0,0 +1,54 @@ +/* +// 2024-03-30 Hyperling +// Creating a Kotlin version which needs compiled then run. +*/ + +fun main() { + var pennies: Int + var nickels: Int + var dimes: Int + var quarters: Int + var maxPennies: Int = 0 + var maxNickels: Int = 0 + var maxDimes: Int = 0 + var maxQuarters: Int = 0 + + println("Got any spare change?") + + for (change in 1..99) { + quarters = change / 25 + var remainder = change % 25 + + dimes = remainder / 10 + remainder = remainder % 10 + + nickels = remainder / 5 + remainder = remainder % 5 + + pennies = remainder / 1 + + if (quarters > maxQuarters) { + maxQuarters = quarters + println("Change ${change}c required $maxQuarters quarter(s).") + } + + if (dimes > maxDimes) { + maxDimes = dimes + println("Change ${change}c required $maxDimes dime(s).") + } + + if (nickels > maxNickels) { + maxNickels = nickels + println("Change ${change}c required $maxNickels nickel(s).") + } + + if (pennies > maxPennies) { + maxPennies = pennies + println("Change ${change}c required $maxPennies penny(ies).") + } + } + + print("The optimum amount is $maxQuarters quarter(s), $maxDimes dime(s)") + println(", $maxNickels nickel(s), and $maxPennies pennies.") + +} diff --git a/spare_change.kts b/spare_change.kts new file mode 100755 index 0000000..89e6229 --- /dev/null +++ b/spare_change.kts @@ -0,0 +1,51 @@ +/* +// 2024-03-30 Hyperling +// Creating a Kotlin version which can be run via command line. +*/ + +var pennies = 0 +var nickels = 0 +var dimes = 0 +var quarters = 0 +var maxPennies = 0 +var maxNickels = 0 +var maxDimes = 0 +var maxQuarters = 0 + +println("Got any spare change?") + +for (change in 1..99) { + quarters = change / 25 + var remainder = change % 25 + + dimes = remainder / 10 + remainder = remainder % 10 + + nickels = remainder / 5 + remainder = remainder % 5 + + pennies = remainder / 1 + + if (quarters > maxQuarters) { + maxQuarters = quarters + println("Change ${change}c required $maxQuarters quarter(s).") + } + + if (dimes > maxDimes) { + maxDimes = dimes + println("Change ${change}c required $maxDimes dime(s).") + } + + if (nickels > maxNickels) { + maxNickels = nickels + println("Change ${change}c required $maxNickels nickel(s).") + } + + if (pennies > maxPennies) { + maxPennies = pennies + println("Change ${change}c required $maxPennies penny(ies).") + } +} + +print("The optimum amount is $maxQuarters quarter(s), $maxDimes dime(s)") +println(", $maxNickels nickel(s), and $maxPennies pennies.") From 0e384c7a454af194b6259b33eb22aa79ab38cb5a Mon Sep 17 00:00:00 2001 From: Hyperling Date: Sat, 30 Mar 2024 12:19:21 -0700 Subject: [PATCH 2/2] Use underscore, dash was for Termux. --- spare-change.php => spare_change.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename spare-change.php => spare_change.php (100%) diff --git a/spare-change.php b/spare_change.php similarity index 100% rename from spare-change.php rename to spare_change.php