Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
ĠvLʁf+Ġvẏf+
Try it Online!Try it Online!
-1 thanks to lyxal
Ġ # Group runs of identical chars vL # Length of each ʁfvẏf # 0...n each and flatten + # Add to input
Port of caird coinheringaahing's answer.
ĠvLʁf+
Try it Online!
Ġ # Group runs of identical chars vL # Length of each ʁf # 0...n each and flatten + # Add to input
Ġvẏf+
Ġ # Group runs of identical chars vẏf # 0...n each and flatten + # Add to input
Port of caird coinheringaahing's answercaird coinheringaahing's answer.
Port of caird coinheringaahing's answer
KƛṫOnt+ĠvLʁf+
K Ġ # Prefixes ƛ Group runs of #identical Map...chars OvL # Count occurencesLength of.. ṫ # Last itemeach O ʁf # In0... ṫ # Alln buteach lastand itemflatten nt+ + # AddedAdd to numberinput
KƛṫOnt+
K # Prefixes ƛ # Map... O # Count occurences of.. ṫ # Last item O # In... ṫ # All but last item nt+ # Added to number