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
double_it : IO () | |
double_it = do | |
input <- getLine | |
let n = the Int (cast input) | |
printLn (n * 2) |
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
Idris> :t [1 .. 10] | |
enumFromTo 1 10 : List Integer | |
Idris> :t [1 ..] | |
enumFrom 1 : Stream Integer |
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
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE DeriveFunctor #-} | |
module RapidCheck where | |
import Data.List | |
import Data.Monoid((<>)) | |
import System.Random | |
import Text.Show.Functions |
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
/** Catamorphisms */ | |
#include <algorithm> | |
#include <boost/algorithm/string/join.hpp> | |
#include <boost/range/algorithm.hpp> | |
#include <boost/range/adaptors.hpp> | |
#include <boost/range/numeric.hpp> | |
#include <boost/variant.hpp> | |
#include <cassert> | |
#include <functional> |
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 trap(heights: List[int]) -> int: | |
right_heights = list(heights) | |
for i in reversed(range(len(right_heights)-1)): | |
right_heights[i] = max(right_heights[i], right_heights[i+1]) | |
left_h = 0 | |
total_volume = 0 | |
for i in range(1, len(heights)-1): | |
h = heights[i] | |
left_h = max(heights[i-1], left_h) |
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 trap(heights: List[int]) -> int: | |
total_volume = 0 | |
for i, h in enumerate(heights): | |
left_h = max(heights[:i], default=0) | |
right_h = max(heights[i+1:], default=0) | |
volume = max(0, min(left_h, right_h) - h) | |
total_volume += volume | |
return total_volume |
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 trap(heights: List[int]) -> int: | |
left_h = 0 | |
total_volume = 0 | |
for i in range(1, len(heights)-1): | |
h = heights[i] | |
left_h = max(heights[i-1], left_h) | |
right_h = max(heights[i+1:], default=0) | |
volume = max(0, min(left_h, right_h) - h) | |
total_volume += volume | |
return total_volume |
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 maxSubArray(nums: List[int]) -> int: | |
max_sum = float('-inf') | |
cum_sum = 0 | |
for num in nums: | |
cum_sum += num | |
if cum_sum >= max_sum: | |
max_sum = cum_sum | |
if cum_sum <= 0: | |
cum_sum = 0 | |
return max_sum |
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 maxSubArray(nums: List[int]) -> int: | |
max_sum = float('-inf') | |
for i in range(len(nums)): | |
cum_sum = 0 | |
for j in range(i, len(nums)): | |
cum_sum += nums[j] | |
if cum_sum > max_sum: | |
max_sum = cum_sum | |
return max_sum |
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 wordBreak(self, s: str, wordDict: List[str]) -> bool: | |
if not wordDict: | |
return False | |
word_dict = set(wordDict) | |
smallest_word = min(len(w) for w in wordDict) | |
longest_word = max(len(w) for w in wordDict) | |
@lru_cache(maxsize=None) | |
def can_break_from(i: int) -> bool: |
NewerOlder