Take a look at the puzzle given here:
https://trello.com/jobs/developer
Can you solve it with Macro Scheduler code?
I have a solution. But I'll let you puzzle over it first.
Puzzler Of the Week?
Moderators: JRL, Dorian (MJT support)
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Puzzler Of the Week?
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Re: Puzzler Of the Week?
With risk of being the first with something that can be improved....
Looking at the pseudo code provided, it seems that if you adjust the hash number (subtract 37^9 if you are looking at 9 letters) then what remains is to find the number (ie the digits) that with base 37 gives the adjusted hash number.
Looking at the pseudo code provided, it seems that if you adjust the hash number (subtract 37^9 if you are looking at 9 letters) then what remains is to find the number (ie the digits) that with base 37 gives the adjusted hash number.
Code: Select all
Let>the_string=acdegilmnoprstuw
Let>hash=910897038977002
Let>no_letters=9
//To check the provided test example
//Let>hash=680131659347
//Let>no_letters=7
//Adjust the hash to simplify the calculations
Let>adj=7*{Power(37,%no_letters%)}
Let>hash_adj=hash-adj
Let>rest=hash_adj
Let>result_string=
//Loop over letters and find the digits needed (using
//37 as base) to get to the adjusted hash number.
Let>ct=no_letters+1
While>ct>1
Let>ct=%ct%-1
Let>tmp={Power(37,(%ct%-1))}
If>%tmp%>%rest%
Let>digit=0
Else
Let>digit={Int(%rest%/%tmp%)}
Endif
MidStr>the_string,{%digit%+1},1,char
Let>result_string=%result_string%%char%
Let>rest={%rest%-%digit%*%tmp%}
EndWhile
//Check - Calculate the hash for the result
Gosub>Check,result_string
Ask>Spoiler Alert!! Do you want to see the secret word?,strResponse
If>strResponse=YES
MessageModal>Secret Word: %result_string%%CRLF%Hash: %check_res%
Else
MessageModal>Secret Word: ?%CRLF%Hash: %check_res%
endif
//A Sub to check the result
SRT>Check
Let>checkstring=Check_VAR_1
Let>res=7
Let>ct=0
While>ct<no_letters
Add>ct,1
MidStr>checkstring,ct,1,strSub
Position>strSub,the_string,1,nPos,TRUE
Let>res={%res%*37+%nPos%-1}
EndWhile
Let>check_res=res
Endif
END>Check
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Re: Puzzler Of the Week?
Interesting solution. I'm wondering if we should have put an embargo on solutions for a while until people had had a chance to figure it out themselves. But since you've posted your solution, here's mine:
The index of each character is the remainder after dividing the hash by 37 (because in the original the hash is calculated by multiplying by 37 and then adding index), and the next hash is the integer part.
Note that this solution does not need to know how many characters are in the resulting string.
We could shorten the above a little:
Any other solutions?
Code: Select all
Let>str=acdegilmnoprstuw
Let>h=910897038977002
Let>the_str=
Let>i=0
While>h>37
Let>i=i+1
Let>index={(%h% mod 37) + 1}
MidStr>str,index,1,char
Let>the_str=%char%%the_str%
Let>h={%h% div 37}
EndWhile
MessageModal>the_str
Note that this solution does not need to know how many characters are in the resulting string.
We could shorten the above a little:
Code: Select all
Let>str=acdegilmnoprstuw
Let>h=910897038977002
Let>the_str=
Let>i=0
While>h>37
Let>i=i+1
Let>the_str={Copy(%str%,(%h% mod 37) + 1,1) + %the_str%}
Let>h={%h% div 37}
EndWhile
MessageModal>the_str
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Re: Puzzler Of the Week?
ok, this is not mindblowing and it would be the same of what i have, but here is not much credits to score.
Honestly i must confess to have peeked at your solutions...
but Marcus, i do not get the function of
let>i=0
...
Let>i=i+1
why is it in your solution?
kind regards,
Djek
Honestly i must confess to have peeked at your solutions...
but Marcus, i do not get the function of
let>i=0
...
Let>i=i+1
why is it in your solution?

kind regards,
Djek
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Re: Puzzler Of the Week?
Good spot. It's not needed. A remnant of prior workings.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?