View EvenPower.java
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
public class Is2Power { | |
public static void main(String[] args) { | |
for (int i = 0;i <= 1024; i++) { | |
if ((i & -i) == i) | |
System.out.println(Integer.toBinaryString(i) + ", " + Integer.toBinaryString(-i) + " " + i); | |
} | |
} | |
} |
View gist:3395915
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
(defn distincto | |
"s is a sequence of sequence of vars. | |
ensure that vars in each particular sequence | |
take on distinct values." | |
[s] | |
(if (seq s) | |
(let [vars (first s)] | |
(all | |
(distinctfd vars) | |
(distincto (next s)))) |
View crc32.clj
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
(defn- crc32 | |
"Generate a crc32 checksum for the given string" | |
[token] | |
(let [hash-bytes | |
(doto (java.util.zip.CRC32.) | |
(.reset) | |
(.update (.getBytes token)))] | |
(Long/toHexString (.getValue hash-bytes)))) |
View python_test.py
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 mysum(*args): | |
return sum(args) | |
def mytimes(*args): | |
if not args: | |
return 0 | |
else: | |
result = 1 | |
for v in args: | |
result *= v |
View CsvObjTools.java
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 java.io.BufferedReader; | |
import java.io.File; | |
import java.io.FileInputStream; | |
import java.io.FileNotFoundException; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.lang.reflect.Field; | |
import java.lang.reflect.Method; | |
import org.slf4j.Logger; |
View csv.lua
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
-- Using lua to parse CSV file to a table. | |
-- Notice: first line must be data description filed. | |
-- The separator is '|', change it if you want. | |
-- Usage: csv = require('csv') | |
-- tab = csv.load('test.csv', ',') | |
-- table.foreach(tab[1], print) | |
-- print(tab[1].you_field) | |
--encoding=utf-8 |
View words.lua
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
#!/usr/local/bin/lua | |
require "io" | |
local args = {...} | |
if #args < 1 then | |
print("Please specify the file path.") | |
print("./words.lua as.txt") | |
return | |
end |
View MaxMultiply.c
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 <stdlib.h> | |
#include <time.h> | |
// 问题: | |
// 求解数组中连续一段子数组和的最大数列的乘积。 | |
// | |
// 解答:特殊情况,全是负数的时候需要处理 | |
// 先应该判断是否数字大于0,大于0则进行乘积运算 | |
// 然后将运算的结果跟上次运算的结果进行比较, | |
// 如果大于上次结果就保存,直到遍历结束.期间增加 |
View MaxSum.c
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 <stdlib.h> | |
#include <time.h> | |
// 问题: | |
// 求解数组中连续一段子数组和的最大值。 | |
// | |
// 解答:特殊情况,全是负数的时候需要处理 | |
// 先判定是否上次计算的和是否大于0 | |
// 如果大于0则继续累计求和,否则就重 | |
// 新取值,然后再跟已经记录过的最大和 |
View bsearch.c
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> | |
int bsearch(int *a, int n, int v) | |
{ | |
int l = 0, r = n - 1, m = 0; | |
while (l <= r) { | |
m = l + ((r - l) >> 1); | |
if (a[m] > v) { | |
r = m - 1; |
OlderNewer