mIRC Home    About    Download    Register    News    Help

Topic Options
#264030 - 21/10/18 07:21 AM New Challenge! $palicount() - a palindrome counter
jaytea Offline
Fjord artisan

Registered: 23/02/06
Posts: 546
Please see the below replies for extra clarification and important updates to the rules!

I would like to share an old tradition with you, one that inspired myself and many of my fellow scripters over the years to cultivate our knowledge of mIRC's fun and quirky syntax. It's a tradition that bred generations of avid scripters, sparked valuable discussion, and provided many hours of satisfying thought to all those who partook.

I'm talking, of course, about mIRCscripting challenges.

I have one for you. It's easily stated, maybe even easily coded, but I hope and estimate it will be tricky to fashion a winning entry.

Name: $palicount() - a palindrome counter!
Difficulty: Easy
Criteria: Shortcode
Deadline: Wed 21 Nov 10:00 (10am) GMT

Description:

Your challenge is to create a custom identifier that returns the total number of palindromes in the input. This includes palindromes that are part of other, larger palindromes. Ignore palindromes less than 3 characters in length.

Examples:

$palicount(abcc) = 0

$palicount(abcdcb) = 2
The palindromes here are "bcdcb" and "cdc".

$palicount(racecarac) = 5
The palindromes here are "racecar", "aceca", "cec", "carac", and "ara".

$palicount(aaaaa) = 6
The palindromes here are "aaaaa", two occurrences in different positions of "aaaa", and three of "aaa".

$palicount(babbab) = 4
The palindromes here are "babbab", "bab", "bab", and "abba".

Input:

The input will be a single argument consisting of an alphanumeric string less than 100 characters.

Output:

A single integer N representing the number of palindromes found.

Judging:

Your alias will be judged based on its codesize as measured by the following link: https://jay-tea.github.io/mirc/countcode.html

Regex related functions in mIRC have come a long way over the years, and now provide scripters with a set of tools so powerful that it is no longer fair to allow them to compete with other methods.

So, there will be two winning categories: regex and non-regex. One scripter may compete in both of these categories with separate entries if they wish.

Rules:

- Your alias should be case sensitive, ie. $palicount(abA) = 0
- Your code will be loaded into the remote section of a clean mIRC instance.
- Additional code, such as an auxiliary remote alias, is allowed.
- No sockets.
- COM Object are permitted, but no calls that involve network communication.
- Your alias must run "cleanly", ie. not leave behind any hash tables, global variables, @windows, etc.
- Your alias must be able to run consecutively and return correct values if called more than once in the same line of code.
- This is not a lateral thinking exercise. I won't accept any exploitation of the rules or countcode script, no matter how creative.
- Similarly, your alias needs to terminate before I die.

Submitting:

Entries should be submitted to me through PM on these forums, or on IRC if you don't have an account.

Test alias:

To be made! Check back later.

By the way, I would be interested and greatly amused to see an entry from you, Khaled, if you happen to be reading this laugh


Edited by Khaled (23/10/18 10:27 AM)
_________________________
"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde

Top
#264035 - 21/10/18 07:48 PM Re: New Challenge! $palicount() - a palindrome counter [Re: jaytea]
Raccoon Offline
Hoopy frood

Registered: 18/02/03
Posts: 2504
> This is not a lateral thinking exercise. I won't accept any exploitation of the rules or countcode script, no matter how creative.

I always found the creative 'honorable mentions' a fulfilling part of these contests, and wouldn't mind seeing those rule-broke approaches as well, especially when they don't follow an expected path or reveal an interesting quark in the language. smile
_________________________
doin� things a particle can

Top
#264039 - 22/10/18 02:29 AM Re: New Challenge! $palicount() - a palindrome counter [Re: jaytea]
FroggieDaFrog Offline
Hoopy frood

Registered: 16/04/10
Posts: 907
Loc: USA
For COMs, is requiring a non-native library allowed? If not, then I'd suggest going with COMs not being allowed.

The reason is that what is native to my machine may not be native to yours. Not that its allowed, but a decent example is windows native MSXML. Some machines have v2, later versions have v3, win10 has v7. Each has different interfaces, quirks, etc.


