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 prob(a, n, t): | |
rest = t - a | |
if rest < 2: | |
return 0 | |
if rest == 2: | |
return 4 | |
if rest <= n + 1: | |
return rest + 1 | |
if rest <= 2 * n: | |
return 2 * n - rest + 1 |
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 calc_import_path(target: str, start: str) -> str: | |
import os | |
target = os.path.join('root', target) | |
start = os.path.join('root', start) | |
d = os.path.relpath(os.path.dirname(target), os.path.dirname(start)) | |
if not d.startswith('.'): | |
d = os.path.join('.', d) | |
return os.path.join(d, os.path.basename(target)) |
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
#define _GNU_SOURCE | |
#include <stdio.h> | |
#include <ftw.h> | |
int walk(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf) | |
{ | |
static const char *flag2msg[] = { | |
[FTW_F] = "Regular file.", | |
[FTW_D] = "Directory.", | |
[FTW_DNR] = "Unreadable directory.", |
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
use libc::*; | |
use std::convert::TryInto; | |
use structopt::StructOpt; | |
#[derive(StructOpt, Debug)] | |
struct Cli { | |
#[structopt(subcommand)] | |
cmd: Command, | |
} |
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
package main | |
type S struct { | |
i int | |
} | |
func main() { | |
var a []*int | |
for _, s := range []S{{1},{2},{3}} { | |
a = append(a, &s.i) |
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
package main | |
import "github.com/ethereum/go-ethereum/common" | |
func main() { | |
hashes := []common.Hash{{1}, {2}, {3}} | |
ss := convertDirectly(hashes) | |
checkResult("direct", ss) |
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
struct Hoge { | |
agony: String | |
} | |
impl Drop for Hoge { | |
fn drop(&mut self) { | |
println!("drop: {}", self.agony); | |
} | |
} |
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
pragma solidity >=0.5.0; | |
contract Refunder { | |
modifier fullyRefund() { | |
uint256 gas = gasleft(); | |
_; | |
gas = gas - gasleft() + 21000; | |
msg.sender.transfer(gas * tx.gasprice); | |
} |
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
package main | |
import ( | |
"os" | |
"syscall" | |
"time" | |
) | |
const ( | |
CHILD_ARG = "child" |
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
package main | |
import "math/rand" | |
func main() { | |
n := 0 | |
for n < 4 { | |
for n = 0; rand.Int()%2 == 0; n++ { | |
println("ズン") | |
} |
NewerOlder