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 PrimeFactor | |
| def self.new | |
| @memoized = {} | |
| Hash.new do |h, index| | |
| @memoized[index] ||= memoize(h, index) | |
| h[index] = @memoized[index] | |
| end | |
| end |
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 PrimeFactor | |
| def initialize(number) | |
| @factors = Fiber.new do | |
| divisor = 2 | |
| while divisor < number | |
| while number % divisor == 0 | |
| Fiber.yield divisor | |
| number = number / divisor | |
| end | |
| divisor = divisor + 1 |
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
| 245 try { | |
| 246 X509CertImpl firstCertImpl = X509CertImpl.toImpl(firstCert); | |
| 247 issuerSelector.parseAuthorityKeyIdentifierExtension( | |
| 248 firstCertImpl.getAuthorityKeyIdentifierExtension()); | |
| 249 | |
| 250 worthy = issuerSelector.match(trustedCert); | |
| 251 } catch (Exception e) { | |
| 252 // It is not worth trying. | |
| 253 } |
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
| lines = File.open('time_table.csv', 'rb') { |file| file.read } | |
| require 'time' | |
| File.open('result_time_table.csv', 'w') do |csv| | |
| lines.each do |line| | |
| tokens = line.chomp.split(",") | |
| if tokens[1] == ":" | |
| csv.puts tokens.join(",") | |
| next |
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 suicide? [board point color size] | |
| (let [board (assoc board point color) | |
| enemy (find-enemy board point color size) | |
| ally (find-ally board point color size)] | |
| (and (reduce #(and %1 (> (count (find-liberty %2)) 0)) true enemy) | |
| (= (count (find-liberty ally)) 0)))) | |
| (defn legal? [board point color size ko] | |
| (and (not (= ko point)) | |
| (not (out-of-bound point size)) |
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 find-enemy [board point color size] | |
| (let [color (if (= white color) black white) | |
| neighbors (find-neighbors point size)] | |
| (set (reduce | |
| #(if (ally? %2) | |
| (merge %1 (find-ally board %2 color size)) | |
| %1) | |
| () neighbors)))) |
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 find-liberty-helper [board point size] | |
| (filter #(gray? board % size) (find-neighbors point size))) | |
| (defn find-liberty [board points size] | |
| (loop [points points liberty ()] | |
| (let [point (first points)] | |
| (if (= 0 (count points)) | |
| (set liberty) | |
| (recur (rest points) (clojure.set/union (find-liberty-helper board point size) liberty)))))) |
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 ally? [board point color] (= color (nth board point))) | |
| (defn new-ally? [board point color ally] | |
| (and (ally? board point color) (not (.contains ally point)))) | |
| (defn find-neighbors [point size] | |
| (let [north (- point size) | |
| east (inc point) | |
| south (+ point size) | |
| west (dec point)] |
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 gray? [board point size] (= gray (nth board point))) |
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 out-of-bound [point size] (or (< point 0) (> point (dec size)))) |