How to resolve the algorithm Balanced brackets step by step in the Arturo programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Balanced brackets step by step in the Arturo programming language

Table of Contents

Problem Statement

Task:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Balanced brackets step by step in the Arturo programming language

Source code in the arturo programming language

isBalanced: function [s][
	cnt: 0
 
	loop split s [ch][
		if? ch="]" [
			cnt: cnt-1
			if cnt<0 -> return false
		]
		else [
			if ch="[" -> cnt: cnt+1
		]
    ]

    cnt=0
]
 
loop 1..10 'i [
	str: join map 0..(2*i)-1 [x][ sample ["[" "]"]]
	
	prints str

	if? isBalanced str  -> print " OK"
	else 				-> print " Not OK"
]


  

You may also check:How to resolve the algorithm Radical of an integer step by step in the C++ programming language
You may also check:How to resolve the algorithm Reduced row echelon form step by step in the Java programming language
You may also check:How to resolve the algorithm Check output device is a terminal step by step in the Raku programming language
You may also check:How to resolve the algorithm Table creation/Postal addresses step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Sort using a custom comparator step by step in the Euphoria programming language