This file contains 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
(load "graph_util") | |
(defparameter *congestion-city-nodes* nil) | |
(defparameter *congestion-city-edges* nil) | |
(defparameter *visited-nodes* nil) | |
(defparameter *node-num* 30) | |
(defparameter *edge-num* 45) | |
(defparameter *worm-num* 3) | |
(defparameter *cop-odds* 15) |
This file contains 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
(defparameter *robot-num* 10) | |
(defun robots () | |
;; namedによって(return-from main とループを抜けれるように名前を持たせている | |
(loop named main | |
;; 幅64のゲーム盤におけるオフセット | |
;; withはループ内にローカル変数を作成する | |
with directions = '((q . -65) (w . -64) (e . -63) | |
(a . -1) (d . 1) | |
(z . 63) (x . 64) (c . 65)) |
This file contains 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
(defparameter *width* 100) | |
(defparameter *height* 30) | |
(defparameter *jungle* '(45 10 10 10)) | |
(defparameter *plant-energy* 80) | |
;; key => (x座標 . y座標), value => t | |
;; コンスセルを比較するにはequalが必要となる為、:test #'equalとしている | |
(defparameter *plants* (make-hash-table :test #'equal)) | |
(defparameter *reproduction-energy* 200) | |
(defstruct animal x y energy dir genes) |
This file contains 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
;; CLISP特有のソケットコマンド・バイト/文字列変換コマンドを使っている | |
;; 日本語を利用するためのエンコーディング指定 | |
(setf *terminal-encoding* charset:utf-8) | |
(setf *default-file-encoding* charset:utf-8) | |
;; 16進数で表されたASCIIコードをデコードする | |
(defun http-char (c1 c2 &optional (default #\space)) | |
(let ((code (parse-integer | |
(coerce (list c1 c2) 'string) |
This file contains 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 Circuit | |
def initialize(circuit) | |
@circuit = analyze(circuit) | |
end | |
def calc | |
@circuit.inject(0) {|memo, item| memo + item.val}.truncate | |
end | |
def analyze(circuit) |
This file contains 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
#!/usr/bin/env ruby | |
LOG_ITEMS = %w(ip_address ident_user_name authenticate_user_name access_date request_line status_code forwarding_byte caller_url user_agent).each | |
class LogParser | |
def initialize(logs) | |
@logs = logs.chomp | |
@result = {} | |
@start_idx = 0 | |
end |
This file contains 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
# from http://guides.rubyonrails.org/association_basics.html#the-has-many-through-association | |
##### Model ##### | |
class Physician < ActiveRecord::Base | |
has_many :appointments | |
has_many :patients, through: :appointments | |
accepts_nested_attributes_for :appointments | |
end |
This file contains 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
source "https://rubygems.org" | |
gem "sinatra" |
This file contains 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
source 'https://rubygems.org' | |
gem 'sinatra' |
This file contains 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 Player | |
attr_reader :size | |
def initialize(senryaku) | |
@count = 0 | |
@size = senryaku.size | |
@senryaku = senryaku | |
@senryaku_enum = senryaku.each_char.cycle | |
end |