Based on Chunky vs. Smooth Strings.
Squiggles /\_/\/\__/\/\/\/\_/\_/\
are fun to make on a keyboard when you are really bored. But not all squiggles are created equal. Some squiggles are smooth, like \___/
, and some are chunky, like /\/\/\/\
. Others are just downright broken, like ////_\\\
Inside every squiggle of N
characters, there are N-1
squiggle-junctions. Each squiggle-junction is classified into one of three types:
Smooth (angle > "90 degrees"):
\_ __ _/
Chunky (angle = "90 degrees")
/\ \/
Broken (anything that doesn't connect)
// \\ /_ _\
Let's define the smoothness to be the proportion of junctions that are smooth, with chunkiness and brokenness defined similarly. Each value ranges between 0
and 1
. The sum of a squiggle's smoothness, chunkiness, and brokenness is always equal to 1.
For example, the squiggle /\/\\_//\_
has 3 smooth junctions, 4 chunky junctions, and 2 broken junctions. It is thus 0.3333
smooth, 0.4444
chunky, and 0.2222
broken.
Empty strings and strings with only one character have undefined values, all input will be at least 2 characters long.
Challenge
Write a program that takes in a squiggle of arbitrary length and outputs any two of its smoothness, chunkiness, and brokenness values.
- You may write a program or function, with input via STDIN, command line, or as a string argument.
- You may assume the input is at least of length >= 2 and consists only of the characters
/\_
with an optional trailing newline. - Print (or return if a function) the two floats to a precision of at least 4 decimals, rounded or truncated. If the true value is
2/3
, acceptable values include any value between0.6666
and0.6667
, even things like0.666637104
. If the exact value is1/3
, any answer containing0.3333
is valid. You may leave off trailing zeros, or the leading zero if the value is less than one. - Output any pair of the three values as you prefer, just be sure to state which two and in what order.
The shortest code in bytes wins.
Examples
/\/\\/\//\\
→ Smoothness 0
, Chunkiness 0.7
, Brokenness 0.3
_/\\_/\\/__/\\\//_
→ Smoothness 0.29411764705
, Chunkiness 0.29411764705
, Brokenness 0.41176470588
//\\__/_\/
→ Smoothness 0.3333333
, Chunkiness 0.2222222
, Brokenness 0.4444444
Bonus question: Which do you prefer, smooth or chunky or broken squiggles?