Skip to content

Instantly share code, notes, and snippets.

@parrot-studio
parrot-studio / fizzbuzz.rb
Created August 8, 2012 04:38
FizzBuzzを書いたことがないとまずいらしいので・・・
# coding: utf-8
(1..100).each do |n|
puts case
when n % 15 == 0
'FizzBuzz'
when n % 3 == 0
'Fizz'
when n % 5 == 0
'Buzz'
else
@parrot-studio
parrot-studio / BF.scala
Last active December 20, 2015 16:29
BrainF**k interpreter by Scala (confirmed by 2.10.2)
import scala.annotation.tailrec
object BF {
class Parser(val str: String) {
val cmap = Map(
">" -> 'pinc,
"<" -> 'pdec,
"+" -> 'inc,
"-" -> 'dec,
@parrot-studio
parrot-studio / geolocation.rb
Created September 13, 2013 00:49
座標系の計算モジュール 2点間の距離算出と、ある地点からNメートルの範囲にある緯度/経度範囲の算出 (ほとんど他の方のBlogのパクリであまりよろしくない) 実際は方形で大雑把に絞り込んだ後、具体的な各地点間の距離を算出し、 「半径Nメートル以内にあるポイント」を絞り込んでいる
# coding: utf-8
module Geolocation
def distance_to(lat, lon, mode = nil)
return unless (lat && lon)
return unless (self.respond_to?(:latitude) && self.respond_to?(:longitude))
earth_distance(self.latitude, self.longitude, lat, lon, mode)
end
def distance_between(point, mode = nil)
@parrot-studio
parrot-studio / mini.rb
Last active December 28, 2015 02:18
miniが待てないんだよщ(゚Д゚щ)
# encoding: utf-8
require 'mail'
MAIL_ENCODING = 'ISO-2022-JP'
MYADDR = "hogehoge"
def send_message
mes = "mini来た!!"
m = Mail.new
# coding: utf-8
def read_data(count)
c = count.to_i
return if c < 0
ret = []
count.times do
s = gets
next unless s
ret << s.to_i
end
https://paiza.jp/poh/ando
glasses
https://paiza.jp/poh/ando/share/f872136d
santa
https://paiza.jp/poh/ando/share/b8c73b8b
swimwear
https://paiza.jp/poh/ando/share/841f1803
https://paiza.jp/poh/hatsukoi/
https://paiza.jp/moshijo
@parrot-studio
parrot-studio / bf.exs
Last active January 17, 2017 10:37
BrainF**k interpreter by Elixir
defmodule BF do
@cmap %{
">" => :pinc,
"<" => :pdec,
"+" => :inc,
"-" => :dec,
"." => :out,
"," => :inp,
"[" => :jmp,
"]" => :ret
# https://paiza.jp/logic_summoner/challenges/logics_skill_4005
def mark(board, table, w, max, color, base, ind)
return if table[ind]
return unless color == board[ind]
r = ind % w
table[ind] = base
mark(board, table, w, max, color, base, ind - 1) if r > 0 # left
mark(board, table, w, max, color, base, ind + 1) if r < w - 1 # right
mark(board, table, w, max, color, base, ind - w) if ind >= w # up