Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ##Jonglez avec les densités comme vous voulez (résultat de RANDOM un peu binaire)
- function gen {
- perl << END
- print "$2.ox\n";
- for (my \$i = 0; \$i < $2; \$i++) {
- for (my \$j = 0; \$j < $2; \$j++) {
- if (int(rand($2) * 2) < $3) {
- print "o";
- }
- else {
- print ".";
- }
- }
- print "\n";
- }
- END
- }
- cd `dirname $0`;i=1;j=1;k=1;x=0
- if [[ -z $2 ]] || [ ! -f $1 ]; then echo -e "usage: `basename $0` bsq nb \"c\" \nPS: \
- More grids More size More time\nPSPS: the script create only valid grids" ; exit ; fi
- if [[ ! -z $3 ]]; then rep=$3 ;else rep=" "; fi
- if [ ! -d grids ]; then mkdir grids;fi
- echo "Part 1: gen $2 grids" ; sleep 1
- coordx=(); coordy=(); density=()
- while [ $x -le $2 ]; do
- gen $i $j $k > grids/pl$x
- echo -e "\r$((100 * $x / $2))%\c";k=$((RANDOM / 1000))
- j=$((i + 10));i=$((i + 50 + x));coordx[$x]=$i;coordy[$x]=$j
- density[$x]=$k;((x++))
- done
- echo -e "\nPart 2: testing" ; sleep 1
- # the tricky part: since we removed F..
- x=1
- result=()
- while [ $x -le $2 ]; do
- echo "Grid $x"
- echo -e "`cat grids/pl$x | time -f "%e seconds" $1 2>&1 | tee grids/result | \
- grep -v "seconds" | sed "s/o/\\\\\033[0;33mo\\\\\033[0m/g" | \
- sed "s/x/\\\\\033[0;32mx\\\\\033[0m/g" | tr "." "$rep"`"
- result[$x]="`cat grids/result | tail -n1 | cut -d' ' -f1`"
- ((x++))
- done
- x=1
- echo -e "\nPerfs :"
- while [ $x -le $2 ];do
- res=`echo ${result[$x]} | cut -d. -f1 | perl -pe 's/[^\x20-\x7f]//g'` #le petit ^C qui se balade :P
- if [ $res -eq 0 ]; then color="\033[0;32m"
- elif [ $res -le 2 ]; then color="\033[0;33m"
- else color="\033[0;31m" ; fi
- echo -e "Grid $x - x:${coordx[$x]} y:${coordy[$x]} dens:${density[$x]}\t=>$color ${result[$x]}s\033[0m"; ((x++))
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement