The Unofficial Macro Scheduler Puzzler #9
Moderators: Dorian (MJT support), JRL
The Unofficial Macro Scheduler Puzzler #9
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.
- 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
Thanks JRL. I look forward to seeing some solutions. I have two of my own but I'll hold them back for now.
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: The Unofficial Macro Scheduler Puzzler #9
haha !
If you hold them to your own, you cant claim to be the first !
Wel here's my script
come on, guys, dont let this make you shivering and being afraid to submit your solution!
Kind regards,
Djek
If you hold them to your own, you cant claim to be the first !
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%
Kind regards,
Djek
Re: The Unofficial Macro Scheduler Puzzler #9
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.
Re: The Unofficial Macro Scheduler Puzzler #9
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%
Re: The Unofficial Macro Scheduler Puzzler #9
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????
Anyone see a way to do it in 8 lines? 7?? 6??? 5????
Re: The Unofficial Macro Scheduler Puzzler #9
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%
Re: The Unofficial Macro Scheduler Puzzler #9
Ooooow !!
respect !
respect !
Re: The Unofficial Macro Scheduler Puzzler #9
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.
Anyone got a script using 5 or fewer lines? You have until Friday.
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.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.)
- 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
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?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
- 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
I highjacked the LOCALVARS in order to get it down to 5 rows
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%
- 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
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?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
- 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
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?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Re: The Unofficial Macro Scheduler Puzzler #9
Ok, i decided to "kill it with fire !"
I ve got it down to 1 line
...no, i did not read the contest regulations properly..
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%
- 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
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
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?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?