An adventure down a side road

 Not all side roads lead to nowhere.  Sometimes the fun of an off the beaten track road leads you to new insights.

While trying to decide which way to turn next in my quest to re-write the company application in Objectscript, an email from Global Masters arrived.  After guessing (incorrectly) on the Quiz (it was a health share related question I know nothing about but a chance for 15 points is worth a guess), I came across a new codeGolf challenge.  I've seen these before but since I didn't have the first clue about ObjectScript, I always skipped them.

Today seemed like a good day to learn a little more ObjectScript and the challenge was interesting and not too complicated.


Write a class method to accept two strings and determine if they are an anagram.  The challenge is to write it in the fewest number of characters - which usually leads to less than maintainable/human readable code.  I wasn't after the prize of fewest characters; I was on a quest to write a functional class method.

Here is my less than elegant solution (it passed all the unit tests provided)

ClassMethod Detector(a As %String, b As %String) As %Boolean

{

  SET a=$CHANGE(a," ","")

  SET a=$ZCVT(a,"l")

  SET b=$CHANGE(b," ","")

  SET b=$ZCVT(b,"l")

  SET c = ""

  FOR i = 1 :1 :$L(a)

  {

    SET p = $F(b,$E(a,1))

    if p { SET $E(b,p-1)="" } else { set c=c_$E(a,1) }

    set $E(a,1)=""

  }

  if ($L(a) + $L(b) + $L(c) ) { q 0 } else { q 1 }

}


There are six old challenges that I'm planning to complete just for the experience.  No prize - except for more experience with ObjectScript.

Comments

Popular posts from this blog

The Importance of an Error Message

Day 4 of 2024

The rabbit hole of my birthday