We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
importControl.Monad-- Repeat a string n times, concatenatedrep::Int->String->Stringrepns=concat$replicatens-- Center a string between n "_" on each sidecenter::Int->String->Stringcenterns=(repn"_")++s++(repn"_")-- Double a string with a "_" in the middle for bottom half of iterationdouble::String->Stringdoubles=s++"_"++s-- Base triangle of size nsierpbase::Int->[String]sierpbasen=map(\k->center((2^n)-k)(rep(2*k-1)"1"))[1..(2^n)]-- Sierpinski with detpth d and n iterationssierp::Int->Int->[String]sierpd0=sierpbasedsierpdn=(map(center(2^(d-1)))(sierp(d-1)(n-1)))++(mapdouble(sierp(d-1)(n-1)))main::IO()main=don<-readLn::IOIntmapM_putStrLn(sierp5n)
A Haskell solution using an approach similar to bubbler9903 (actually, the exact opposite technically, but the observations are the same)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Functions and Fractals: Sierpinski triangles
You are viewing a single comment's thread. Return to all comments →
A Haskell solution using an approach similar to bubbler9903 (actually, the exact opposite technically, but the observations are the same)