Skip to content

Instantly share code, notes, and snippets.

@iEverX
iEverX / Main.java
Last active August 16, 2024 14:59
如何将一副扑克牌排序,限制条件是只能查看最上面的两张牌,交换最上面的两张牌,或是将最上面的一张牌放到这摞牌的最下
package algo;
import java.util.ArrayList;
import java.util.List;
// https://v2ex.com/t/1065513
public class Main {
public static void main(String[] args) {
Box box = new Box(4, 7, 2, 6, 3, 5, 8, 1, 8, 4, 76, 2, 3, 14, 0, 9, 7);
@iEverX
iEverX / bloom_filter.py
Last active December 22, 2015 17:29
Simple bloom filter, just for learning. Need bitarray support
# -*- coding: utf-8 -*-
import os
from hashlib import md5
from bitarray import bitarray
class BloomFilter(object):
def __init__(self, count, size, hash_count=8):
img.grayscale {
filter: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg'><filter id='grayscale'><feColorMatrix type='matrix' values='0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0'/></filter></svg>#grayscale"); /* Firefox 10+, Firefox on Android */
filter: gray; /* IE6-9 */
-webkit-filter: grayscale(100%); /* Chrome 19+, Safari 6+, Safari 6+ iOS */
}
img.grayscale.disabled {
filter: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg'><filter id='grayscale'><feColorMatrix type='matrix' values='1 0 0 0 0, 0 1 0 0 0, 0 0 1 0 0, 0 0 0 1 0'/></filter></svg>#grayscale");
-webkit-filter: grayscale(0%);
}
@iEverX
iEverX / caniadate.c
Last active December 16, 2015 01:09
一堆数字里有一个数字占了全部数字的一半以上,另外的数字都是随机的,快速找到这个数字
/*
* 一堆数字里有一个数字占了全部数字的一半以上,另外的数字都是随机的,
* 快速找到这个数字
*
* 算法来自 http://segmentfault.com/q/1010000000187028
* 由递归改为循环
* 时间复杂度 O(n - m)
*/
#include <stdio.h>
@iEverX
iEverX / bc_count.c
Created April 8, 2013 12:59
给定一个32位无符号整数n,求n的二进制表示中1的个数
/*
* 给定一个32位无符号整数n,求n的二进制表示中1的个数
* 算法来自 http://www.cnblogs.com/graphics/archive/2010/06/21/1752421.html
*/
#include <stdio.h>
#define PRT(func, num) (printf("%s(%x):\t%d\n", #func, num, func(num)))
unsigned int bc_plain(unsigned int n)
@iEverX
iEverX / tag.css
Created December 19, 2012 07:54
Add tags. Need jQuery
#input_outer {
border: 1px solid orange;
border-radius: 3px;
padding: 2px; display:
inline; width: 200px;
overflow: hidden;
}
.t_input {
width: 100px;
@iEverX
iEverX / maze.py
Created November 9, 2012 10:53
A solution for the problem http://weibo.com/1915548291/z4eTPtAnv
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
plus = lambda x : x + 7
minus = lambda x : x - 5
mul = lambda x : x * 3
div = lambda x : x // 2
func = {'+': plus,
'-': minus,
@iEverX
iEverX / id_check.py
Created August 23, 2012 07:43
身份证校验码计算
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
from functools import reduce
# 系数,fix = (2 ** (17 - i) % 11 for i in range(17))
fix = (7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2)
# 根据身份证号前17位计算第18位
def get_check_code(id_head):