Skip to content

Instantly share code, notes, and snippets.

View gwy15's full-sized avatar

gwy15 gwy15

  • Bytedance
View GitHub Profile
#!/usr/bin/pypy
import random
import math
import unittest
def simulate(n, m, k, times=1000000):
'''
随机模拟计算概率
Args:
@gwy15
gwy15 / main.cpp
Created October 26, 2018 20:31
template compile OTM
#include <iostream>
#include <tuple>
template <int n> auto foo(int a) {
return std::make_tuple(foo<n - 1>(a), foo<n - 1>(a));
}
template <> auto foo<0>(int a) { return std::make_tuple(a, a); }
int main() {
import random
probs = [1.2, 1.2, 1.1, 1.05, 1.5, 1.75, 2.0, 1.7]
probs.append(100 - sum(probs))
populations = list(range(len(probs)))
def getTime():
time = 0
collected = [False for key in populations]
{
"callback":"http://localhost:11913/weibo"
}
import gzip as compressLib
import json
import hashlib
import asyncio
from pathlib import Path
import dataclasses
import requests
import aiohttp
import async_pool
fn find_collatz(number: u64, cache: &mut Vec<i32>) -> i32 {
let n = cache.len() as u64;
let index = number as usize;
if number < n && cache[index] != 0 {
// cache hit
cache[index]
} else {
// cache miss
let result = match number {
fn close_test4() {
let string_postfix = "456";
let closure = move |mut s: String| {
s.push_str(string_postfix);
s
};
let mut vec_of_closures = Vec::new();
// vec_of_closures.push(closure);
push_closure_to_vec(closure, &mut vec_of_closures);
#!/bin/bash
sudo apt update
sudo apt -y install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get -y update
sudo apt-get -y install docker-ce
#![feature(test)]
extern crate test;
use rand::prelude::*;
use std::{io::Error, panic::catch_unwind};
use test::Bencher;
fn main() {}
const TARGET: i32 = 30;
use std::{
marker::PhantomData,
ops::{Deref, DerefMut},
};
const EXTRA_MASK: u64 = 0xFFFF_0000_0000_0000;
const POINTER_MASK: u64 = 0x0000_FFFF_FFFF_FFFF;
pub struct Pointer<T> {
ptr: *mut (),
_marker: PhantomData<T>,