exfreeterのブログ

一念発起した。今日から頑張る。元ニートでもやれる。

はてなブログをMarkdownで書くことにした

はてなブログってMarkdownに対応してたんですね...。
知らなかった(>_<)

てことで、

はてなブログをMarkdownモードに変えてみた

ブログの設定画面でサクって変更出来ました。
この記事も早速Markdownで書いてます。
快適っす。

色々あるけど、何よりも

コードを書けるのが良い

  • Javascpipt
alert("Hello, World!");
  • Ruby
message = "Hatena"
puts "I like #{message}!!" # I like Hatena!!


昨日のRubyでW杯シミュレータ作ったっていう記事も、本当はブログ内にコードを貼ってみたかったんですけど、やり方が分からなくて諦めたんですよねぇ...。
諦める前にググるべきだった...。

一応、昨日のコードの断片です。

def check_duplication(country, group, tmp_results)
  countries = countries_of_group(group, tmp_results).select{|country| country != ""} << country
  confederations = countries.map{|c| confederation(c)}
  if confederations.uniq.length == confederations.length
    return false
  else
    a = confederations.uniq.select{|i| confederations.index(i) != confederations.rindex(i)}
    if a.length == 1 && a[0] == UEFA[0] && (confederations.length - confederations.uniq.length) < confederations.length - 2
      return false
    end
    return true
  end
end

def decide_group(country, groups, tmp_results)
  begin
    group = groups.sample
  end while check_duplication(country, group, tmp_results)
  group
end

グループを決めて、そのグループ内に同一大陸の国がいないか(欧州だけは2ヶ国までOK)をチエックしてるところです。
decide_groupをPot1の国々から順に呼んでいく感じになります。

POTS.each_with_index do |pot, i|
  groups = ("A".."H").to_a
  pot.unshift(pot.pop) if i == 2
  pot.each_with_index do |country, j|
    if i == 0 && j == 0
      result = {group: "A", position: 0}
    else
      result = draw(country, groups, results)
      result[:position] = 0 if i == 0
    end
    countries_of_group(result[:group], results)[result[:position].to_i] = country
    groups.delete(result[:group])
  end
end

こんな感じですね。
pot.unshift(pot.pop) if i == 2のところは、そうしないと上記のdecide_group内のWhile文で無限ループの恐れがあるので。(欧州の国は各グループに2ヶ国までというルールを回避出来なくなる)
詳しくは、以下のGithubからどうぞ。

toshikidoi/2014_fifa_world_cup_draws_simulator · GitHub

何にせよ、ブログの内容に集中するためにもMarkdownでストレスなく書けるのは良いですね。