Skip to content

Instantly share code, notes, and snippets.

private fun readChar(): Char = readString()[0]
private fun readChars(): CharArray = readString().toCharArray()
private fun readInt(): Int = readLine()!!.toInt()
private fun readInts(): List<Int> = readLine()!!.trim().split(" ").map(String::toInt)
private fun readLong(): Long = readLine()!!.toLong()
private fun readLongs(): List<Long> = readLine()!!.trim().split(" ").map(String::toLong)
private fun readString(): String = readLine()!!.trim()
private fun readStrings(): List<String> = readLine()!!.trim().split(" ")
fun roll(die: Int, dieSides: Int) = Pair(die + (die % dieSides) + (die + 1) % dieSides + 2, (die + 2) % dieSides + 1)
private fun readChar(): Char = readString()[0]
private fun readChars(): CharArray = readString().toCharArray()
private fun readInt(): Int = readLine()!!.toInt()
private fun readInts(): List<Int> = readLine()!!.trim().split(" ").map(String::toInt)
private fun readLong(): Long = readLine()!!.toLong()
private fun readLongs(): List<Long> = readLine()!!.trim().split(" ").map(String::toLong)
private fun readString(): String = readLine()!!.trim()
private fun readStrings(): List<String> = readLine()!!.trim().split(" ")
import java.util.*
private fun readChar(): Char = readString()[0]
private fun readChars(): CharArray = readString().toCharArray()
private fun readInt(): Int = readLine()!!.toInt()
private fun readInts(): List<Int> = readLine()!!.trim().split(" ").map(String::toInt)
private fun readLong(): Long = readLine()!!.toLong()
private fun readLongs(): List<Long> = readLine()!!.trim().split(" ").map(String::toLong)
private fun readString(): String = readLine()!!.trim()
private fun readStrings(): List<String> = readLine()!!.trim().split(" ")
private fun readChar(): Char = readString()[0]
private fun readChars(): CharArray = readString().toCharArray()
private fun readInt(): Int = readLine()!!.toInt()
private fun readInts(): List<Int> = readLine()!!.trim().split(" ").map(String::toInt)
private fun readLong(): Long = readLine()!!.toLong()
private fun readLongs(): List<Long> = readLine()!!.trim().split(" ").map(String::toLong)
private fun readString(): String = readLine()!!.trim()
private fun readStrings(): List<String> = readLine()!!.trim().split(" ")
data class Header(val version: Long, val typeId: Long)
import java.util.*
private fun readChar(): Char = readString()[0]
private fun readChars(): CharArray = readString().toCharArray()
private fun readInt(): Int = readLine()!!.toInt()
private fun readInts(): List<Int> = readLine()!!.trim().split(" ").map(String::toInt)
private fun readLong(): Long = readLine()!!.toLong()
private fun readLongs(): List<Long> = readLine()!!.trim().split(" ").map(String::toLong)
private fun readString(): String = readLine()!!.trim()
private fun readStrings(): List<String> = readLine()!!.trim().split(" ")
@ende76
ende76 / gist:9487691
Created March 11, 2014 15:05
Problem approach to an optimal solution for http://www.problemotd.com/problem/kings-wine/

King's Wine

In celebration of our king finding the village that was cheating him he decides to throw a celebration for the other 9 villages. In preparation for the celebration he orders 1000 barrels of the finest wine.

When the members of the uninvited village find out about the party they send an assassin to poison one of the barrels of wine. The poison takes 7 days to kill so the party guests won't realize what is happening for awhile.

However, after poisoning a random barrel the king's guard finds out and has the assassin executed. There is no time to order more wine so the king devises a genius plan to have his 10 loyal servants taste test the wine to find the poisoned barrel just in time for the party in 10 days. What is the plan that he devises so that he is left with 999 barrels of wine for the party?

@ende76
ende76 / gist:6087033
Created July 26, 2013 07:49
This examples throws an error at compile time: does_not_fulfill_static.rs:5:32: 5:44 error: cannot capture variable of type `&[u8]`, which does not fulfill `'static`, in a bounded closure
use std::vec;
fn closure_with_captured_variables(target_bytes: &[u8], prefix: &[u8]) -> @fn(&[u8]) -> ~[u8] {
|bytes| {
vec::append(bytes.to_owned(), target_bytes)
}
}
fn main() {
use std::vec;
fn encrypt_decrypt_consistent_key() -> (@fn(&[u8]) -> ~[u8], @fn(&[u8]) -> ~[u8]) {
let key = "random key".as_bytes().to_owned();
let key0 = copy key;
(|bytes: &[u8]| {
vec::append(bytes.to_owned(), key)
}, |bytes: &[u8]| {
vec::append(bytes.to_owned(), key)
@ende76
ende76 / illustrated_exec.go
Last active December 11, 2015 09:08
(SOLVED) Minimal program to illustrate a possible misunderstanding of what os.exec() can and cannot do with external programs' output.
package main
import (
"fmt"
"log"
"os"
"os/exec"
)
type MyWriter struct{}
@ende76
ende76 / LIS331HH_example.ino
Created January 18, 2013 13:11
Small example on how to read input from a LIS331HH accelerometer chip, and then to use that input to replicate the orientation of the chip using a servo.
// Arduino UNO system clock speed: 16 MHz
// max SPI clock frequency: 10 MHz
// shift order: MSB first
// SPC idle level: HIGH
// data samples capture edge: rising
#include <SPI.h>
#include <Servo.h>