Based on Chunky vs. Smooth Strings.
/\_/\/\__/\/\/\/\_/\_/\ 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
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.4444 chunky, and
Empty strings and strings with only one character have undefined values, all input will be at least 2 characters long.
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 between
0.6667, even things like
0.666637104. If the exact value is
1/3, any answer containing
0.3333is 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.
/\/\\/\//\\ → Smoothness
_/\\_/\\/__/\\\//_ → Smoothness
//\\__/_\/ → Smoothness
Bonus question: Which do you prefer, smooth or chunky or broken squiggles?