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 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 |
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
#include <iostream> | |
#include <string> | |
#include <set> | |
#include <vector> | |
using namespace std; | |
int main() { | |
int n = 0; | |
string nothing; |
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
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 |
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
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 |
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
-- 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은 새로운 것에 대한 명확한 이해에 도움을 준다. |
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
-- 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) |
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 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("-"); |
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
-- 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 |
NewerOlder