This file contains hidden or 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
$VERBOSE = true | |
module Enumerable | |
def count_by | |
return to_enum(__method__) unless block_given? | |
Hash.new(0).tap{|h| | |
each{|v|h[yield v] += 1} | |
} | |
end |
This file contains hidden or 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
# an aproach to http://www.ruby-forum.com/topic/3446541 | |
$VERBOSE = true | |
class Hash | |
def maph | |
return to_enum(__method__) unless block_given? | |
{}.tap {|hash| | |
each_pair do |key, value| |
This file contains hidden or 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
# an approach to | |
# * http://vipprog.net/wiki/exercise.html#h54a0395 | |
# * http://vipprog.net/wiki/%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9F%E3%83%B3%E3%82%B0%E8%A8%80%E8%AA%9E/Ruby/%E7%B7%B4%E7%BF%92%E5%95%8F%E9%A1%8C%E8%A7%A3%E7%AD%94%E4%BE%8B.html#h97ae94f | |
# tested Ruby 1.9.3 | |
$VERBOSE = true | |
ENCRYPTED = 'qdq-gi.q-a ziatmxxitmdqibtqi-ustbi ri.qmoqrcxi.qbubu zir -ibtqi-qp-qaai ripmymsqkir -ibtqi-qy dmxi ri.cnxuoi rruoumxakir -ibtqiqzmobyqzbkii-q.qmxi -imyqzpyqzbi rixmeaki -puzmzoqai -i-qscxmbu zaimzpir -i btq-iymbbq-a;iz -iatmxximzgi.q-a zinqiuzimzgiemgipuao-uyuzmbqpimsmuzabir -ia. za -uzsiacotiimi.qbubu zj' | |
chars = [*'abcdefghijklmnopqrstuvwxyz .,'.chars, '\-'] |
This file contains hidden or 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
# an approach to | |
# * http://vipprog.net/wiki/exercise.html#d082e883 | |
# tested Ruby 1.9.3 | |
$VERBOSE = true | |
right = rand 100 | |
loop do |
This file contains hidden or 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
# an approach to | |
# * http://vipprog.net/wiki/exercise.html#ffeaab60 | |
# tested Ruby 1.9.3 | |
$VERBOSE = true | |
class Array | |
def uniq? | |
dup.uniq!.nil? |
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
# Cで書かれたアルゴリズムやらデータ構造なりを、自分なりにRubyで表現してみるお勉強PJ。 | |
# 参考書籍(プログラミングの宝箱 アルゴリズムとデータ構造) | |
# Ruby1.9.3で動作確認済み | |
$VERBOSE = true | |
class Array |
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
# Cで書かれたアルゴリズムやらデータ構造なりを、自分なりにRubyで表現してみるお勉強PJ。 | |
# 参考書籍(プログラミングの宝箱 アルゴリズムとデータ構造) | |
# Ruby1.9.3で動作確認済み | |
# ・・・と思ったけど、早速理解に時間がかかった。 | |
# 再帰部分を切り出したり代入をRubyっぽくしたり以外、ほぼ書籍直訳状態 | |
# さらにwhileの構文でひっかかり、結局下記のサイトを参考にして脱出した・・・うーん、要・再チャレンジ | |
# 参考サイト: http://www.jamboree.jp/cms/archives/47 |
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
# Cで書かれたアルゴリズムやらデータ構造なりを、自分なりにRubyで表現してみるお勉強PJ。 | |
# 参考書籍(プログラミングの宝箱 アルゴリズムとデータ構造) | |
# Ruby1.9.3で動作確認済み | |
# と言っといてなんだけど、同書籍にCじゃなくJava版もあったので今度はそちらをもとにした。 | |
# ところがこれもというかなおさらというか読みやすくはない。 | |
# どちらにせよ1文字のカウンタ変数とか使われると、この広さはすでに読むのしんどいなー。 | |
# (古本で入手したんだけど、そもそもC版の方の変数名に前所有者の解説コメントが。ということはやっぱ直感的じゃないのでは) |
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
# Cで書かれたアルゴリズムやらデータ構造なりを、自分なりにRubyで表現してみるお勉強PJ。 | |
# 参考書籍(プログラミングの宝箱 アルゴリズムとデータ構造) | |
# Ruby1.9.3で動作確認済み | |
$VERBOSE = true | |
class Array |
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
# Cで書かれたアルゴリズムやらデータ構造なりを、自分なりにRubyで表現してみるお勉強PJ。 | |
# 参考書籍(プログラミングの宝箱 アルゴリズムとデータ構造) | |
# Ruby1.9.3で動作確認済み | |
# アイディアだけ聞いて実装イメージの大半を自力でつかめたのはこれと線形探索ぐらいだった気がする。(あってるのか別にして) | |
# でもこれそのものをRubyで使うことはないんだろうな・・・RubyのArrayは可変な上にindex使えるんだし。 | |
$VERBOSE = true |
OlderNewer