This file contains 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
num = ARGV[0] | |
1.upto(num.to_i) {|i| | |
if i % 3 == 0 && i % 5 == 0 then | |
puts "fizzbuzz" | |
elsif i%3 == 0 then | |
puts "fizz" | |
elsif i%5 == 0 then | |
puts "buzz" | |
else | |
puts i |
This file contains 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 expr(e, stack=[], rpn=[]) | |
case e | |
when "=" | |
rpn += stack.reverse | |
return rpn.inject([]) do |arr, token| | |
case token.to_s | |
when /[-+*\/]/ then arr << arr.pop(2).inject($&) | |
when /\d+/ then arr << $&.to_f | |
end | |
end.shift |
This file contains 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 expr(e) e.to_s.include?("=") ? e.split[0..-2].inject([]){|arr,e| (!arr.empty? && arr.last =~ /[^\d]/) ? [eval([*arr,e].join)] : arr << e } : ->(_e){expr("#{e} #{_e}")} end | |
puts expr(4)["+"][3]["*"][2]["-"][1]["="] |
This file contains 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
<?php | |
class AdAbTest { | |
private $templates = array(); | |
public function addTemplate($template, $ratio) { | |
$this->templates[] = array( | |
"template" => $template, | |
"ratio" => $ratio, | |
); | |
} |
This file contains 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
#include <math.h> | |
double AttackerSuccessProbability(double q, int z){ | |
double p = 1.0 - q; | |
double lambda = z * (q / p); | |
double sum = 1.0; | |
int i, k; | |
for (k = 0; k <= z; k++){ | |
double poisson = exp(-lambda); | |
for (i = 1; i <= k; i++)poisson *= lambda / i; | |
sum -= poisson * (1 - pow(q / p, z - k)); |