1 Problem, 4 More Programming Languages (Python vs Kotlin vs F# vs Wolfram)
source link: https://www.youtube.com/watch?v=6-mk6OpcUdM
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
1 Problem, 4 More Programming Languages (Python vs Kotlin vs F# vs Wolfram)
20 Comments
Thanks for the updated video and the 4 more programming languages! Btw. in Kotlin, scan is deprecated and is replaced by runningReduce and runningFold. Also, you can reference the plus-operator with Int::plus. Your Kotlin solution could when look like this :
fun maxDepth(s: String) = s .map { when (it) { '(' -> 1; ')' -> -1; else -> 0 } } .runningReduce(Int::plus) .max()
Read more 1 week ago (edited)
As of python 3.10 Guido has approved structured pattern matching (after blocking it a decade and a half 🙈)!
I think it makes the imperative approach surprisingly readable!
def max_depth(s:str) -> int: result = 0 depth = 0
for char in s: match char: case '(': depth += 1 case ')': depth -= 1 result = max(depth, result)
return result
Read more 6 days ago (edited)
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK