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
| from typing import TypeVar, List, Optional | |
| from functools import partial | |
| T = TypeVar('T') | |
| class TreeNodeTy: | |
| pass | |
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
| interface IGroupedElements<T> { | |
| [value: string]: T[] | |
| } | |
| const groupBy = <T, U>(collection: T[], predicate: (elem: T) => U): IGroupedElements<T> => { | |
| return collection.reduce((accumulator, current) => { | |
| const output = predicate(current).toString() | |
| if (output in accumulator) { |
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 Main where | |
| binaryToIntegral :: Integral a => String -> a | |
| binaryToIntegral xs = sum $ map fst bits | |
| where count = length xs - 1 | |
| bits = filter ((/= zero) . snd) $ zip (map (2^) [count, pred count..0]) xs | |
| zero = '0' | |
| main :: IO () |