Open codereport opened 4 years ago
fn maxDepth(s: str) -> i32 { s.filter(not in "()") .map('(' ? 1 : -1) .scan(+) .max } fn maxDepth(s: str) -> i32 { s.map('(' ? 1 : -1).scan(+).max } fn maxDepth(s: str) -> i32 { s | map('(' ? 1 : -1) | scan(+) | max } fn maxConsecutiveOnes(arr: vec) -> i32 { arr.chunkBy(==) .map(sum) .max } fn maxConsecutiveOnes(arr: vec) -> i32 { arr.chunkBy(==).map(sum).max } fn maxConsecutiveOnes(arr: vec) -> i32 { arr.chunkBy(=1) .filter(_.head = 1) .map(size) .max } fn avg(arr: vec) -> f32 { arr.divide(S! sum, size) } avg = divide(S!, sum, size) fn canBeSquare(path: str) -> bool { 'LRUD'.outerProduct(path, =) .map(sum) .allEqual } fn deltas := arr.sliding(2).map(W! -) fn deltas(arr: vec) -> arr { arr.sliding(2).map(W! -) } fn rainWater(arr: vec) := i32 { fn mountain := min(S! scan(max), under(rev).scan(max)) arr.mapReduce(mountain, S! +, W! -) } fn mountain := min(S! scan(max), under(rev).scan(max)) fn rainWater := mapFold(mountain, S! +, W! -) fn isPalindrome(word: str) -> bool { word.equal(S! rev, id) } fn palindrome? := word.equal(S! rev, id) fn deltas := arr.sliding(2).map(W! -) fn average := divide(S!, sum, size) fn mco := chunkBy(=).map(sum).max fn any?(pred: fn) := bool { mapFold(false, and, pred) } fn any? := mapFold(false, and) fn any? := fold(false, and) fn all? := fold(true, or) fn sum := fold(0, +) fn product := fold(1, *) fn minimum := fold(min) fn maximum := fold(max) sumType TrafficColor := Male | Female | NonBinary fn trafficColorString(g: Gender) -> str { match (g) | Gender::male <- "male" | Gender::female <- "female" | Gender::nonbinary <- "nonbinary" } fun maxDepth(s: str) -> i32 { s |> filter(not in "()") |> map(is '(' ? 1 : -1) |> scan(+) |> max } fun maxDepth(s: str) -> i32 { s :> filter(not in "()") :> map(is '(' ? 1 : -1) :> scan(+) :> max } func maxDepth(s: str) -> i32 { s | filter(not in "()") | map(is '(' ? 1 : -1) | scan(+) | max } fn findNumbers(Arr arr) -> i32 { arr.map(B! string size) .filter(even?) .size } fn findNumbers(Arr arr) -> i32 { arr.map(string) .map(size) .filter(even?) .size }