Skip to content

Instantly share code, notes, and snippets.

#define eq(X, a) ((X[0] == a[0]) && (X[1] == a[1]))
main() {
int t;
float tp, tn, fp, fn, p, r;
tp = tn = fp = fn = 0;
char c[3];
scanf("%d\n", &t);
while (t--) {
main() {
char c = getchar(), t, p = -1;
int freq[128] = {0};
while ( (t = getchar()) != '\n' ) {
if (p == c)
freq[t] ++;
p = t;
}
def ncr(n, r)
a, b = r, n-r
a, b = b, a if a < b # a is the larger
numer = (a+1..n).inject(1) { |t,v| t*v } # n!/r!
denom = (2..b).inject(1) { |t,v| t*v } # (n-r)!
numer / denom
end
def ncrdigs_naive(n, r, base)
ncr(n, r).to_s(base).length
#include <stdio.h>
int gray_decode(int n) {
int p = n;
while (n >>= 1) p ^= n;
return p;
}
int main() {
int t, c;
a, b = gets.split.map {|x| x.to_i }
data = []
a.times do
data << gets.split.map {|x| x.to_i }
end
gets.to_i.times do
px, py, qx, qy = gets.split.map {|x| x.to_i }
sum = 0
gets.to_i.times do
n = gets.to_i
puts 4*n*n - 3*n
end

Keybase proof

I hereby claim:

  • I am vikhyat on github.
  • I am vikhyat (https://keybase.io/vikhyat) on keybase.
  • I have a public key whose fingerprint is 4B56 5241 D57E 05C0 63FC D8BB 93DF 9F5A 4004 802A

To claim this, I am signing this object:

@vikhyat
vikhyat / gist:5569625983b95f99bcc3
Created June 16, 2014 17:37
Manga Information Importer
require 'nokogiri'
require 'date'
require 'json'
def repair_broken_html(html)
rep = html
# Broken UTF-8 encoding.
rep = rep.unpack('C*').pack('U*') unless rep.valid_encoding?
# "<" is not escaped.
rep = rep.gsub(/<([^A-Za-z!\/])/, '&lt;\1')
@vikhyat
vikhyat / gist:768c4fe883de83a799a4
Last active August 29, 2015 14:02
HABTM Preload Benchmark
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'arel', github: 'rails/arel'
gem 'sqlite3'
GEMFILE
system 'bundle'
end
:command WQ wq
:command Wq wq
:command W w
:command Q q