Skip to content

Instantly share code, notes, and snippets.

@sillyfellow
Last active February 8, 2016 13:09
Show Gist options
  • Save sillyfellow/80a99061deb3f3992c29 to your computer and use it in GitHub Desktop.
Save sillyfellow/80a99061deb3f3992c29 to your computer and use it in GitHub Desktop.
#!/bin/bash -
#===============================================================================
# FILE: Mind Trainder
# USAGE: ./mind_trainer.sh
#
# DESCRIPTION: Train your mind to quickly find your income as a freelancer.
# AUTHOR: Dr. Sandeep Sadanandan (sillyfellow), [email protected]
#===============================================================================
set -o nounset # Treat unset variables as an error
function my_random()
{
echo $(shuf -i $1-$2 -n 1)
}
# Of course, you could have rates like 55.5 per hour.
# But I am going with multiples of five.
function five_floor()
{
NUMBER=$1
ffREM=$((NUMBER % 5))
echo $((NUMBER - ffREM))
}
function check_correctness()
{
EXPECTED=$1
begin_time=`date +%s`
read COMPUTED < /dev/tty
end_time=`date +%s`
TIMETAKEN=$((end_time - begin_time))
CORRECTNESS="Wrong!! (expected: $EXPECTED)"
[ $EXPECTED -eq $COMPUTED ] && CORRECTNESS="Correct!!!"
echo "You took $TIMETAKEN, and you were completely $CORRECTNESS"
}
function evaluate_hours()
{
DAYS=$1
echo "Find the total hours of work in $DAYS days"
check_correctness $((DAYS * 8))
}
function evaluate_netto()
{
DAYS=$1
RATE=$2
echo "Now tell me your netto at a rate of $RATE!"
check_correctness $((DAYS * 8 * RATE))
}
function evaluation_round()
{
DAYCOUNT=$(my_random 8 18)
HOURRATE=$(five_floor $(my_random 70 131))
evaluate_hours $DAYCOUNT
evaluate_netto $DAYCOUNT $HOURRATE
}
while true
do
evaluation_round
echo ""
done
@sillyfellow
Copy link
Author

Of course, no real error checking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment