- Yuguiさん
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
| require './minruby' | |
| def evaluate(tree, genv, lenv) | |
| case tree[0] | |
| when 'lit' | |
| tree[1] | |
| when '+' | |
| lenv['plus_count'] ||= 0 | |
| lenv['plus_count'] += 1 | |
| left = evaluate(tree[1], genv, lenv) |
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
| require 'mathn' | |
| car, *cdr = (1..9).map{|i| ['', '+', '-', '*', '/'].map { |o| o + i.to_s }} | |
| exps = car.product(*cdr).map {|exp| exp.join}.delete_if{|e| e =~ /^[\+|\*|\/]/} | |
| komachies = exps.select{|e| eval(e) == 100} | |
| komachies.each {|k| puts k} | |
| puts "#{komachies.count} / #{exps.count}" |
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
| def euler_62 | |
| n = 1 | |
| hash = Hash.new {|h, k| h[k] = []} | |
| current_length = 1 | |
| while true | |
| cubic = n**3 | |
| key = cubic.to_s.split('').sort.join | |
| hash[key] << cubic | |
| if key.length > current_length |
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
| def formula_ptn(ptn) | |
| ope = ptn.to_s(3).rjust(8, '0').gsub('0', 'n').gsub('1', '+').gsub('2', '-') | |
| (1..9).map(&:to_s).each_with_index.inject('') do |result, (num, index)| | |
| result += num | |
| if ope[index] && ope[index] != 'n' | |
| result += ope[index] | |
| end | |
| result | |
| end | |
| 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
| code = <<END | |
| puts "Hello World!" | |
| END | |
| puts RubyVM::InstructionSequence.compile(code).disasm |
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
| class Number < Struct.new(:value) | |
| def to_s | |
| value.to_s | |
| end | |
| def inspect | |
| "<<#{self}>>" | |
| end | |
| def reducible? |
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
| require 'open-uri' | |
| require 'open_uri_redirections' | |
| require 'soundcloud' | |
| OUTDIR = 'user48736353001' | |
| Dir.mkdir(OUTDIR) unless Dir.exists? OUTDIR | |
| def save(title, download_url) | |
| puts title | |
| file_name = "#{OUTDIR}/#{title}.mp3" |
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
| def kanagawa(str) | |
| f = str.scan(/[0-9]+|[^0-9]/) | |
| ['|', '&', '+', '*'].each do |op| | |
| while(i = f.index(op)) do | |
| f[(i - 1)..(i + 1)] = eval(f[(i - 1)..(i + 1)].join('')) | |
| end | |
| end | |
| f[0] | |
| end |
NewerOlder