Ruby

Binary Indexed Tree

AtCoder Beginner Contest 153 atcoder.jp BIT知らなかった。 BIT github.com 参考 Competitive Programming Tutorials - Binary Indexed Trees Binary Indexed Tree のはなし F - Silver Fox vs Monster class BIT def initialize(n) @tree = Array.new(n +…

[Ruby] 再帰的group_by

やりたいこと こういうデータ↓を [ { prefecture: '埼玉県', city: '深谷市', town: '北根', address: '3-5' }, { prefecture: '埼玉県', city: '深谷市', town: '北根', address: '3-7-19' }, { prefecture: '埼玉県', city: '深谷市', town: '堀米', addre…

画像からQuineを生成するGemを作った

AAQ - Ascii Art Quine aaq | RubyGems.org yskoht/aaq: Create ascii art quine from image file | Github できること 画像からRubyのQuineをつくれます。たとえば、Octocatの画像をQuineにしてみます。 Octcat 出力されるアスキーアートは自分自身を出力す…

Ruby on Rails チュートリアル 第4章をやったメモ

Ruby on Rails チュートリアル:実例を使って Rails を学ぼうのRails 5.1(第4版) 4章はRubyの文法について。 symbol-to-proc便利 >> ['1', '2', '3'].map(&:to_i) => [1, 2, 3] splitで1文字ずつ分割 >> def string_shuffle(s) >> s.split('').shuffle.jo…