OP
Fjord artisan
Joined: Feb 2006
Posts: 523 |
ResultsI was very impressed with the variety of methods, not to mention the ingenuity displayed! Without further ado, the results: Non-Regex (7 entrants):And the winner is.... Degausser (aka Jamie)!1. Degausser (158 bytes)
alias palicount {
var %x 99,%c 0
while %x {
var %s %s $+ $mid($1,%x,1),%y $len(%s)
while %y > 2 {
if (* $+ $mid($1,%x,%y) iswmcs %s) inc %c
dec %y
}
dec %x
}
return %c
}
2. Sat (167 bytes)
alias palicount {
var %i 2.9, %t 0
while %i < $len($1) {
var %j -.1
while ($mid(#$1,$calc(%i -%j),1) === $mid($1,$calc(%i +%j),1)) inc %j
inc %t $or(%j)
inc %i .5
}
return %t
}
3. maroon (172 bytes)
alias palicount {
var %c 0,%p 97
while %p {
var %o %p,%r
while $mid($1,%o,1) != $5 {
%r = $v1 $+ %r
if ???* iswm %r && (%r $+ * iswmcs $mid($1,%p)) inc %c
inc %o
}
dec %p
}
return %c
}
4. Tefad (189 bytes)
alias palicount {
var %s $len($1),%i %s,%o 0
while %i {
var %d 2
while %d {
var %c %d - 1,%h %i + %c,%l %i - 1
while %l && %h <= %s && $mid($1,%h,1) === $mid($1,%l,1) {
inc %o %c
inc %h
dec %l
%c = 1
}
dec %d
}
dec %i
}
return %o
}
5. Kol (190 bytes)
alias palicount {
var %x 99,%r 0
while %x {
var %y 99
while %y {
var %t $mid($1@,%x,%y),%z 99,%c
while %z {
%c = %c $+ $mid(%t,%z,1)
dec %z
}
if $poscs(%t %t,%c,2) > 4 {
inc %r
}
dec %y
}
dec %x
}
return %r
}
6. Talon (209 bytes)
alias palicount {
var %a 0,%d 0
while %a < $len($1) {
var %b 3,%c $v2 - %a
inc %a
while %b <= %c {
var %y $mid($1,%a,%b),%z $len(%y),%x
while %z {
%x = %x $+ $mid(%y,%z,1)
dec %z
}
if (%y === %x) inc %d
inc %b
}
}
return %d
}
7. FroggieDaFrog (273 bytes)
alias -l c {
var %o
while ($calc($2 -%o) > 0 && $mid($1,$v1,1) === $mid($1,$calc($2 +%o +$3),1)) {
inc %o
}
return $calc(%o -1)
}
alias palicount {
var %i 1,%r 0
while (%i < $len($1)) {
inc %r $c($1,%i)
if ($mid($1,%i,1) === $mid($1,$calc(1+%i),1)) inc %r $c($1,%i,1)
inc %i
}
return %r
}
Regex (2 entrants):And the winner is.... maroon!1. maroon (173 bytes)
alias palicount {
var %c 0,%p 97
while %p {
var %o %p,%r
while $mid($1,%o,1) != $5 {
%r = $v1 $+ %r
if $regex($mid($1,%p),^ $+ %r) && (???* iswm %r) inc %c
inc %o
}
dec %p
}
return %c
}
2. Raccoon (214 bytes)
ALIAS palicount return $calc($regsubex($x($1),/(.)(?=(.*)$)/g,$y($x(\1\2)) +))
ALIAS x return $regsubex(x,$1,/(.)/g,$mid(\A,-\n,1))
ALIAS y return $len($regsubex(y,$1,/(.)(?=(.+\1)$)|./gF,$iif(\1\2 === $$x(\1\2),1)))
Raccoon should get accolades for having a far more regexy method  Thank you to everyone for competing!
"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
|