11.04.2013 Views

Guida avanzata di scripting Bash - Portale Posta DMI

Guida avanzata di scripting Bash - Portale Posta DMI

Guida avanzata di scripting Bash - Portale Posta DMI

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Appen<strong>di</strong>ce A. Script aggiuntivi<br />

# --------------------------------------------------------------------- #<br />

# On a rectangular grid, let each "cell" be either "living" or "dead". #<br />

# Designate a living cell with a dot, and a dead one with a blank space.#<br />

# Begin with an arbitrarily drawn dot-and-blank grid, #<br />

#+ and let this be the starting generation, "generation 0". #<br />

# Determine each successive generation by the following rules: #<br />

# 1) Each cell has 8 neighbors, the adjoining cells #<br />

#+ left, right, top, bottom, and the 4 <strong>di</strong>agonals. #<br />

# 123 #<br />

# 4*5 #<br />

# 678 #<br />

# #<br />

# 2) A living cell with either 2 or 3 living neighbors remains alive. #<br />

# 3) A dead cell with 3 living neighbors becomes alive (a "birth"). #<br />

SURVIVE=2 #<br />

BIRTH=3 #<br />

# 4) All other cases result in a dead cell for the next generation. #<br />

# ##################################################################### #<br />

startfile=gen0 # Read the starting generation from the file "gen0".<br />

# Default, if no other file specified when invoking script.<br />

#<br />

if [ -n "$1" ] # Specify another "generation 0" file.<br />

then<br />

if [ -e "$1" ] # Check for existence.<br />

then<br />

startfile="$1"<br />

fi<br />

fi<br />

ALIVE1=.<br />

DEAD1=_<br />

# Represent living and "dead" cells in the start-up file.<br />

# ---------------------------------------------------------- #<br />

# This script uses a 10 x 10 grid (may be increased,<br />

#+ but a large grid will will cause very slow execution).<br />

ROWS=10<br />

COLS=10<br />

# Change above two variables to match grid size, if necessary.<br />

# ---------------------------------------------------------- #<br />

GENERATIONS=10 # How many generations to cycle through.<br />

# Adjust this upwards,<br />

#+ if you have time on your hands.<br />

NONE_ALIVE=80 # Exit status on premature bailout,<br />

#+ if no cells left alive.<br />

TRUE=0<br />

FALSE=1<br />

ALIVE=0<br />

625

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!