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 xs: Vec<Box<dyn PrintableNumber>> = vec![Box::new(Foo), Box::new(Bar)]; | |
print_each(xs); | |
} | |
struct Foo; | |
struct Bar; | |
// Combined trait that requires both ToString and ToInt | |
trait PrintableNumber: ToString + ToInt {} |
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
letterChar : Char -> Boolean | |
letterChar c = List.contains c <| toCharList "abcdefghijklmnopqrstuvwxyz" | |
groupAnswers : Text -> Map Char Nat | |
groupAnswers gr = | |
combine : Map Char Nat -> Char -> Map Char Nat | |
combine accMap c = | |
if letterChar c then | |
use Nat + | |
putWith (+) c 1 accMap |
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
/** | |
* Observable version of the above | |
*/ | |
function drawRectsObservable() { | |
// implement this function! | |
const svg = document.getElementById("drawRects")!, | |
mousedown = Observable.fromEvent<MouseEvent>(svg, 'mousedown'), | |
mousemove = Observable.fromEvent<MouseEvent>(svg, 'mousemove'), | |
mouseup = Observable.fromEvent<MouseEvent>(svg, 'mouseup'), |
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 Observable<Input> { | |
// ... SNIP | |
/** Create two new observables, where one contains only those inputs for which the condition | |
* holds, and the other contains only those for which the condition does not hold | |
*/ | |
splitBy(condition: (_:Input)=>boolean): [Observable<Input>, Observable<Input>] { | |
const yes = this.filter(condition); | |
const no = this.filter(i => ! condition(i)); |
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
#include <stdio.h> | |
void print_prototype(int num_elements); | |
void print_func(int num_elements); | |
void sort_func_generator(int num_elements); | |
int main(int argc, char *argv[]) { | |
int num_ints; | |
scanf("%d", &num_ints); | |
sort_func_generator(num_ints); |
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
####################################### | |
# suggestion for an additional for-loop structure. | |
####################################### | |
for x in y while condition: | |
do_stuff() | |
# as syntax sugar for: | |
for x in y: |
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 checkio(text): | |
nopunc="" | |
alph="abcdefghijklmnopqrstuvwxyz" | |
for char in text: | |
if char.lower() in alph: | |
nopunc+=char.lower() | |
maxcount=1 | |
mostfreq="" | |