Skip to content

Instantly share code, notes, and snippets.

@kkotaro0111
Last active March 31, 2017 09:02
Show Gist options
  • Save kkotaro0111/0531d837cc8a5701749f80f5c84bed93 to your computer and use it in GitHub Desktop.
Save kkotaro0111/0531d837cc8a5701749f80f5c84bed93 to your computer and use it in GitHub Desktop.
月壱関東脱出計画の行き先決めるルーレット
# use data from MIC
# http://www.soumu.go.jp/denshijiti/code.html
#
# CSV data format
# > prefecture, city
# Related: 月壱関東脱出計画
# https://peraichi.com/landing_pages/view/escapefromkanto
# 仕様
# 47都道府県から1つ、ランダムで選択し、次に、その都道府県に属する市区町村をランダムで1つ選択する
# Modify
# 2017.03.30 by tarom
require 'csv'
prefectures = {}
CSV.foreach('cities.csv', headers: true) do |row|
next if row['city'].nil?
prefecture = row['prefecture']
prefectures[prefecture] ||= []
prefectures[prefecture] << row['city']
end
puts 'prefecture roulette...'
prefecture = prefectures.keys.sample
puts prefecture
puts 'city roulette...'
city = prefectures[prefecture].sample
puts city
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment