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
#include <stdio.h> | |
int gray_decode(int n) { | |
int p = n; | |
while (n >>= 1) p ^= n; | |
return p; | |
} | |
int main() { | |
int t, 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
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 |
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
main() { | |
char c = getchar(), t, p = -1; | |
int freq[128] = {0}; | |
while ( (t = getchar()) != '\n' ) { | |
if (p == c) | |
freq[t] ++; | |
p = t; | |
} |
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
#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--) { |
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
main() { | |
int n, m, k, t=0, i; | |
scanf("%d\n", &n); | |
int s[n][2]; | |
for (i=0; i<n; i++) | |
scanf("%d %c\n", &s[i][0], &s[i][1]); | |
scanf("%d\n", &m); |
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
#define classify(x) (((x) >= 0.5) ? '+' : '-') | |
float sigmoid(float x) { | |
return 1 / (1 + exp((double) -x)); | |
} | |
main() { | |
int d, q, i, a, t; | |
scanf("%d %d\n", &d, &q); | |
int beta[d+1]; |
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
int fib(n) { | |
return n < 2 ? n : fib(n-1) + fib(n-2); | |
} | |
int main() { | |
int t, n; | |
scanf("%d\n", &t); | |
while (t--) { | |
scanf("%d\n", &n); | |
printf("%f\n", fib(n+2) / pow(2, n)); |
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
function readAnime(results) { | |
return _.map(results.anime, function(anime) { | |
anime.linked = {}; | |
_.each(Object.keys(anime.links), function(rel) { | |
var relVal; | |
if (Array.isArray(anime.links[rel])) { | |
relVal = _.find(results.linked[rel], function(candidate) { | |
// return whether candidate.id is in anime.links[rel] | |
}); | |
} else { |
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
Here's how it's going to look like from the end user perspective: | |
1 hour before my PRO membership ends, if I am on a recurring plan | |
Hummingbird will try to charge my credit card. If it succeeds | |
everything is good. If it fails my subscription will run out and | |
Hummingbird will try to charge my credit card again tomorrow, 3 | |
days from now and 5 days from now. I will receive an email from | |
Hummingbird if the charge is successful, and a different email | |
every time charging my card fails. |
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
test |