Skip to content

Instantly share code, notes, and snippets.

@wowdyaln
wowdyaln / howmanyPrime.js
Last active June 14, 2017 13:46
function howmanyPrime in js and ruby
/*
變數:
dividend(被除數): 從 3 開始 .. 到 (某數)
divisor(除數):從 2 開始 .. 到 (某數-1)
變數代號:
dividend# => dd
divisor# => dr
邏輯 圍繞在 dd % dr 這個數學式
@wowdyaln
wowdyaln / Sundaram algorithm.js
Created May 26, 2017 07:26
slightly modified the Sieve of Sundaram algorithm to cut the unnecessary iterations and it seems to be very fast.
function primeSieve(n){
var a = Array(n = n/2),
t = (Math.sqrt(4+8*n)-2)/4,
u = 0,
r = [];
for(var i = 1; i <= t; i++){
u = (n-i)/(1+2*i);
for(var j = i; j <= u; j++) a[i + j + 2*i*j] = true;
}
for(var i = 0; i<= n; i++) !a[i] && r.push(i*2+1);
function getPrimes(max) {
var sieve = [], i, j, primes = [];
for (i = 2; i <= max; ++i) {
if (!sieve[i]) {
// i has not been marked -- it is prime
primes.push(i);
for (j = i << 1; j <= max; j += i) {
sieve[j] = true;
}
}
@wowdyaln
wowdyaln / benchmark_findAllPrime.rb
Last active June 1, 2017 13:51
how much time does Ruby spend in executing a function
def howmanyPrime(number)
dd = 3
dr = 2
output = []
for dd in 3..number
for dr in 2..(number-1)
if dd%dr == 0
break
elsif dr+1 == dd
@wowdyaln
wowdyaln / .gitignore
Last active June 3, 2017 06:35 — forked from octocat/.gitignore
Some common .gitignore configurations
# normal file #
###################
*.jpg
*.mp3
*.png
*.gif
*.wav
# Compiled source #
@wowdyaln
wowdyaln / _youdow_wrap.css
Created June 3, 2017 13:07
Anki2 的 css 配置 for addon wordquery
.youdao a, .youdao a:active, .youdao a:hover {
color: #138bff
}
.youdao a {
cursor: pointer
}
.youdao body {
font-size: 14px
@wowdyaln
wowdyaln / prime_Sundaram.rb
Created June 14, 2017 13:49
Sieve of Sundaram algorithm
##### Sieve of Sundaram algorithm
def prime_Sundaram(n)
n = n/2
a = []
a[n] = nil
t = (Math.sqrt(4+8*n)-2)/4
u = 0
r = []

開源之道

Original transcript: http://allisonrandal.com/2012/04/15/open-source-enlightenment/

這幾年來,我慢慢覺得,我們參與開源社群,就像是在一條道路上並肩而行:這不僅讓我們成為更好的程式設計者,也讓我們通過與人合作,而成為更好的人。

您可以將它想成一條修行之道,讓身而為人的我們能夠不斷成長。接下來,我想談談我對開源世界的個人觀點,希望能與您分享。

首先,人是一切開源專案的核心。程式碼是很重要,但最核心的永遠是人。

@wowdyaln
wowdyaln / The Supermarket Queue.rb
Created July 6, 2017 02:51
[codewar] The Supermarket Queue
def queue_time(queue, cashier)
# 每個位置一起減去當中最小的值
def subtract_the_min(arr)
arr.map do |ele|
ele - arr.min
end
end
# 如果 at_a_certain_moment 裡面有0 -> 找到這個位置,塞入下一個顧客 ->直到每個位置都不是0
@wowdyaln
wowdyaln / node
Created September 3, 2017 18:48
gitignore sample
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Runtime data
pids
*.pid