Skip to content

Instantly share code, notes, and snippets.

View youknowcast's full-sized avatar

Hideki Ambe youknowcast

View GitHub Profile
@youknowcast
youknowcast / fizz_buzz.py
Created June 15, 2019 01:01
aiit_system_programming_vol02
def fb(n):
if n % 15 == 0:
return 'FizzBuzz'
elif n % 3 == 0:
return 'Fizz'
elif n % 5 == 0:
return 'Buzz'
else:
return ''
@youknowcast
youknowcast / fizz_buzz.py
Created June 30, 2019 05:11
challenge1-1 fizz_buzz.py
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'
@youknowcast
youknowcast / nl.py
Created June 30, 2019 05:20
challenge1-2 nl.py
import sys
import os
args = sys.argv
if len(args) < 2:
print("usage python nl.py path/to/file")
exit()
path = args[1]
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
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'))
@youknowcast
youknowcast / eratosthenes.c
Created July 7, 2019 07:30
eratosthenes with Clang
#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++) {
@youknowcast
youknowcast / eratosthenes.go
Created July 7, 2019 07:32
eratosthenes with golang
package main
import (
"fmt"
"math"
)
const NUM = 100000
func main() {
@youknowcast
youknowcast / main.rs
Created July 7, 2019 07:33
eratosthenes with Rust
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);
@youknowcast
youknowcast / ls.py
Last active July 28, 2019 01:44
challenge3-2 ls
from argparse import ArgumentParser, FileType
import os
import grp
import pwd
import stat
import datetime
parser = ArgumentParser(
prog='ls.py',
usage='',
@youknowcast
youknowcast / mysh.py
Last active July 28, 2019 05:40
challenge3-3
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()