And could you clarify requirements on brackets, as you made no mention of them. Are we allowed to have unclosed brackets?
Code:
alias example {
  ; ....


Edited by FroggieDaFrog (22/10/18 02:31 AM)
_________________________
I am SReject
My Stuff

Top
#264042 - 23/10/18 08:45 AM Re: New Challenge! $palicount() - a palindrome counter [Re: FroggieDaFrog]
jaytea Offline
Fjord artisan

Registered: 23/02/06
Posts: 546
IMPORTANT: RULE CLARIFICATION AND TEST ALIAS

I'd like to clarify a few of the rules and also use this opportunity to give you a test alias:

Code:
alias test_palicount {

  var %+ = scon 1 $(%test = %test, 0), %i = 1, %test, %time, %tot, %fail

  %+ jaytea 0
  %+ a 0
  %+ aa 0
  %+ aaA 0
  %+ 000 1
  %+ 0x00 1
  %+ 0x000 2
  %+ abcc 0
  %+ abcdcb 2
  %+ racecarac 5
  %+ aaaaa 6
  %+ aaAaa 2 
  %+ aaAAAaa 3
  %+ babbab 4
  %+ babbabbab 10
  %+ madamadam 8
  %+ madammadam 8
  %+ madamracecar 5
  %+ donaldtrump 0
  %+ amanaplanacanalpanama 16
  %+ 00000000000000000000000000000000000000000000000000 1176
  %+ 01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101 2352
  %+ aAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaA 2352
  %+ 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 4753
  %+ aaasdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfbbb 2
  %+ qlgapbhfcdyjkygrodepkwypocggteqvxpjgajvbcuvkltflpjbsmbwirysgqejsgtverbapiqvvjyolzyvsbwgqcsjxrpqccno 0

  echo 3 -eag Starting test:
  %time = $ticks

  while ($gettok(%test, %i, 32) != $null) {
    var %in = $v1, %out = $gettok(%test, $calc(1 + %i), 32)
    if ($palicount(%in) != %out) {
      echo 4 -ag Failed on $!palicount( $+ %in $+ ) (returned $v1 instead of %out $+ )
      inc %fail
    }
    inc %tot
    inc %i 2  
  }
  %time = $calc($ticks - %time)

  echo $iif(%fail, 4 -eag Failed. Only passed, 3 -eag Success! Passed) $calc(%tot - %fail) out of %tot tests in %time $+ ms

}


Just load and use /test_palicount to test out your alias

Now, rules.. some of you have made some good points and raised interesting questions so I'll attempt to clarify them all here:

1. Code will be tested on mIRC 7.52 (thanks Ouims :P)

2. COM: let us now say COM is now entirely disallowed. The rule in my post comes from a time when various scripters were learning and playing around with COM objects, and so I wanted to grant them the freedom to pursue methods that were almost certainly not going to be conducive to winning.

3. {} Braces: please include the final trailing brace. It's only 1 byte, everyone knows the trick by now, and I'll be adding it to your code if you omit it :P

4. Identifier warning will be disabled. Go nuts :P

I think that's it, but stay tuned to this topic in case there are any further updates. Have fun!
_________________________
"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde

Top
#264216 - 10/11/18 05:31 AM Re: New Challenge! $palicount() - a palindrome counter [Re: jaytea]
jaytea Offline
Fjord artisan

Registered: 23/02/06
Posts: 546
Less than two weeks to go - get your entries in!
_________________________
"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde

Top
#264292 - 17/11/18 08:16 AM Re: New Challenge! $palicount() - a palindrome counter [Re: jaytea]
jaytea Offline
Fjord artisan

Registered: 23/02/06
Posts: 546
OK, with 4 days to go, I believe it's time for a quick poke and an update with the list of competitors so far.

In no particular order:

Non-regex:
  • Degausser aka Jamie
  • FroggieDaFrog aka SReject
  • Tefad
  • maroon
  • Talon
  • Kol
  • Sat aka Saturn

Regex:
  • Raccoon
  • maroon

If you did submit and don't see your name on these lists (unlikely), let me know!

Also, no sign of Khaled yet. Perhaps he's waiting til the last minute?? laugh


Edited by jaytea (17/11/18 11:43 AM)
_________________________
"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde

Top
#264330 - 21/11/18 05:34 PM Re: New Challenge! $palicount() - a palindrome counter [Re: jaytea]
jaytea Offline
Fjord artisan

Registered: 23/02/06
Posts: 546
Oh goodness I totally forgot to post the results earlier! It'll have to wait til tomorrow since they're all on my work PC. Sorry guys. Submission is closed now :P
_________________________
"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde

Top
#264337 - 22/11/18 06:15 AM Re: New Challenge! $palicount() - a palindrome counter [Re: jaytea]
jaytea Offline
Fjord artisan

Registered: 23/02/06
Posts: 546
Results

I 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)

Code:
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)

Code:
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)

Code:
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)

Code:
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)

Code:
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)

Code:
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)

Code:
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)

Code:
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)

Code:
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 smile

Thank you to everyone for competing!
_________________________
"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde

Top
#264338 - 22/11/18 07:30 AM Re: New Challenge! $palicount() - a palindrome counter [Re: jaytea]
Raccoon Offline
Hoopy frood

Registered: 18/02/03
Posts: 2504
Say what? Saturn didn't win??! Who's this Degausser kid and how dare he win!!?

(btw, you missed my slightly-shortened entry somehow. no big deal though.)
Code:
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)))

((yes. i can only think in $regsubex() anymore. this is who i've become))
_________________________
doin� things a particle can

Top
#264341 - 22/11/18 08:07 AM Re: New Challenge! $palicount() - a palindrome counter [Re: jaytea]
Sat Offline
Hoopy frood

Registered: 19/04/04
Posts: 831
Loc: The Netherlands
Congratulations to Degausser, and a big thanks to jaytea for organizing the challenge!
_________________________
Saturn, QuakeNet staff

Top
#264348 - 22/11/18 09:18 AM Re: New Challenge! $palicount() - a palindrome counter [Re: jaytea]
Degausser Offline
Self-satisified door

Registered: 03/08/17
Posts: 4
Hurray, hitting the big time!

Thank you Jaytea for taking the time in hosting this challenge, and giving everyone else a shot at winning xD

Thanks to everyone who participated as well, It's nice to see an increasing level of interest in these challenges, even if they are few and far between.


Edited by Degausser (22/11/18 09:19 AM)

Top
#264351 - 22/11/18 10:11 AM Re: New Challenge! $palicount() - a palindrome counter [Re: Raccoon]
jaytea Offline
Fjord artisan

Registered: 23/02/06
Posts: 546
Originally Posted By: Raccoon
Say what? Saturn didn't win??! Who's this Degausser kid and how dare he win!!?

(btw, you missed my slightly-shortened entry somehow. no big deal though.)
Code:
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)))

((yes. i can only think in $regsubex() anymore. this is who i've become))


Sorry my bad!! I updated it
_________________________
"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde

Top