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
# ヒット&ブローを表すクラス。 | |
# このクラスのオブジェクトはイミュータブル。 | |
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
(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
// 原始的でシンプルな方法 | |
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
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
// 使用例 | |
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
(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 java.awt.AWTException; | |
import java.awt.MouseInfo; | |
import java.awt.Point; | |
import java.awt.Robot; | |
import java.awt.event.InputEvent; | |
public class Main { | |
public static void main(String[] args) throws InterruptedException, AWTException { | |
final Robot robot = new Robot(); |
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.ekisample | |
import scala.collection.mutable | |
import scala.xml.XML | |
import java.net.URLEncoder | |
object Main { | |
def main(args: Array[String]) { | |
val shiritori = new Shiritori() |
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.scala.practice | |
import scala.collection.immutable.Queue | |
object OnePersonGame { | |
def main(args: Array[String]) { | |
import Operations._ | |
test(solve(List()), List()) | |
test(solve(List(5)), List(REMOVE)) |