Skip to content

Instantly share code, notes, and snippets.

@apstndb
apstndb / oddeven.hs
Created July 22, 2012 13:50
oddEven implementation
oddEven :: [Int] -> ([Int],[Int])
oddEven [] = ([], [])
oddEven (x:xs) | odd x = (x:odds, evens)
| otherwise = (odds, x:evens)
where (odds, evens) = oddEven xs
@apstndb
apstndb / guessnumber.hs
Created September 9, 2012 08:45
第4回 スタートHaskell2 数当てゲーム解答
import System.IO
import Data.List
import System.Random
main = do
gen <- getStdGen
let answer = take 4 (randomRs ('1', '4') gen)
putStrLn "Hello, guess the number!"
guessNumber answer
import Control.Applicative
import Data.List
import System.Random
-- XとYと爆弾の数(TODO: 決め打ちしない)
maxX :: Int
maxX = 9
maxY :: Int
maxY = 9
numBoms :: Int
import Control.Applicative
import Data.List
import System.Random
-- XとYの数(TODO: 決め打ちしない)
maxX :: Int
maxX = 9
maxY :: Int
maxY = 9
import Control.Applicative
import Data.List
import System.Random
-- XとYの数(TODO: 決め打ちしない)
maxX :: Int
maxX = 9
maxY :: Int
maxY = 9
@apstndb
apstndb / state.hs
Last active December 11, 2015 09:58
第7回 スタートHaskell2演習問題「Stateモナドを使ってみよう」解答 http://wiki.haskell.jp/Workshop/StartHaskell2/exercise14
import Control.Monad.State
type Point = (Int, Int)
move :: Char -> State Point ()
move 'u' = do (x,y) <- get; put (x, y-1) -- 上へ移動
move 'd' = do (x,y) <- get; put (x, y+1) -- 下へ移動
move 'l' = do (x,y) <- get; put (x-1, y) -- 左へ移動
move 'r' = do (x,y) <- get; put (x+1, y) -- 右へ移動
@apstndb
apstndb / reader.hs
Last active December 11, 2015 09:58
第7回 スタートHaskell2演習問題「Readerモナドを使ってみよう」解答 http://wiki.haskell.jp/Workshop/StartHaskell2/exercise14
import Data.List
import System.Environment
import Data.Maybe
import Control.Monad.Reader
type Env = [(String, String)]
environment :: Env
environment =
[ ("HOME", "/home/haskell")
@apstndb
apstndb / GCF_GVISOR_EVAL.md
Last active May 28, 2018 13:28
Google Cloud Functions should be based on gVisor

deploy function

${PROJECT_NAME} should be your own project name.

$ gcloud functions deploy helloExec --trigger-http --project=${PROJECT_NAME}

execute function

@apstndb
apstndb / GAE_JAVA8_GVISOR_EVAL.md
Last active May 27, 2018 14:41
App Engine Java 8 Standard Runtime should be based on gVisor

It can be checked by the same method of Google Cloud Functions

deploy App Engine Java 8

$ mvn appengine:deploy

get result

https://twitter.com/sonatard/status/1002767157262872577

グローバル領域のポインタ比較は定数化されている。

$ go build -gcflags '-N -l' -o executable .
$ go tool objdump -s isEqual executable
TEXT main.isEqual(SB) /Users/apstndb/work/gosandbox/main.go
  main.go:7             0x10935b0               c644240800              MOVB $0x0, 0x8(SP)
 main.go:8 0x10935b5 c644240800 MOVB $0x0, 0x8(SP)