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 fb(n): | |
if n % 15 == 0: | |
return 'FizzBuzz' | |
elif n % 3 == 0: | |
return 'Fizz' | |
elif n % 5 == 0: | |
return 'Buzz' | |
else: | |
return '' |
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
all_map = {} | |
fb_map = {} | |
f_map = {} | |
b_map = {} | |
all_map[0] = 0 | |
i = 1 | |
for i in range(200): | |
all_map[i] = i | |
fb_map[i * 15] = 'FizzBuzz' |
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
import sys | |
import os | |
args = sys.argv | |
if len(args) < 2: | |
print("usage python nl.py path/to/file") | |
exit() | |
path = args[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
def calc7(arr): | |
if len(arr) == 0: | |
return -1 | |
else: | |
is_7 = False | |
ret = 0 | |
for i in arr: | |
if is_7: | |
ret += i * 2 | |
is_7 = False |
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 mask_3rd(word): | |
if len(word) < 3: | |
return word | |
else: | |
ch = word[2] | |
ret = word.replace(ch, "*") | |
return "".join([ret[:2], ch, ret[3:]]) | |
print(mask_3rd('logging')) | |
print(mask_3rd('apple')) |
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 <stdio.h> | |
#include <math.h> | |
#define NUM 100000 | |
int main(void) { | |
int prime[NUM + 1]; | |
int i, j, Limit; | |
for (i=2; i <= NUM; 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
package main | |
import ( | |
"fmt" | |
"math" | |
) | |
const NUM = 100000 | |
func main() { |
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
fn main() { | |
let num: usize = 100000; | |
let mut prime = vec![1; num+1]; | |
let limit: usize; | |
for i in 2..num { | |
prime[i] = 1; | |
} | |
limit = ((num as f64).sqrt() as usize); |
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
from argparse import ArgumentParser, FileType | |
import os | |
import grp | |
import pwd | |
import stat | |
import datetime | |
parser = ArgumentParser( | |
prog='ls.py', | |
usage='', |
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
import sys | |
import os | |
import subprocess | |
current = os.path.dirname(os.path.abspath(__file__)) | |
def builtin_method(opt, piped_ret): | |
global current | |
opt_arr = opt.split() |
OlderNewer