Skip to content

Instantly share code, notes, and snippets.

View vigdorchik's full-sized avatar

Eugene Vigdorchik vigdorchik

  • St.Petersburg, Russia
View GitHub Profile
import Data.List
import Data.Int
import Data.Bits
import System.IO
type Bitmap = Int64
data Problem = Problem Int {-rows-} Int {-cols-} Bitmap {-board-} [Bitmap] {-tiles-}
extract :: [String] -> [Problem]
extract ls =
(2,0), (0,0), (0,1)
(1,1), (0,3), (0,0), (3,1), (1,2)
(3,1), (1,0), (1,2), (2,2), (0,0)
(3,1), (0,1), (1,3), (0,2), (2,0)
(3,1), (2,3), (1,0), (0,0), (5,1)
(3,2), (1,2), (0,2), (1,0), (1,1)
(0,1), (0,4), (1,1), (0,0), (2,2)
(2,2), (2,1), (1,5), (0,3), (0,2)
(3,3), (2,2), (3,1), (0,0), (2,0)
(1,1), (2,0), (0,2), (0,4), (2,3)
import Data.List
import Data.Int
import Data.Bits
import Control.Arrow
import System.IO
type Bitmap = Int64
data Problem = Problem {
rows :: Int,
cols :: Int,
(2,0) (0,0) (0,1)
(1,1) (0,3) (0,0) (3,1) (1,2)
(3,1) (1,0) (1,2) (2,2) (0,0)
(3,1) (0,1) (1,3) (0,2) (2,0)
(3,1) (2,3) (1,0) (0,0) (5,1)
(3,2) (1,2) (0,2) (1,0) (1,1)
(0,1) (0,4) (1,1) (0,0) (2,2)
(2,2) (2,1) (1,5) (0,3) (0,2)
(3,3) (2,2) (3,1) (0,0) (2,0)
(1,1) (2,0) (0,2) (0,4) (2,3)
fib = map fib' [0..] where
fib' 0 = 0; fib' 1 = 1; fib' n = (fib !! (n-1))+(fib !! (n-2))
Prelude> let eps = 0.00000001
Prelude> let fix f x_1 x_2 = let f_x = x_1 - (f x_1)*(x_1 - x_2)/((f x_1) - (f x_2)) in if abs (f_x - x_1) < eps then f_x else fix f f_x x_1
Prelude> let root a = fix ((flip (-)) a . flip (^) 3) (a-1) (a+1)
Prelude> root 27
3.0
@vigdorchik
vigdorchik / gist:7135016
Created October 24, 2013 10:50
Use AnyVal
class ImplicitString(val c : C[String]) extends AnyVal {
def foo(): Unit = Console.println(c.t.toUpperCase())
}
class ImplicitInt(val c: C[Int]) extends AnyVal {
def foo(): Unit = Console.println(c.t)
}
@vigdorchik
vigdorchik / gist:7133781
Created October 24, 2013 09:08
Allocationless implicits for different instantiations
class C[T]
object ImplicitString {
def foo(): Unit = Console.println("of String")
}
object ImplicitInt {
def foo(): Unit = Console.println("of Int")
}