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 "tour/tree" | |
import "fmt" | |
// Walk walks the tree t sending all values | |
// from the tree to the channel ch. | |
func Walk(t *tree.Tree, ch chan int) { | |
WalkRecursive(t, ch) | |
close(ch) |
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
extern mod std; | |
use core::cmp::*; | |
fn main() { | |
let b = make_bst::<int>(); | |
b.add(8); | |
b.add(3); | |
b.add(6); | |
b.add(7); | |
b.add(4); |
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
extern mod std; | |
use core::cmp::*; | |
fn main() { | |
let mut b = BST::<int> { Root: @None }; | |
b.add(8); | |
b.add(3); | |
b.add(6); | |
b.add(7); | |
b.add(4); |
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
extern mod std; | |
use core::io::ReaderUtil; | |
use core::vec; | |
use core::vec::*; | |
fn main() { | |
let input = get_lines(); | |
let first_line: &str = input[0]; | |
let toks = str::split_char(first_line, ' '); | |
let ldn = map(toks, |&s| uint::from_str(s).get()); |
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
fn main() { | |
let mut input = get_lines(); | |
let num_cases_str = vec::remove(&mut input, 0); | |
let num_cases = int::from_str(num_cases_str).get(); | |
let mut i = 1; | |
while i <= num_cases { | |
let credit = int::from_str(vec::remove(&mut input, 0)).get(); | |
let _num_items = int::from_str(vec::remove(&mut input, 0)).get(); | |
let items = vec::map(str::split_char(vec::remove(&mut input, 0), ' '), |&s| int::from_str(s).get()); | |
let (a, b) = best_buy(credit, items); |
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
using(var rng = new RNGCryptoServiceProvider()) | |
{ | |
var bytes = new byte[4]; | |
rng.GetBytes(bytes); | |
var value = BitConverter.ToUInt32(bytes, 0); | |
value.Dump(); | |
} |
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
public string ConvertToBase(uint value, char[] characterSet) | |
{ | |
var radix = (uint)characterSet.Length; | |
var result = new List<char>(); | |
do | |
{ | |
var remainder = value % radix; | |
value = value / radix; | |
result.Add(characterSet[remainder]); | |
} while(value > 0); |
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
public string ConvertToBase(uint value, char[] characterSet) | |
{ | |
var radix = (uint)characterSet.Length; | |
var result = string.Empty; | |
do | |
{ | |
var remainder = value % radix; | |
value = value / radix; | |
result = characterSet[remainder] + result; | |
} while(value > 0); |
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
void Main() | |
{ | |
var charset = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray(); //which characters can appear in the string | |
var length = 32; //length of the string | |
Console.WriteLine(GenerateKey(charset, length)); | |
} | |
///Generate a random string of arbitrary length using RNGCryptoServiceProvider. | |
///characterSet is the set of characters that can appear in the string. | |
///length is the desired length of string. |
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
public static class ExtensionMethods | |
{ | |
//given a list {1,2,3,4}, this will return {(1,2), (2,3), (3,4)} | |
public static IEnumerable<Tuple<T,T>> AsSlidingPairs<T>(this IEnumerable<T> list) | |
{ | |
if(list == null) throw new ArgumentNullException(); | |
if(!list.Any()) | |
{ | |
yield break; | |
} |
OlderNewer