Thank you to everyone who participated in this challenge.
As a number of you who participated knew, there was a number of problems you could run into when coding this challenge. Initial thoughts were this; recursively going through the boxes, count how many sides each box has, if it has 3, increase counter, manipulate the bit to give the box the missing side and carry on in the loop. This would cause problems when giving a side that completes another box next to it giving it 4 sides. Next time in the loop it would see that box has 4 sides and wouldn't count it.
As figured out, one way around it was to count the number of boxes with 4 sides prior to entering the loop, then again at the end outside the loop. Then using the formula:
(new calculated boxes with 4 sides) - (old boxes with 4 sides) = new boxes
Then add this onto the result. It's a bit of a dirty technique really, but it was useful for some. I would be interested in knowing any other struggles you had to overcome when coding your alias in the forum.
Now onto the results...
There was a total of 12 non regex-entries of which 7 were valid and 5 invalid. In the regex section there were 2 valid entries.
alias c return $calc((1+$2+ %n)*($1+ %k % %n)+1+%k /%n +(1+%n)^2*$2)
alias s bset -t &a $1-
alias y {
s $c 1
s $c(1) 1
s $c(,1) 11
%k = -1
}
alias w {
%k = 0
while %k < $calc(%n ^2) {
if $count($bvar(&a,$c) $bvar(&a,$c(1)) $bvar(&a,$c(,1),2),9) = $1 $2 % $+ r
inc %k
}
}
alias boxes {
%r = 0
s 1 $1 $2
%n = $numtok($2,32)
w 4 dec
w 3 y
w 4 inc
return %r
alias c inc %c $gettok(%r,$1,2)
alias p %ø = $puttok(%ø,1,$1,2)
alias boxes {
%ø = $replace($1-,1,1,0,0)
tokenize 32 $2
%n = 0
:a
%s = $0 ^ 2
%r = %ø
while %s {
var %a %s + $0,%b $calc($0 ^2-(1-%s)/$0 +%a),%d %b + 1
%c =
c %s
c %a
c %b
c %d
if %c < 4 var % $+ %s 1
if %c > 2 && $(,% $+ %s) {
p %s
p %a
p %b
p %d
inc %n
dec % $+ %s
}
dec %s
}
if %r = %ø return %n
goto a
* Failed on test: 0000000 1111111 1000011 1001000 0000001 0011110 1111111 1000000, 11011011 01011010 01100111 01111001 01100010 01000010 01111011 = 15 should of returned 28
Alias Boxes {
var %w00a = $1
var %w00b = $2
var %s001 = 0
var %s002 = 0
var %s003 = 0
:again
var %w001 = %w00a
var %w002 = %w00b
var %w003 = $numtok(%w001,32)
var %w004 = $numtok(%w002,32)
var %w006 = 1
while (%w006 <= %w004) {
var %w005 = 1
while (%w005 <= $len($gettok(%w001,1,32))) {
var %c001 = $dim(%w001,%w006,%w005,0)
var %c002 = $dim(%w001,%w006,%w005,1)
var %c003 = $dim(%w002,%w006,%w005,0)
var %c004 = $dim(%w002,%w006,%w005,0,1)
var %w007 = $calc(%c001 + %c002)
var %w008 = $calc(%c003 + %c004)
var %w009 = $calc(%w007 + %w008)
var %w011 = $+(%w011,%w009)
var %r001 = $iif(%w009 = 3,1,%c001)
var %r002 = $iif(%w009 = 3,1,%c002)
var %r003 = $iif(%w009 = 3,1,%c003)
var %r004 = $iif(%w009 = 3,1,%c004)
var %r005 = $+(%r005,%r001)
var %r006 = $+(%r006,%r002)
var %r007 = $+(%r007,%r003)
var %r008 = $+(%r008,%r004)
if (%s001 = 0) {
if (%w009 = 4) { inc %s002 }
}
if (%s001 = 1) {
if (%w009 = 4) { inc %s003 }
}
inc %w005
}
var %w012 = %w012 %w011
var %r009 = %r009 %r005
var %r010 = %r010 %r006
var %r011 = %r011 $+($left(%r007,1),%r008)
var %r005
var %r006
var %r007
var %r008
var %w011
inc %w006
}
var %r012 = $gettok(%r009,1,32) %r010
var %r013 = $+(%r012,$chr(44),%r011)
if (%s001 = 0) { inc %s001 | var %w00a = %r012 | var %w00b = %r011 | goto again }
echo $color(info) *** %r013 %s003
return $calc(%s003 - %s002)
}
Alias Dim {
var %data = $mid($gettok($1,$iif($4 = 1,$calc($2 + 1),$2),32),$iif($5,$calc($3 + 1),$3),1)
return %data
}