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
{- | |
State monad things, but in Haskell. | |
I am but a humble FP noob. | |
-} | |
module Main where |
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.data.State | |
sealed trait Input | |
case object Coin extends Input | |
case object Turn extends Input | |
case class Machine(locked: Boolean, candies: Int, coins: Int) | |
object Main extends App { | |
val insertCoin: State[Machine, (Boolean, Int)] = State(machine => { |
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
/* interop */ | |
[@bs.val] [@bs.scope "Math"] external random : unit => float = "random"; | |
[@bs.val] [@bs.scope "Math"] external floor : float => int = "floor"; | |
let random = (max: float): int => { | |
floor(random() *. max); | |
}; | |
let x = (n: int): option('float) => { | |
switch (n) { | |
| 0 => None |
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
[%bs.raw {|require('./App.css')|}]; | |
[@bs.module] external logo : string = "./logo.svg"; | |
type action = Hello | Goodbye | Whatever; | |
type state = { | |
greeting: string | |
}; |
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 me.sent1nel | |
import cats.effect.IO | |
import io.circe.{Json, Encoder} | |
import org.http4s.HttpService | |
import org.http4s.dsl.Http4sDsl | |
import org.http4s.server.blaze.BlazeBuilder | |
import org.http4s.util.StreamApp | |
import org.http4s.circe._ |
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 me.sent1nel | |
sealed trait Stream[+A] { | |
def headOption: Option[A] = this match { | |
case Empty => None | |
case Cons(h, t) => Some(h()) | |
} | |
// 5.1 | |
def toList: List[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
sealed trait Tree[+A] | |
case class Leaf[A](value: A) extends Tree[A] | |
case class Branch[A](left: Tree[A], right: Tree[A]) extends Tree[A] | |
object Tree { | |
// 3.29, FP in Scala | |
def identity[A](a: A): A = a // I combinator | |
def constant[A,B](a: A)(b: B): A = a // K combinator | |
def map[A,B](t: Tree[A])(f: A => B): Tree[B] = |
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 me.sent1nel; | |
import java.util.ArrayList; | |
import java.util.Date; | |
import java.util.List; | |
import java.util.stream.Collectors; | |
// https://javalin.io/ | |
import io.javalin.Javalin; | |
import io.javalin.Handler; |
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
// actor started | |
// First: Actor[akka://testSystem/user/first-actor#-477064136] | |
// >>> Press ENTER to exit <<< | |
// Second: Actor[akka://testSystem/user/first-actor/second-actor#1443434381] | |
// sub-actor started | |
// sub-actor stopped | |
// actor stopped | |
package com.lightbend.akka.sample |
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 Solution { | |
def main(args: Array[String]) { | |
val sc = new java.util.Scanner (System.in); | |
var n = sc.nextInt(); | |
var a = Array.ofDim[Int](n,n); | |
for(a_i <- 0 to n-1) { | |
for(a_j <- 0 to n-1){ | |
a(a_i)(a_j) = sc.nextInt(); | |
} |