Corewars program…

Written by

in

The following corewars program is a statistically optimal program, which attacks a midpoint of a program, given the number of programs, coresize, average program size, and then their standard deviation. It’s just using pre-defined numbers, generated from a shell script…

r: data 0

coresize / nprogs = 273

avg prog size: 35.65

std dev: 31.49

thus, desired search points:

[ |1dev| (midpoint) |1dev| ]

make next midpoint here: ---------------------> ^^^^^^

midpoint = interval / 2 = 136

main: move 0, [r] # midpoint
add -31, r
move 0, [r] # left 1dev
add 62, r
move 0, [r] # right 1dev
add 74, r

jump main

Here is the corresponding shell script:

#!/bin/sh

# this calculates statistics from any list of numbers.

# in particular, it's used to calculate the number of lines for each
# corewars program.

# wc -l *.cw ... which is then parsed by cut -d ' ' -f [1,2,3,4,5,6]
# to get all the tokens, and then "grep -v" to remove the text,
# since the output of wc is not cut-friendly.

# expavg is actually the average from a previous calculation, but
# since this requires 2 passes, i couldn't be bothered. just
# alter it yourself for the 2nd pass.


r=0
sum=0
avg=0
numprogs=0
expavg=35

while read r ; do

	numprogs=`expr $numprogs '+' 1`

	avg=`expr $r '+' $avg`

	r=`expr $r '-' $expavg`

	s=`expr $r '*' $r`

	sum=`expr $sum '+' $s`

done

echo "numprogs = $numprogs"
echo "avg = $avg / numprogs"
echo "dev = sqrt ( $sum / numprogs )"

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *