#!/usr/local/bin/gawk -E #@include "getopt.awk" @include "library.awk" BEGIN{ Optind = Opterr = 1 while ((c = getopt(ARGC, ARGV, "ds:")) != -1) { opts++ if(c == "s") { z = split(verifyval(Optarg), a, "|") if(z != 4) { usage() exit } } if(c == "d") { Dlevel = 1 } } if(opts == "") { usage() exit } dbg(1,"Given a set of three numbers: " strip(a[1]) " | " strip(a[2]) " | " strip(a[3]) ) print sauce( strip(a[1]), strip(a[2]), strip(a[3]), strip(a[4]) ) } # # Given a set of three numbers: 61 | 94 | 127 # Calculate: 127 - 61 = 66 # 66 * 0.5 = 33 # 61 + 33 = 94 # if 94 >= 94 return 1, else return 0 # Adjust the 0.5 upwards to be more leinent ie. return 1 more often # function sauce(count,realcount,numfound, factor, i,j,k) { if(! factor) factor = 0.4 if(int(realcount) < int(1) || int(numfound) < int(1) ) { dbg(1,"A. Break") return 0 } if(int(count) == int(-1001) ) { # estimate what it might be since we don't have an actual count if( int(numfound) <= int(500) ) { count = int((numfound / 2) * -1) } else { count = int(-250) } } if(int(count) == int(numfound)) { dbg(1,"B. Break") return 1 } if(int(realcount) == int(numfound)) { dbg(1,"C. Break") return 1 } if(int(count) < int(10) && int(count) > int(0)) { dbg(1,"D. Break") count = int(count * 10) realcount = int(realcount * 10) numfound = int(numfound * 10) } if(int(count) == int(realcount)) { if(int(count) >= int(numfound * factor)) { dbg(1,"E. Break") return 1 } if(int(count) == int(500) && int(numfound) < int(10000) ) { # Arbitrary 10,000 limit - over and probably runaway dbg(1,"E2. Break") return 1 } dbg(1,"F. Break") return 0 } # If 190/210 > 85% ie. realcount is within 15% of numfound if( int(percent(realcount,numfound)) >= int(85)) { dbg(1,"G. Break") return 1 } i = int(numfound - count) dbg(1," Calculate: " numfound " - " count " = " i) j = int(i * factor) dbg(1," " i " * " factor " = " j) k = int(count + j) dbg(1," " count " + " j " = " k) dbg(1," if " realcount " >= " k " return 1") if( int(realcount) >= int(k) ) return 1 return 0 } # # Print debug statement of certain level and lower # function dbg(level, str) { if(level <= Dlevel) { print str return } } function usage() { print "sauce: Print the result of the sauce algorithm." print "" print "Options: -s x-x-x-x Numbers to process" print " -d Print debug info" print "" print "Usage: sauce -s \"a|b|c|d\"" print " a = count, b = realcount, c = numfound, d = percentage" print "" print "Example: sauce -s \"61|94|127|0.4\"" print "" print "Output of 1 means good to go, 0 means reject" print "" exit }