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 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 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
| 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
| 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
| 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
| 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
| # multiple exits | |
| if a | |
| code | |
| code | |
| code | |
| if b | |
| code | |
| code | |
| code | |
| return c |
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
| 1.day.ago # => Sun, 11 Mar 2012 18:58:25 EDT -04:00 | |
| 24.hours.ago # => Sun, 11 Mar 2012 18:58:28 EDT -04:00 | |
| 2.days.ago # => Sat, 10 Mar 2012 18:58:35 EST -05:00 | |
| 48.hours.ago # => Sat, 10 Mar 2012 17:58:38 EST -05:00 |
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
| (60 * 60).seconds # => 3600 seconds | |
| (60 * 60).seconds.parts # => [[:seconds, 3600]] | |
| (60 * 60).seconds.parts.size # => 1 | |
| ([1.second] * 60 * 60).sum # => 3600 seconds | |
| ([1.second] * 60 * 60).sum.parts.size # => 3600 |