Skip to content

Instantly share code, notes, and snippets.

View therealcisse's full-sized avatar

Amadou Cisse therealcisse

View GitHub Profile
@Daenyth
Daenyth / ImmutableLRU.scala
Created March 12, 2019 17:36
LruRef / LRU for cats-effect
package teikametrics
import scala.collection.SortedMap
/**
* Immutable implementation of an LRU cache.
*
* @author Twitter
*
* Copy pasted from the version previously in twitter-util v19.1.0 at
import cats.effect.ExitCase._
import cats.effect.Sync
import cats.effect.concurrent.Ref
import cats.syntax.flatMap._
import cats.syntax.functor._
trait Tap[F[_]] {
def apply[A](effect: F[A]): F[A]
}
@pathikrit
pathikrit / README.md
Last active April 24, 2021 17:36
My highly opinionated list of things needed to build an app in Scala
@pathikrit
pathikrit / SudokuSolver.scala
Last active April 12, 2024 15:00
Sudoku Solver in Scala
val n = 9
val s = Math.sqrt(n).toInt
type Board = IndexedSeq[IndexedSeq[Int]]
def solve(board: Board, cell: Int = 0): Option[Board] = (cell%n, cell/n) match {
case (r, `n`) => Some(board)
case (r, c) if board(r)(c) > 0 => solve(board, cell + 1)
case (r, c) =>
def guess(x: Int) = solve(board.updated(r, board(r).updated(c, x)), cell + 1)
val used = board.indices.flatMap(i => Seq(board(r)(i), board(i)(c), board(s*(r/s) + i/s)(s*(c/s) + i%s)))