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
rainbowText <- function(text, colorFun = grDevices::rainbow, ...) { | |
text <- trimws(text) | |
# colorspace has some good fucntions that you can use here | |
colors <- colorFun(nchar(text), ...) | |
# wrap each letter in a differently colored span | |
html <- paste0( | |
Map(function(letter, color) | |
paste0("<span style='color:", color, "'>", letter, "</span>"), | |
strsplit(text, "")[[1]], colors | |
), collapse = "" |
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 Lcd where | |
import Data.List | |
import Control.Arrow | |
-- Integer square root | |
isqrt :: Integer -> Integer | |
isqrt = floor . sqrt . fromIntegral | |
-- Either a list of factors or the number itself (if prime) | |
primefactors :: Integer -> [Integer] |
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
as.monotonic <- function(x) { | |
while(sum(diff(x)<0)) { | |
lastMonotonic <- which(diff(x)<0) | |
firstNonMonotonic <- lastMonotonic[1] + 1 | |
# which chunk of the time series needs to be adjusted up | |
lastNonMonotonic <- ifelse(length(lastMonotonic)>1, lastMonotonic[2], length(x)) | |
monotonicRange <- firstNonMonotonic:lastNonMonotonic | |
# add last monotonic value to nonmonotonic chunk | |
x[monotonicRange] <- x[monotonicRange] + x[lastMonotonic[1]] | |
} |