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: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>
@ende76
ende76 / test_pca.m
Created June 3, 2012 17:24
Unit Test for Assignment "Dimensionality Reduction (Week 8)"
function [success] = test_pca()
eps = 1E-4;
X = [ ...
0.8414710 -0.2879033 -0.4040376 0.9017883 -0.9661178 0.5661076 0.1059875 -0.7271425 0.9988152 -0.7904332 0.2021499; ...
0.9092974 -0.9613975 0.5514267 0.1235731 -0.7391807 0.9995202 -0.7794661 0.1847817 0.4987132 -0.9425145 0.9333205; ...
0.1411200 -0.7509872 0.9999119 -0.7682547 0.1673557 0.5139785 -0.9482821 0.9268185 -0.4599035 -0.2280523 0.8064006; ...
0.7568025 0.1498772 0.5290827 -0.9537527 0.9200260 -0.4441127 -0.2452520 0.8167426 -0.9956870 0.6960801 -0.0619203; ...
0.9589243 0.9129453 -0.4281827 -0.2623749 0.8268287 -0.9938887 0.6832617 -0.0442427 -0.6160405 0.9802397 -0.8733120; ...