Skip to content

Instantly share code, notes, and snippets.

// exercism.io - 첫 번 째 풀이
case class Matrix(matrix: List[List[Int]]) {
def saddlePoints: Set[(Int, Int)] = {
matrix match {
case Nil :: _ => Set()
case _ =>
val rowsMax = matrix.map(_.max)
val columnsMin = matrix.transpose.map(_.min)
val ret = for {
trait Functor[F[_]] {
def map[A, B](fa: F[A])(f: A => B): F[B]
}
trait Applicative[F[_]] extends Functor[F] {
def apply[A, B](fab: F[A => B])(fa: F[A]): F[B] =
map2(fab, fa)((ff, a) => ff(a))
def unit[A](a: => A): F[A]
public static int GetRevision()
{
var p = new Process { StartInfo = new ProcessStartInfo
{
FileName = "git",
Arguments = "rev-list HEAD --count",
RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true,
/*
https://www.scala-exercises.org/cats/semigroup
*/
import cats.implicits._
import cats.kernel.Semigroup
Semigroup[Int].combine(1, 2)
Semigroup[List[Int]].combine(List(1, 2, 3), List(4, 5, 6))
def traverse[A, B](a: List[A])(f: A => Option[B]): Option[List[B]] = {
a match {
case Nil => Some(Nil)
case h :: t =>
println(h)
f(h).flatMap(v => traverse(t)(f).map(v :: _))
}
}
traverse(List(1,2,3,4,5))(x => if (x < 3) Some(x) else None)
출처: (https://ko.wikipedia.org/wiki/%EB%A0%88%EB%93%9C-%EB%B8%94%EB%9E%99_%ED%8A%B8%EB%A6%AC)
- 삽입
1. 삽입된 N이 첫 번째 노드이면 삽입, 아니면 2번
void insert_case1(struct node *n)
{
if (n->parent == NULL) n->color = BLACK;
else insert_case2(n);
}
sealed trait Color
case object Black extends Color
case object Red extends Color
case object Empty extends Tree { def color = Black }
case class Node(color: Color, left: Tree, value: Int, right: Tree) extends Tree
case object Leaf extends Tree { def color = Black }
sealed trait Tree {
def color: Color
# error handle
{Command} && ( {Success} ) || ( {Failed} )
에러가 발생하면 %%ERRORLEVEL%% 에 코드 저장됨
IF NOT errorlevel == 0 (ECHO ErrorLevel: %ERRORLEVEL%)
# 빈 줄 출력
ECHO.
# Token 검사