Skip to content

Instantly share code, notes, and snippets.

View recursivecurry's full-sized avatar

Jongsoo Lee recursivecurry

View GitHub Profile
package coroutine
import scala.collection.mutable
class Channel[A]() {
private val queue: mutable.Queue[A] = mutable.Queue.empty
// private val players: mutable.Queue[Player] = mutable.Queue.empty
def isEmpty: Boolean = queue.isEmpty
#include <iostream>
#include <string>
#include <set>
#include <vector>
using namespace std;
int main() {
int n = 0;
string nothing;
val edges: Map[Int,IndexedSeq[(Int,Int)]] = (for {
i <- 1 to m
Array(x, y, z) = StdIn.readLine().split("\\s+").map(_.toInt)
vs <- Seq(x - 1 ->(y - 1, z), y - 1 ->(x - 1, z))
} yield vs).groupBy(_._1).mapValues(_.map(_._2)).view.force
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import scala.collection.mutable.ArrayBuffer
import scala.io.StdIn
case class Pos(row: Int, col: Int)
case class Key(pos: Pos, distance: Int)
object Vanya {
def distance(p1: Pos, p2: Pos): Int = (p1.row - p2.row).abs + (p1.col - p2.col).abs
@recursivecurry
recursivecurry / transducer.hs
Last active March 6, 2016 11:35
Understanding Clojure transducers through types
-- http://conscientiousprogrammer.com/blog/2014/08/07/understanding-cloure-transducers-through-types/
-- Transducer의 자료형을 만들기 위해서는 Rank-2 type이 필요하다.
{-# LANGUAGE RankNTypes #-}
-- 함수형 프로그래밍에서 함수는 1급 시민이다. 함수를 조합하고 변환하는 것은 매우 평범한 것이다.
-- h = (f . g)라면 f (g x) = h x 이다.
-- reducer는 reduce에서 사용되는 함수에서 다양한 how를 제거하고 일반화하여 정의한 것이다.
-- 그리고 transducer는 reduce를 새로운 reducer로 변환시키는 함수이다.
-- haskell의 type system은 새로운 것에 대한 명확한 이해에 도움을 준다.
-- Understanding Clojure transducers through types
-- http://conscientiousprogrammer.com/blog/2014/08/07/understanding-cloure-transducers-through-types/
{-# LANGUAGE RankNTypes #-}
type Reducer a r = r -> a -> r
--type Transducer a b = Reducer a r -> Reducer b r
type Transducer a b = forall r . Reducer a r -> Reducer b r
--class Foldable f where
-- fold :: Transducer a (f a)
import java.io.*;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
public class CamelCase {
public static String camelCase(String word) {
final String[] wordList = word.split("-");
-- HACKERRANK: Pentagonal Numbers
-- https://www.hackerrank.com/challenges/pentagonal-numbers
module Main where
import qualified Control.Monad as M
import Data.Array
pentagonalNumbers :: Array Int Int