« Caption contest... | Main| New Workplace product coming soon... »

A Domino formula puzzler...

Category
Remember my little programming challenge previously, well here's another one, which I intend to use and expand on as a cool technote for the blog if someone posts a good solution to this puzzle.

The challenge:
You have a field that contains a hexadecimal number, it could be a large hexadecimal number, lets say up to 32 characters long (you see where this is going?). Write an @formala that will convert the hexadecimal number to Base-36. Yep base 36. So where as base 16 (HEX) goes up to "F" Base 36 goes up to "Z", so for example the Hex Number 27 is 13 in base 36. Just to be complete, write the inverse formula that converts it back from Base-36 to Base-16 (HEX)

Have fun!

Comments

Gravatar Image1 - Cool challenge, bonus points if you can do it without looping?

Too bad I don't have a Designer client installed. I just now tried to write a solution without documentation, but I couldn't remember enough @functions. Bah!

Gravatar Image2 - Here you go Damien, documentation..

http://doc.notes.net/domino_notes/7.0/help7_designer.nsf

Gravatar Image3 - I keep checking back here for the answer only to be dissapointed every time.

This is not something that I want to burn a day on, but, I am curious as to how one would do such a task.

My thoughts were around automating the process of manual long division for the conversion, but, I was stuck on doing hex math maually. Then my attention whet elseware.

Maybe instead of doing the work in Lotus formula language, it could be done in Fabric?

Gravatar Image4 - I outlined a solution in your follow-up post, but I left the details as an exercise for the class

Gravatar Image5 - I have written two pieces of (untested) @formula code: One which converts a hex string to a Number and another which converts a number to a base-36 string. I don't think it works for 32 character long hex strings, because of limitations in the representation of Numbers on a computer, but the code could be used a starting point.

REM {Hex to Num};
Num := 0;
@For(i:=1; i<=@length(Hex); i:=i+1;
Num := Num*16+@TextToNumber(@Replace(hex; "0":::"F"; "0":::"15"));

REM {"0":::"X" is a shorthand for "0":"1":"2":..."X"};

REM {Num to Base36};
Base36 := "";
@DoWhile(
m := @Modulo(Num; 36);
Base36 := @Replace(@Text(m); "0":::"36"; "0":::"Z") + Base36;
Num := @Integer(Num/36);
Num > 0);

Gravatar Image6 - What about a challenge for calculating the MD5 checksum of a string using @Formula?

Post A Comment

:-D:-o:-p:-x:-(:-):-\:angry::cool::cry::emb::grin::huh::laugh::rolleyes:;-)