The Unofficial Macro Scheduler Puzzler #9

Anything Really. Just keep it clean!

Moderators: Dorian (MJT support), JRL

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

The Unofficial Macro Scheduler Puzzler #9

Post by JRL » Thu May 15, 2014 8:58 pm

If you follow the Macro Scheduler forums you may have seen this thread about how to convert a decimal integer to binary integer. This puzzler is for the reciprocal of that. Who can write a Macro Scheduler script to convert a binary integer to a decimal integer? 30 points for the solution our panel of judge likes the best. Entries end sometime May 23, 2014.

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

Re: The Unofficial Macro Scheduler Puzzler #9

Post by Marcus Tettmar » Fri May 16, 2014 1:50 pm

Thanks JRL. I look forward to seeing some solutions. I have two of my own but I'll hold them back for now. :D
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: 148
Joined: Sat Feb 05, 2005 11:35 pm
Location: Holland
Contact:

Re: The Unofficial Macro Scheduler Puzzler #9

Post by Djek » Fri May 16, 2014 6:59 pm

haha !
If you hold them to your own, you cant claim to be the first !
:D

Wel here's my script

Code: Select all

//Bin-to-Dec
//Djek
let>BinVal=10111010001000010
let>DecVal=0
let>BitExp=0
Length>BinVal,LBinval
let>LBinval1=LBinVal
Repeat>LBinVal1
  MidStr>%BinVal%,%LBInval1%,1,RPos
  if>Rpos=1
    let>DecVal=%DecVal%+{2^%BitExp%}
  endif
  let>LBinVal1=LBinVal1-1
  let>BitExp=BitExp+1
Until>LBinVal1=0
MessageModal>Binary = %binval%%CRLF%Decimal = %Decval%

come on, guys, dont let this make you shivering and being afraid to submit your solution!
8)
Kind regards,
Djek

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: The Unofficial Macro Scheduler Puzzler #9

Post by JRL » Fri May 16, 2014 9:14 pm

Great job Djek! Thank you for your contribution. We'll see if you've struck fear into the hearts of all the other forumites or if there will be others who dare to take the challenge.

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

Re: The Unofficial Macro Scheduler Puzzler #9

Post by hagchr » Sat May 17, 2014 11:16 am

Another way to Rome...?

Code: Select all

Let>BinVal=10111010001000010
RegEx>\d,BinVal,0,Matches,NumMatches,,,
Let>DecVal=0
Let>ctr=0
While>ctr<NumMatches
    Let>ctr=%ctr%+1
    Let>tmp=Matches_%ctr%
    Let>tmp1={Power(2,%NumMatches%-%ctr%)}
    Let>DecVal=%DecVal%+{%tmp%*%tmp1%}
EndWhile
MessageModal>Binary = %BinVal%%CRLF%Decimal = %Decval%

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: The Unofficial Macro Scheduler Puzzler #9

Post by JRL » Sat May 17, 2014 7:52 pm

Good job hagchr! You weren't frightened off. From 12 working lines down to 9 working lines.

Anyone see a way to do it in 8 lines? 7?? 6??? 5????

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

Re: The Unofficial Macro Scheduler Puzzler #9

Post by hagchr » Sun May 18, 2014 7:59 am

Slightly shorter version (not sure if politically correct to use the RegEx replace/result variable to initiate the overall result variable but it seems to work.)

Code: Select all

Let>BinVal=10111010001000010
RegEx>\d,BinVal,0,Matches,NumMatches,1,0,DecVal
Let>ctr=0
While>ctr<NumMatches
    Let>ctr=%ctr%+1
    Let>DecVal={%DecVal%*2}+Matches_%ctr%
EndWhile
MessageModal>Binary = %BinVal%%CRLF%Decimal = %DecVal%

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

Re: The Unofficial Macro Scheduler Puzzler #9

Post by Djek » Mon May 19, 2014 12:00 pm

Ooooow !!
respect !
:shock:

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: The Unofficial Macro Scheduler Puzzler #9

Post by JRL » Mon May 19, 2014 2:46 pm

Wow!!! from 9 lines to 6. Skipped right over 8 and 7. Very impressive!

Anyone got a script using 5 or fewer lines? You have until Friday.
hagchr wrote: (not sure if politically correct to use the RegEx replace/result variable to initiate the overall result variable but it seems to work.)
Not sure what politics has to do with any of this. If you could write a one line regex that did the conversion it would not only be PC but unbeatable.

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

Re: The Unofficial Macro Scheduler Puzzler #9

Post by Marcus Tettmar » Mon May 19, 2014 7:46 pm

Agree with JRL here. The use of RegEx here is inspired. It gets the length, an array of each bit and initialises the decimal value all on one line. Brilliant.
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
Grovkillen
Automation Wizard
Posts: 1131
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: The Unofficial Macro Scheduler Puzzler #9

Post by Grovkillen » Tue May 20, 2014 9:05 am

I highjacked the LOCALVARS in order to get it down to 5 rows :lol:

Code: Select all

Let>BinVal=10111010001000010
RegEx>\d,BinVal,0,Matches,NumMatches,1,0,DecVal
While>LOCALVARS<NumMatches
    Let>LOCALVARS=%LOCALVARS%+1
    Let>DecVal={%DecVal%*2}+Matches_%LOCALVARS%
EndWhile
MessageModal>Binary = %BinVal%%CRLF%Decimal = %DecVal%
Let>ME=%Script%

Running: 15.0.27
version history

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

Re: The Unofficial Macro Scheduler Puzzler #9

Post by Marcus Tettmar » Tue May 20, 2014 9:17 am

Ok, now that's getting sneaky ;-) If we're going to resort to such tactics I can think of a way to use another system variable for the decimal output value and get it down to 4 lines ......
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
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: The Unofficial Macro Scheduler Puzzler #9

Post by Marcus Tettmar » Tue May 20, 2014 9:31 am

And if number of lines is the key metric here (rather than readability) there's a way to do it in three ...
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: 148
Joined: Sat Feb 05, 2005 11:35 pm
Location: Holland
Contact:

Re: The Unofficial Macro Scheduler Puzzler #9

Post by Djek » Tue May 20, 2014 11:33 am

Ok, i decided to "kill it with fire !"
8)
I ve got it down to 1 line

Code: Select all

//Bin-to-Dec  [cheat-mode ON]
//Djek

Let>BinVal=10111010001000010
HTTPRequest>http://www.djekdata.com/mjtnet/btd.asp?strBin=%BinVal%,,POST,,DecVal,,,,
MessageModal>Binary = %BinVal%%CRLF%Decimal = %DecVal%

...no, i did not read the contest regulations properly..
:lol:

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

Re: The Unofficial Macro Scheduler Puzzler #9

Post by Marcus Tettmar » Tue May 20, 2014 11:53 am

My three lines work even when you're not connected to the internet and without using any external process. :-) Any ideas ... ?


Sent from my iPad using Tapatalk
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