From 10fa701c72c79de41359dcf8478c9933c184b051 Mon Sep 17 00:00:00 2001 From: rzuckerm Date: Thu, 26 Mar 2026 18:18:09 -0500 Subject: [PATCH 1/2] Disable Sleep Sort in Scala --- archive/s/scala/SleepSort.scala | 48 --------------------------------- 1 file changed, 48 deletions(-) delete mode 100644 archive/s/scala/SleepSort.scala diff --git a/archive/s/scala/SleepSort.scala b/archive/s/scala/SleepSort.scala deleted file mode 100644 index 29911efc0..000000000 --- a/archive/s/scala/SleepSort.scala +++ /dev/null @@ -1,48 +0,0 @@ -import scala.collection.mutable.ListBuffer -import scala.concurrent._ -import ExecutionContext.Implicits.global -import scala.concurrent.duration._ - -object SleepSort { - def main(args: Array[String]): Unit = { - var result = invalidChecker(args) - - if(!result){ // After going through checker, it will output result to procede with SleepSort or not - // println(result) - println("Usage: please provide a list of at least two integers to sort in the format \"1, 2, 3, 4, 5\"") - } else { - val numbers = args.flatMap(_.split(",")).map(_.trim).filter(_.nonEmpty).map(_.toInt) - println(sleepSort(numbers)) - } - } - - - // Checking for formating, empty array, and Non-numeric values - def invalidChecker(args: Array[String]): Boolean = args match { - case null | Array() => false // "No Input" - case arr if arr.forall(_.isEmpty) => false //"Empty Input" - case arr if arr.forall(_.length == 1) && arr.length == 1 => false //"Invalid Input: Not A List" - case arr if !arr.exists(_.contains(",")) => false //"Invalid Input: Wrong Format" - case _ => true - } - - // delaying time to add a value to list base on it weight - def sleepSort(args: Array[Int]): String = { - val delayTimer: Long = 100L - val output = new ListBuffer[Int]() - - val futures = args.map { num => - Future { - blocking { - Thread.sleep(num * delayTimer) // Delay execution - } - output.synchronized { - output += num - } - } - }.toList // Convert Array to List to fix type mismatch - - Await.result(Future.sequence(futures), Duration.Inf) // Wait for all futures - output.mkString(", ") // Format output correctly - } -} From 228b142b5398b183a42023ae7c5b9112592eabd6 Mon Sep 17 00:00:00 2001 From: rzuckerm Date: Thu, 26 Mar 2026 18:21:12 -0500 Subject: [PATCH 2/2] Forgot to add files --- .../archive/s/scala/SleepSort.scala | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 needs-attention/archive/s/scala/SleepSort.scala diff --git a/needs-attention/archive/s/scala/SleepSort.scala b/needs-attention/archive/s/scala/SleepSort.scala new file mode 100644 index 000000000..29911efc0 --- /dev/null +++ b/needs-attention/archive/s/scala/SleepSort.scala @@ -0,0 +1,48 @@ +import scala.collection.mutable.ListBuffer +import scala.concurrent._ +import ExecutionContext.Implicits.global +import scala.concurrent.duration._ + +object SleepSort { + def main(args: Array[String]): Unit = { + var result = invalidChecker(args) + + if(!result){ // After going through checker, it will output result to procede with SleepSort or not + // println(result) + println("Usage: please provide a list of at least two integers to sort in the format \"1, 2, 3, 4, 5\"") + } else { + val numbers = args.flatMap(_.split(",")).map(_.trim).filter(_.nonEmpty).map(_.toInt) + println(sleepSort(numbers)) + } + } + + + // Checking for formating, empty array, and Non-numeric values + def invalidChecker(args: Array[String]): Boolean = args match { + case null | Array() => false // "No Input" + case arr if arr.forall(_.isEmpty) => false //"Empty Input" + case arr if arr.forall(_.length == 1) && arr.length == 1 => false //"Invalid Input: Not A List" + case arr if !arr.exists(_.contains(",")) => false //"Invalid Input: Wrong Format" + case _ => true + } + + // delaying time to add a value to list base on it weight + def sleepSort(args: Array[Int]): String = { + val delayTimer: Long = 100L + val output = new ListBuffer[Int]() + + val futures = args.map { num => + Future { + blocking { + Thread.sleep(num * delayTimer) // Delay execution + } + output.synchronized { + output += num + } + } + }.toList // Convert Array to List to fix type mismatch + + Await.result(Future.sequence(futures), Duration.Inf) // Wait for all futures + output.mkString(", ") // Format output correctly + } +}