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.security.MessageDigest) | |
(defn sha1 [s] | |
(let [md (MessageDigest/getInstance "SHA-1")] | |
(do | |
(. md update (. s getBytes)) | |
(apply str (map #(format "%02x" %) (. md digest)))))) |
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 com.taroid.slideshare4s.{SortOrder, SlideShare, Query} | |
object Main { | |
def main(args: Array[String]) { | |
val apiKey = System.getenv("SLIDESHARE_API_KEY") | |
val sharedSecret = System.getenv("SLIDESHARE_SHARED_SECRET") | |
val ss = SlideShare(apiKey, sharedSecret) | |
val query = Query(words = "kotlin", itemsPerPage = 10, language = "ja", sortOrder = SortOrder.LATEST) |
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 Main { | |
def main(args: Array[String]) { | |
val puzzle = new SlidePuzzle(3, List(3, 1, 2, 4, 7, 5, 6, 0, 8), 0) | |
val solvedPuzzleHistory = SlidePuzzle.solve(puzzle) | |
assert(solvedPuzzleHistory(3).cells == List(3, 1, 2, 4, 7, 5, 6, 0, 8)) | |
assert(solvedPuzzleHistory(2).cells == List(3, 1, 2, 4, 0, 5, 6, 7, 8)) | |
assert(solvedPuzzleHistory(1).cells == List(3, 1, 2, 0, 4, 5, 6, 7, 8)) | |
assert(solvedPuzzleHistory(0).cells == List(0, 1, 2, 3, 4, 5, 6, 7, 8)) | |
} |
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 com.taroid.sample | |
import java.sql.DriverManager | |
import java.sql.ResultSet | |
import java.sql.Statement | |
import java.sql.Connection | |
fun main(args: Array<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
(defn index-to-pos [index width] [(int (/ index width)) (rem index width)]) | |
(defn pos [{width :width cells :cells} cell] (index-to-pos (.indexOf cells cell) width)) | |
(defn distance [[r1 c1] [r2 c2]] (+ (Math/abs (- r1 r2)) (Math/abs (- c1 c2)))) | |
(defn win-distance [{width :width cells :cells :as board} cell] | |
(distance (pos board cell) (pos {:width width :cells (range 0 (count cells))} cell))) | |
(defn total-win-distance [{cells :cells :as board}] |
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
# ヒット&ブローを表すクラス。 | |
# このクラスのオブジェクトはイミュータブル。 | |
class HitAndBlow | |
NUMBERS_LENGTH = 4 | |
NUMBER_RANGE = (1..9) | |
# 指定された配列が、正解の数の形式として妥当か判定する。 | |
# 数の重複がなく、所定の範囲ないの値を持ち、長さがNUMBERS_LENGTHの配列ならばtrueを、それ以外ならfalseを返す。 | |
def self.valid_numbers? submitted_numbers |
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
fun divisor(val a: Int,val b: Int) : Int = if(b == 0) a else divisor(b, a % b) | |
fun main(args: Array<String>){ | |
test(1, divisor(1, 1)) | |
test(2, divisor(2, 4)) | |
test(2, divisor(4, 2)) | |
test(6, divisor(24, 18)) | |
test(6, divisor(18, 24)) | |
test(1, divisor(13, 19)) | |
test(1, divisor(19, 13)) |
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
// Android(サーバ側) | |
package com.taroid.advent; | |
import android.app.Activity; | |
import android.os.Bundle; | |
import android.widget.Toast; | |
public class MainActivity extends Activity { |
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
// 不変コレクションを作る場合は ImmutableArrayListBuilderクラス を使おう | |
// このテストは失敗する | |
package com.taroid.kt.sample | |
import kotlin.test.assertEquals | |
import org.junit.Test as test | |
class ImmutableCollectionTest() { |
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
module Prime( | |
prime | |
) where | |
prime :: Int -> Bool | |
prime x | x < 0 = error "the argument should be larger than zero." | |
| x == 1 = False | |
| x == 2 = True | |
| mod x 2 == 0 = False | |
| otherwise = all (\y -> mod x y /= 0 || x == y) (take (x - 3) [3, 5..]) |