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
named!(single_token<&[u8], Token>, | |
alt!( | |
left_paren | | |
right_paren | | |
addition_sign | | |
subtraction_sign | | |
multiplication_sign | | |
division_sign | | |
operand | |
) |
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
named!(left_paren<&[u8], Token>, | |
do_parse!(tag!("(") >> (Token::LeftParen)) | |
); | |
named!(right_paren<&[u8], Token>, | |
do_parse!(tag!(")") >> (Token::RightParen)) | |
); | |
named!(addition_sign<&[u8], Token>, | |
do_parse!(tag!("+") >> (Token::Operator(Opcode::Add))) |
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
pub enum Token { | |
LeftParen, | |
RightParen, | |
Operator(Opcode), | |
Operand(isize) | |
} | |
pub enum Opcode { | |
Add, Subtract, Multiply, Divide, | |
} |
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
const TOLERANCE: f64 = 0.00000000000000000001; | |
fn tolerance_equals(a: f64, b: f64) -> bool { | |
((a - b) * (a - b)) < TOLERANCE | |
} | |
fn recursive_cosine_fixedpoint(a: f64) -> f64 { | |
if tolerance_equals(a, a.cos()) { | |
a | |
} else { |
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
import math | |
tolerance = 0.00000000000000000001 | |
def tolerance_equals(a, b): | |
return ((a - b) * (a - b)) < tolerance | |
def recursive_cosine_fixedpoint(a): | |
if tolerance_equals(a, math.cos(a)): | |
return a |
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 |
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 |