Simple Bean Machine program done in Powershell

Powershell Header

In the last article I posted the C++ Code for a simple Bean Machine output. Now I did the same in Powershell. I know this is not really a fantastic Powershell script, but its good to show others how things get done in Powershell.

Like in the C++ bean machine it works like this:

Bean MachineAnd the Output should look like this:

Bean Machine outputAnd here is how you do this in Powershell:

#Config
[int]$ballCount = 100
[array]$box = @(0, 1, 2, 3, 4, 5)
[string]$line = " +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-->"
[string]$numbers = " 0     5     10     15     20     25     30     35     40     45     50"
[object]$random = New-Object  System.Random

#count
for([int]$i = 0; $i -lt $ballCount; $i++){
	[int]$counter = 0

	for([int]$j = 0; $j -lt 5; $j++){
	$leftorright = $random.next(0,2)
	$counter = $counter + $leftorright
	}
	$box[$counter] = $box[$counter] + 1
}

#Output
Write-Host $numbers
Write-Host $line
for ([int]$t = 0; $t -lt 6; $t++){
	[string]$Statusline = ""
	for ([int]$u = 0; $u -lt $box[$t]; $u++){
		[string]$Statusline += "#"
		}
	Write-Host $t "|" $Statusline $box[$t]
	Write-Host $line
}

Related Posts:

2 thoughts on “Simple Bean Machine program done in Powershell

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>