Puzzler Of the Week?

Anything Really. Just keep it clean!

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
Marcus Tettmar
Site Admin
Posts: 7378
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Puzzler Of the Week?

Post by Marcus Tettmar » Thu Jul 24, 2014 3:47 pm

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.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

hagchr
Automation Wizard
Posts: 327
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: Puzzler Of the Week?

Post by hagchr » Thu Jul 24, 2014 8:52 pm

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.

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

User avatar
Marcus Tettmar
Site Admin
Posts: 7378
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Puzzler Of the Week?

Post by Marcus Tettmar » Thu Jul 24, 2014 9:39 pm

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:

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

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
Any other solutions?
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Djek
Pro Scripter
Posts: 147
Joined: Sat Feb 05, 2005 11:35 pm
Location: Holland
Contact:

Re: Puzzler Of the Week?

Post by Djek » Sun Jul 27, 2014 11:19 am

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? :roll:

kind regards,
Djek

User avatar
Marcus Tettmar
Site Admin
Posts: 7378
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Puzzler Of the Week?

Post by Marcus Tettmar » Sun Jul 27, 2014 11:59 am

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?

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts