Langton's ant: Difference between revisions
Content added Content deleted
m (added a ;Task; and ;Related task: (bold) headers, added other whitespace to the task's preamble.) |
(Added PowerShell) |
||
Line 4,428: | Line 4,428: | ||
(bye) |
(bye) |
||
</lang> |
</lang> |
||
=={{header|PowerShell}}== |
|||
{{works with|PowerShell|2}} |
|||
To simplify the steps within the loop, -1 and 1 are used to represent the binary state of the spaces in the grid. As neither state is now a default value, to simplify setting the starting states, an array of arrays is used instead of a two dimensional array. |
|||
<lang PowerShell> |
|||
$Size = 100 |
|||
$G = @() |
|||
1..$Size | ForEach { $G += ,( @( 1 ) * $Size ) } |
|||
$x = $y = $Size / 2 |
|||
# Direction of next move |
|||
$Dx = 1 |
|||
$Dy = 0 |
|||
# While we are still on the grid... |
|||
While ( $x -ge 0 -and $y -ge 0 -and $x -lt $Size -and $y -lt $Size ) |
|||
{ |
|||
# Change direction |
|||
$Dx, $Dy = ( $Dy * $G[$x][$y] ), -( $Dx * $G[$x][$y] ) |
|||
# Change state of current square |
|||
$G[$x][$y] = -$G[$x][$y] |
|||
# Move forward |
|||
$x += $Dx |
|||
$y += $Dy |
|||
} |
|||
# Convert to strings for output |
|||
ForEach ( $Row in $G ) { ( $Row | ForEach { ( ' ', '', '#')[$_+1] } ) -join '' } |
|||
</lang> |
|||
{{out}} |
|||
Default PowerShell console colors reverse the colors from black on white to white on dark blue. Most blank lines not included below. |
|||
<pre style="height:50ex;overflow:scroll"> |
|||
#################################################################################################### |
|||
################################################################################################ ## |
|||
############################################################################################### # |
|||
############################################################################################## # # |
|||
############################################################################################# # |
|||
############################################################################################ # # # # |
|||
########################################################################################### ## ## |
|||
############################## ########################################################## # ## ### |
|||
####################### ###### ######################################################## ## ### |
|||
###################### ## ## # # ###################################################### # ## ## # |
|||
##################### ## # ## ##################################################### ## ### ## |
|||
##################### # ## # ##################################################### # ## ## ### |
|||
############################# ###################################################### ## ### #### |
|||
####################### # # ##################################################### # ## ## ##### |
|||
####################### ## # # ################################################ ## ### ###### |
|||
####################### # # # #### #### ################################ # ## ## ####### |
|||
######################## ## # # # ## #### ## ############################## ## ### ######## |
|||
######################### # # #### ## # ############################ # ## ## ######### |
|||
######################### # ### #### ## ####### ### ###################### ## ### ########## |
|||
########################## # ### ## ## ###### ## ## #################### # ## ## ########### |
|||
########################## # ## ## ### # ####### ### ## ################## ## ### ############ |
|||
########################## # ## # # # # #### ## ################# # ## ## ############# |
|||
########################## ## ## ## # # # # #### # # # ## ########## ## ### ############## |
|||
########################## # ## ## ## # #### ### # ### ## # ######## # ## ## ############### |
|||
############################ # # ### ## ### ## ### ### # ###### ## ### ################ |
|||
######################## ### ### # ## # ### #### ##### # ## ## ################# |
|||
######################## ## ## # ## ## ### # ## # # # ##### #### ## ### ################## |
|||
######################## ### #### # ## # ##### # # ##### ### # ## ## ################### |
|||
####################### ### ### # #### # # # # # # ## ### ## ### #################### |
|||
####################### # ## # ## ### # # # ### # ## ### # ## ## ##################### |
|||
######################## ## #### ## ## ## ## # ###### ## ### ###################### |
|||
######################## #### #### ## ## # ## ### ## # ## ## ####################### |
|||
####################### ###### ### # ####### ### # ## # ## ### ######################## |
|||
####################### ### #### # # ### ###### # # # # ## # # ## ## ######################### |
|||
######################## ### # ## # ## ## # # # ##### ### ########################## |
|||
######################### ## ## # # ###### ## # ## #### # ## ## ########################### |
|||
########################### ##### ## # # ## # # # ## # ### ### ############################ |
|||
########################## ### # ## #### ## ### # ### ## ## ############################# |
|||
########################## # ## # ### ##### ## ## # # # ### ############################## |
|||
########################### ##### # ##### ## ### # ######### ## ############################### |
|||
############################ # #### ## # ### ### # # ### # ################################## |
|||
############################## # # ### # # # # # # # # # ############################## |
|||
############################# ### # # # # # ## # ### # ############################## |
|||
############################# # # # ### ## ## # # ### ##### ############################### |
|||
############################## ### ##### # # ## # ## # # ################################# |
|||
############################### ## # ## # ### # # ## ## # ################################# |
|||
################################### ## # ##### ##### ### ## # ################################ |
|||
################################### ####### ######### # # ## ################################### |
|||
##################################### #### ## ######### ## # ####################################### |
|||
##################################### # ############ ### ####################################### |
|||
###################################### ## ########## ## ######################################## |
|||
####################################### ## ## ######################################### |
|||
#################################################################################################### |
|||
</pre> |
|||
=={{header|Processing}}== |
=={{header|Processing}}== |