- Baby Gin Problem
- Lexicographic–Order
- Johonson-Trotter
- Minimum-exchange Requirement
- Knapsack Problem and Fractional Knapsack Method
- Huffman coding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)))) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package Other | |
| import scalaz.Functor | |
| import scala.language.higherKinds | |
| object exampleList { | |
| sealed trait mList | |
| case object mNil extends mList |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import cats._ | |
| import cats.implicits._ | |
| case class StreamZipper[A](left: Stream[A], focus: A, right: Stream[A]) { | |
| def moveLeft: StreamZipper[A] = | |
| if (left.isEmpty) this | |
| else new StreamZipper[A](left.tail, left.head, focus #:: right) | |
| def moveRight: StreamZipper[A] = | |
| if (right.isEmpty) this |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /bin/bash | |
| # | |
| # Run parallel commands and fail if any of them fails. | |
| # | |
| set -eu | |
| pids=() | |
| for x in 1 2 3; do |