Skip to content

Instantly share code, notes, and snippets.

View beiweiqiang's full-sized avatar
🎯
Focusing

beiweiqiang beiweiqiang

🎯
Focusing
  • Guangzhou, China
View GitHub Profile
@beiweiqiang
beiweiqiang / main.c
Created June 23, 2018 00:45
当所有奇数位为 1, 返回 1
#include <stdio.h>
/*
* CSAPP exercise 2.64
* */
/*
* 当所有奇数位为 1, 返回 1
* 假设 w 为 32
* */
/*
* CS:APP Data Lab
*
* <Please put your name and userid here>
* bei wei qiang
* bits.c - Source file with your solutions to the Lab.
* This is the file you will hand in to your instructor.
*
* WARNING: Do not include the <stdio.h> header; it confuses the dlc
* compiler. You can still use printf for debugging without including
@beiweiqiang
beiweiqiang / main.c
Created July 15, 2018 16:37
2048 in c
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
// 定义方格边大小
#define SIZE 4
#define INIT_RAND_COUNT 2
// 表示位置
@beiweiqiang
beiweiqiang / main.py
Last active July 28, 2018 01:36
python practice 01
# 用于添加, 浏览, 删除 联系人的电话
import pickle
import os
data = []
target = 'backup'
file_name = 'backup_data.data'
path = os.path.join(target, file_name)
if os.path.exists(path):
@beiweiqiang
beiweiqiang / main.py
Created July 28, 2018 05:05
Fibonacci Sequence
# Fibonacci Sequence
# Enter a number and have the program generate the Fibonacci sequence
# to that number or to the Nth number.
import sys
sys.setrecursionlimit(10000)
def fibonacci(n):
@beiweiqiang
beiweiqiang / main.py
Created July 28, 2018 06:23
primer factor
# Prime Factorization -
# Have the user enter a number and
# find all Prime Factors (if there are any) and display them.
# primer factors:
# table https://en.wikipedia.org/wiki/Table_of_prime_factors
def prime_factor(n):
if n == 1:
@beiweiqiang
beiweiqiang / main.py
Created July 28, 2018 07:07
Find Next Prime Number
# Next Prime Number
# Have the program find prime numbers until the user chooses to stop asking for the next one.
# 找到下一个质数
prime_number = [2]
i = 0
def find_next_prime():
global i
@beiweiqiang
beiweiqiang / main.py
Created July 28, 2018 08:17
Fast Exponentiation
# Fast Exponentiation
# Ask the user to enter 2 integers a and b and output a^b (i.e. pow(a,b)) in O(lg n) time complexity.
def my_pow(a, b):
if b == 0: return 1
temp = my_pow(a, b // 2)
if b % 2 == 0:
return temp * temp
else:
@beiweiqiang
beiweiqiang / main.py
Created July 28, 2018 09:34
merge sort AND bubble sort
# Sorting
# Implement two types of sorting algorithms:
# Merge sort and bubble sort.
import math
from random import randint
def merge_arr(arr1, arr2):
"""
@beiweiqiang
beiweiqiang / app.js
Created January 19, 2019 00:14
Digest Access Authentication using Nodejs
const http = require('http');
const crypto = require('crypto');
const realm = 'user';
const ACCOUNT = {
'username': 'psw'
};
class Nonce {
constructor() {