Haskell, 38 bytes
I feel like PPCG is really improving my Haskell. Strokes white cat.
f n=mapM(["<","~<~"]<$f)[1..n]!!n>>=id
f
takes an Int
and returns a String
.
(I'm referring to that <$f
by the way. It saves a character over \_->
.)
In the
Functor
instance for(->) a
(functions from typea
), we have:x <$ f = fmap (const x) f = const x . f = const x
. The only limitation is thatf
and the finalconst x
must use the same source typea
. The instance is completely lazy so this never even evaluatesf
.
Alternatively, same length but less evil ((l!!)
is an anonymous function):
(l!!)
l=(++)<$>"":tail l<*>["<","~<~"]
Both of these use the same representation as @ETHproductions' Japt answer, although especially the first one may give some redundant <
s at the beginning.
The first one calculates all combinations of n
"<"
and "~<~"
strings, then indexes into the resulting list.
The second one recursively calculates an infinite list formed by starting with ""
and then constructing new elements by appending "<"
and "~<~"
strings to each element already in the list (actually it was slightly shorter to also let the ""
get turned into "<"
.)