Skip to content

Instantly share code, notes, and snippets.

View ASRagab's full-sized avatar
👨‍💻

Ahmad Ragab ASRagab

👨‍💻
View GitHub Profile
@ASRagab
ASRagab / nQueens.scala
Created July 29, 2018 19:07
Brute Force nQueens
object nQueens extends App {
type Solution = IndexedSeq[Int]
def createSolutions(n: Int): Seq[Solution] = {
(0 until n).permutations.toSeq
}
def verifySolution(s: Solution): Boolean = {
s.indices.combinations(2).forall(x => Math.abs(x(0) - x(1)) != Math.abs(s(x(0)) - s(x(1))))
}
Date CaloriesBurned Steps Distance(km) Stairs MinutesAtRest MinutesOfLightActivity MinutesOfModerateActivity MinutesOfIntenseActivity CaloriesBurnedWhileActive MinutesOfSleep MinutesOfBeingAwake NumberOfAwakenings LengthOfRestInMinutes
04/28/2016 4030 25571 19.3 15 606 293 42 129 2711 348 20 9 368
04/29/2016 3442 17528 13.36 15 594 239 8 82 1931 454 48 27 502
04/30/2016 3061 9831 7.3 1 561 414 0 0 1651 347 41 20 388
05/01/2016 3331 14262 10.6 5 666 361 21 41 1937 314 34 23 348
05/02/2016 2989 13236 9.98 12 770 234 8 38 1477 377 33 18 410
05/03/2016 3796 18588 14.13 16 599 275 49 79 2360 406 21 8 427
05/04/2016 3525 16382 12.39 16 684 333 10 55 2075 280 35 15 315
05/05/2016 3649 21913 16.4 19 701 287 29 90 2249 370 42 22 412
05/06/2016 3539 19023 14.79 15 575 298 8 85 2112 502 57 31 563
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ASRagab
ASRagab / bankersQueue.sc
Created February 16, 2018 02:08
Banker's Queue Implementation
object queuesBankers {
import BankersQueue._
case class BankersQueue[+A](sizeFront: Int, front: Stream[A], sizeRear: Int, rear: Stream[A]) {
def enqueue[B >: A](b: B) =
check(BankersQueue(sizeFront,front, sizeRear + 1, b #:: rear))
def dequeue = front match {
case h #:: t => {
val remaining = BankersQueue(sizeFront - 1, t, sizeRear, rear)
@ASRagab
ASRagab / scastie.scala
Last active October 24, 2017 23:48
Scala Koans?
def last[T](ls: List[T]): T = {
ls match {
case Nil => throw new Exception("No last element of empty list")
case h :: Nil => h
case _ :: tail => last(tail)
}
}
val test = List(2, 4, 7, 3, 100)
last(test)
@ASRagab
ASRagab / build.sbt
Created April 30, 2017 04:48
Spark 2.1.0 and 2.11.11 build.sbt to allow sbt-assembly to merge properly and to be able to 'sbt run'
name := "spark-mllib-test"
version := "1.0"
scalaVersion := "2.11.11"
val sparkVersion = "2.1.0"
libraryDependencies ++= Seq (
"org.apache.spark" %% "spark-core" % sparkVersion % "provided",
case class Duck(x: Int, y: Int, direction: String)
case class Pond(x: Int, y: Int)
object GoldenPond extends App {
def getInput: (Pond, Seq[(Duck, List[String])]) = {
val scanner = new java.util.Scanner(System.in)
val pond = scanner.nextLine.split(" ").toList.map(_.toInt).take(2) match {
case Nil => throw new Exception("Not enough coordinates for pond")
case List(a, b) => Pond(a, b)
@ASRagab
ASRagab / build.sbt
Last active November 20, 2016 06:17
Correct Dependencies for Scala + Processing 3 including Native Libs (allows OpenGL device to be found for P2D and P3D rendering modes)
name := "GeneticAlgorithm"
version := "1.0"
scalaVersion := "2.11.8"
val processingVersion = "3.2.3"
val joglVersion = "2.3.2"
val processingVideoVersion = "3.0.2"
@ASRagab
ASRagab / build.sbt
Last active August 9, 2016 05:58
DeepLearning4J
lazy val nd4jVersion = SettingKey[String]("nd4jVersion")
lazy val root = (project in file(".")).settings(
scalaVersion := "2.11.8",
name := "nd4sTest",
version := "0.5.0",
organization := "org.nd4j",
resolvers += "Local Maven Repository" at "file:///" + Path.userHome.absolutePath + "/.m2/repository",
nd4jVersion := "0.5.0",
libraryDependencies ++= Seq(
[error] Exception in thread "main" java.lang.ExceptionInInitializerError
[error] at org.nd4j.nativeblas.NativeOpsHolder.<init>(NativeOpsHolder.java:14)
[error] at org.nd4j.nativeblas.NativeOpsHolder.<clinit>(NativeOpsHolder.java:9)
[error] at org.nd4j.linalg.jcublas.ops.executioner.JCudaExecutioner.<clinit>(JCudaExecutioner.java:65)
[error] at java.lang.Class.forName0(Native Method)
[error] at java.lang.Class.forName(Class.java:264)
[error] at org.nd4j.linalg.factory.Nd4j.initWithBackend(Nd4j.java:5202)
[error] at org.nd4j.linalg.factory.Nd4j.initContext(Nd4j.java:5149)
[error] at org.nd4j.linalg.factory.Nd4j.<clinit>(Nd4j.java:169)
[error] at Main$.delayedEndpoint$Main$1(Main.scala:13)