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 does_it_change | |
mutable_array = [1,2] | |
hash = {} | |
hash[mutable_array] = 'foo' | |
puts hash[mutable_array].inspect # prints "foo" | |
mutable_array[1] = 3 | |
puts hash[mutable_array].inspect # prints "nil" | |
end | |
does_it_change |
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 System; | |
using System.Collections.Generic; | |
namespace array_compare | |
{ | |
class Program | |
{ | |
static void DoesItChange() | |
{ | |
Dictionary<int[], string> hash = new Dictionary<int[], 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
use helpers; | |
use std::fmt; | |
#[derive(Debug)] | |
pub struct Node { | |
pub left_child: Option<Box<Node>>, | |
pub right_child: Option<Box<Node>>, | |
pub has_fruit: bool, | |
} |
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 crate rand; | |
mod node; | |
mod helpers; | |
fn recursive_count_fruit(node: Option<Box<node::Node>>) -> i32 { | |
match node { | |
Some(val) => { | |
let our_fruit = if val.has_fruit { 1 } else { 0 }; | |
let unboxed = *val; |
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
// THANKS TO https://rustbyexample.com/std/box.html | |
// for the code that was modified into this example | |
struct Point { | |
x: f64, | |
y: f64, | |
} | |
struct Rectangle { | |
p1: Point, |
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 System; | |
using System.Collections.Generic; | |
namespace collections | |
{ | |
public class CaseInsensitiveDictionary<T> | |
{ | |
private Dictionary<String, T> _dict; | |
public CaseInsensitiveDictionary() | |
{ |
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
class CaseInsensitiveHash | |
def initialize | |
@hsh = {} | |
end | |
def get(key) | |
raise ArgumentError unless key.respond_to?(:to_s) | |
@hsh[key.to_s.downcase.to_sym] | |
end |
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
TOLERANCE = 0.00000000000000000001 | |
def tolerance_equals?(a, b) | |
((a - b) * (a - b)) < TOLERANCE | |
end | |
def recursive_cosine_fixedpoint(a) | |
return a if tolerance_equals?(a, Math.cos(a)) | |
recursive_cosine_fixedpoint(Math.cos(a)) | |
end |