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
let int_sqrt x = x |> float_of_int |> sqrt |> int_of_float | |
(** | |
* [oddSquareNumber n] | |
* returns the sum of all odd square numbers less than [n] | |
* | |
* it does this by going through all the odd numbers from [1] to [sqrt(n)] | |
* and adding the square of each number to the sum if the square is less | |
* than [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
module KeyToRowMap = Map.Make (Char) | |
let qwertyKeyToRowMap = | |
let firstRow = ['q'; 'w'; 'e'; 'r'; 't'; 'y'; 'u'; 'i'; 'o'; 'p'] in | |
let secondRow = ['a'; 's'; 'd'; 'f'; 'g'; 'h'; 'j'; 'k'; 'l'] in | |
let thirdRow = ['z'; 'x'; 'c'; 'v'; 'b'; 'n'; 'm'] in | |
KeyToRowMap.empty | |
|> (fun m -> List.fold_left (fun acc key -> KeyToRowMap.add key 1 acc) m firstRow) | |
|> (fun m -> List.fold_left (fun acc key -> KeyToRowMap.add key 2 acc) m secondRow) | |
|> (fun m -> List.fold_left (fun acc key -> KeyToRowMap.add key 3 acc) m thirdRow) |
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
let sum = List.fold_left (fun acc x -> acc + x) 0 | |
type result = { pies : int; uneaten_pieces : int } | |
let pies pieces piece_per_pie = | |
let total_pieces = sum pieces in | |
let pies = | |
if total_pieces mod piece_per_pie == 0 then total_pieces / piece_per_pie | |
else (total_pieces / piece_per_pie) + 1 | |
in |
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
export class LaunchControl { | |
private serverUrl: string; | |
private lastSessionState: "start" | "end" | null; | |
private trackingId: string; | |
constructor(serverUrl: string, trackingId: string) { | |
this.serverUrl = serverUrl; | |
this.lastSessionState = null; | |
this.trackingId = trackingId; | |
} |
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
function faultyKeeb(str: string): string { | |
const out = []; | |
const vowels = ["a", "e", "i", "o", "u"]; | |
for (const ch of str) { | |
if (vowels.includes(ch)) { | |
out.reverse(); | |
} else { | |
out.push(ch); | |
} | |
} |
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
fn is_isomorphic(s1: &str, s2: &str) -> bool { | |
let mask1 = str_mask(s1); | |
let mask2 = str_mask(s2); | |
mask1 == mask2 | |
} | |
fn str_mask(s: &str) -> Vec<usize> { | |
s.chars() | |
.fold((None, Vec::<usize>::new()), |(last_c, mut acc), curr_c| { |
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 island_perimeter(grid): | |
perimeter = 0 | |
for i in range(len(grid)): | |
row = grid[i] | |
for j in range(len(row)): | |
cell = grid[i][j] | |
if cell != 1: | |
continue |
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 type Grid = Vec<Vec<u8>>; | |
pub fn grid_perimeter(grid: Grid) -> usize { | |
grid.iter() | |
.enumerate() | |
.map(|(i, row)| { | |
row.iter() | |
.enumerate() | |
.filter_map(|(j, cell)| if *cell == 1 { Some(j) } else { None }) | |
.map(|j| { |
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
use itertools::Itertools; | |
pub fn lexo_next(num: usize) -> usize { | |
let digits = digits(num); | |
let mut perms = digits | |
.iter() | |
.permutations(digits.len()) | |
.map(number) | |
.filter(|perm| *perm != num) |
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
(defun range (x y) | |
(let ((start (min x y)) (end (max x y))) | |
(loop for i from start to end | |
collect i))) | |
(defun primep (num) | |
(cond | |
((<= num 1) nil) | |
((= num 2) t) | |
(t |