This file contains hidden or 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
| // Propositional logic implemenation | |
| const True = a => b => a; | |
| const False = a => b => b; | |
| const If = x => x; | |
| const Not = a => a(False)(True); | |
| const And = a => b => a(True)(False)(b(True)(False))(False); | |
| const Or = a => b => a(True)(b(True)(False)); | |
| const Xor = a => b => And(Or(a)(b))(Not(And(a)(b))); | |
| // SKI calculus implementation |
This file contains hidden or 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 toAddress(bytes): | |
| return int.from_bytes(bytes, byteorder='big') | |
| class Map: | |
| # Map structure is tied to a file | |
| def __init__(self, fileHandle): | |
| self.fileHandle = fileHandle | |
| self.header = self.Header(fileHandle) | |
| fileHandle.seek(toAddress(self.header.commands[-1].data)) | |
| self.mesh = Mesh(fileHandle) |
This file contains hidden or 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
| trait Component { | |
| fn draw(&self, ctx: &mut Context) -> (); | |
| fn get_children(&self) -> Vec<Component>; | |
| } | |
| struct Label { | |
| children: Vec<Component>, | |
| text: graphics::Text, | |
| color: graphics::Color, | |
| position: graphics::Point, |
This file contains hidden or 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
| { (include './contract.lll' | |
| (def 'enough-paid (>= callvalue required-amount)) | |
| (def 'enough-betters (>= number-of-betters required-betters)) | |
| (def 'is-paying-out (= paying-out 1)) | |
| (def 'minimum-bet-amount 10) ; Wei | |
| (def 'required-betters 10) | |
| (init { |
This file contains hidden or 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 fn nth(n: usize) -> Result<u64, &'static str> { | |
| if n <= 0 { Err("No primes below 1") } | |
| else { | |
| match (2..).filter(|&x| is_prime(x)).nth(n - 1) { | |
| Some(n) => Ok(n), | |
| None => Err("Iteration error") | |
| } | |
| } | |
| } |
This file contains hidden or 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 fn reply(message: &str) -> &str { | |
| let chrs = || message.trim().chars(); | |
| let has_text = chrs().any(|c| c.is_alphanumeric()); | |
| let has_letters = chrs().any(|c| c.is_alphabetic()); | |
| let has_lowercase = chrs().any(|c| c.is_alphabetic() && !c.is_uppercase()); | |
| if has_letters && has_text && !has_lowercase { "Whoa, chill out!" } | |
| else if chrs().as_str().ends_with("?") { "Sure." } | |
| else if !has_text { "Fine. Be that way!" } | |
| else { "Whatever." } |
This file contains hidden or 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 fn verse(n: i32) -> String { | |
| if n > 2 { | |
| format!("{0} bottles of beer on the wall, {0} bottles of beer.\nTake one down and pass it around, {1} bottles of beer on the wall.\n", n, n - 1) | |
| } else if n == 2 { | |
| format!("2 bottles of beer on the wall, 2 bottles of beer.\nTake one down and pass it around, 1 bottle of beer on the wall.\n") | |
| } else if n == 1 { | |
| format!("1 bottle of beer on the wall, 1 bottle of beer.\nTake it down and pass it around, no more bottles of beer on the wall.\n") | |
| } else { | |
| format!("No more bottles of beer on the wall, no more bottles of beer.\nGo to the store and buy some more, 99 bottles of beer on the wall.\n") | |
| } |
This file contains hidden or 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
| // Viterbi algorithm for finding hidden relationships | |
| function Viterbi(data) { | |
| var V = [{}]; | |
| var path = {}; | |
| // Initialize base cases (t == 0) | |
| for(var i=0;i<data.states.length;i++) { | |
| var state = data.states[i]; | |
| V[0][state] = data.start_probability[state] * data.emission_probability[state][data.observations[0]]; | |
| path[state] = [state]; |
This file contains hidden or 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
| ;------------------------------------------------------------------------- | |
| ; FcAppendRgchToFn(fn, pch, cch) | |
| ;------------------------------------------------------------------------- | |
| ;/* F C A P P E N D R G C H T O F N */ | |
| ;/* Appends characters pointed to by pch, length cch, to end of file fn. | |
| ;Returns first fc written. | |
| ;If there is a free hole of sufficient size in vfkpdText, it will be | |
| ;used instead. | |
| ;fcLim updated to point to after the last char written. | |
| ;*/ |
This file contains hidden or 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
| The programmer bryanl left some real nice comments in the source code. I bet he never expected it to be looked at years later. I've added some commentary myself too. | |
| Line 412: | |
| When a character is typed, it is inserted at rgchInsert[ichInsert++]. | |
| When rgchInsert is full, it is written to the scratch file, and Replace'd | |
| with a new insertion block. | |
| Line 222: | |
| fc = FcAppendRgchToFn(fnScratch, rgchInsert, ichInsert); |