#!/bin/bash

generating=true
number_count=0
arguments=""
last_number=0

#number 1
number_count=$((number_count+1))
number=$(((RANDOM % 100)+1))
arguments="$arguments $number"
last_number=$number

#number 2
number_count=$((number_count+1))
number=$(((RANDOM % 100)+1))
arguments="$arguments $number"
last_number=$number

while [ "$generating" = "true" ]
do
    if [ $number_count -ge 2 ]
    then
	choice=$((RANDOM % 2))
	if [ $choice = 0 ]
	then
	    #operator
	    operator=$((RANDOM % 4))
	    if [ $operator = 0 ]
	    then
		number_count=$((number_count-1))
		arguments="$arguments +"
	    elif [ $operator = 1 ]
	    then
		number_count=$((number_count-1))
		arguments="$arguments -"
	    elif [ $operator = 2 ]
	    then
		number_count=$((number_count-1))
		arguments="$arguments *"
	    elif [ $operator = 3 ]
	    then
		if [ $last_number -ne 0 ]
	        then
		    number_count=$((number_count-1))
		    arguments="$arguments /"
		fi
	    fi
	else
	    #number
	    number_count=$((number_count+1))
	    number=$(((RANDOM % 100)+1))
	    arguments="$arguments $number"
	    last_number=$number
	fi
    else
	choice=$((RANDOM % 2))
	if [ $choice = 0 ]
	then
	    generating=false
	else
	    #number
	    number_count=$((number_count+1))
	    number=$(((RANDOM % 100)+1))
	    arguments="$arguments $number"
	    last_number=$number
	fi
    fi
done
echo "$arguments"


