The Unofficial Macro Scheduler Puzzler #9

Anything Really. Just keep it clean!

Moderators: Dorian (MJT support), JRL

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 12:36 pm

my last shot ;

don't know what contest regulations say about this

Code: Select all

Let>BinVal=10111010001000010
ExportData>5-LINES.SCP_DATA,%SCRIPT_DIR%\5-lines.scp
Include>%SCRIPT_DIR%\5-lines.scp
MessageModal>Binary = %BinVal%%CRLF%Decimal = %DecVal%

/*5-LINES.SCP_DATA:52656745783E5C642C42696E56616C2C302C4D6174636865732C4E756D4D6174636865732C312C302C44656356616C0D0A5768696C653E4C4F43414C564152533C4E756D4D6174636865730D0A202020204C65743E4C4F43414C564152533D254C4F43414C56415253252B310D0A202020206C65743E44656356616C3D7B2544656356616C252A327D2B4D6174636865735F254C4F43414C56415253250D0A456E645768696C650D0A*/


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 12:41 pm

.
Last edited by Djek on Tue May 20, 2014 1:32 pm, edited 2 times in total.

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 12:43 pm

I thought of that, but don't you need another line to delete the temp file so it's not left lying around ;-)
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
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 » Tue May 20, 2014 4:23 pm

I've been involved in disaster recovery all morning. Have only now had a chance to view the last few hours of entries. Very creative.
djek wrote:[cheat-mode ON]
I've been looking for a web site that would pass the answer back. Didn't consider making my own. Of course now we need to know how many lines you're using on the web site. Assuming the best available at this moment you have 5 lines on the web. Plus 1 in the visible script makes 6.
djek wrote:don't know what contest regulations say about this
Regulations? We simply have a panel of judge whose decision is final. We don't need "regulations".

The method you've used has been discussed by the panel and the panel has decided that those Include> lines of code are indeed included in the total line count. Also, unfortunately, the ExportData> function won't export the data when the remarked data block has been shortened to one line. For 5-lines.scp to be exported the export data block will have to be 4 lines.
  • /*
    5-LINES.SCP_DATA:
    526567457...
    */
Kicks the working lines total up to 11
Grovkillen wrote:I highjacked the LOCALVARS in order to get it down to 5 rows
Out panel of judge finds that creative and honorable. Good job! you're in the lead... for the moment.

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 4:57 pm

Marcus, you shouldn't have dared me! Now all I'm thinking of is how you did it in 3 lines! :)
Let>ME=%Script%

Running: 15.0.27
version history

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 » Tue May 20, 2014 5:00 pm

Ok, two more alternatives for the esteemed jury.

(Binary string needs quotation marks)
Let>BinVal="10111010001000010"
WriteLn>%DESKTOP_DIR%\chtestvbxx.vbs,nWLNRes,Set obj=CreateObject("Scripting.FileSystemObject")%CRLF%obj.DeleteFile("%DESKTOP_DIR%\chtestvbxx.vbs")%CRLF%dim Res,I%CRLF%Bin=%BinVal%%CRLF%Bin=Bin%CRLF%Res=0%CRLF%For I = len(Bin) to 1 step -1%CRLF%Dig=mid(Bin,I,1)%CRLF%select case Dig%CRLF%case "0"%CRLF%case "1"%CRLF%Res=Res+(2^(len(Bin)-I))%CRLF%end select%CRLF%Next%CRLF%MsgBox("Binary="&Bin&vbNewLine&"Decimal=" & Res)
ExecuteFile>%DESKTOP_DIR%\chtestvbxx.vbs

  View Snippet Page

(3rd line is somehow added by "the snipper" when inserting the snippet, cannot get rid of it. should be deleted)
Let>BinVal=10111010001000010
IncludeFromVar>RegEx>\d,BinVal,0,Matches,NumMatches,1,0,DecVal%CRLF%Let>ctr=0%CRLF%While>ctr<NumMatches%CRLF%Let>ctr=%ctr%+1%CRLF%Let>DecVal={%DecVal%*2}+Matches_%ctr%%CRLF%EndWhile%CRLF%MessageModal>Binary = %BinVal% / Decimal = %DecVal%

  View Snippet Page

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 5:08 pm

Jäklar! :)
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 5:17 pm

hagchr wrote:Ok, two more alternatives for the esteemed jury.

(Binary string needs quotation marks)
Let>BinVal="10111010001000010"
WriteLn>%DESKTOP_DIR%\chtestvbxx.vbs,nWLNRes,Set obj=CreateObject("Scripting.FileSystemObject")%CRLF%obj.DeleteFile("%DESKTOP_DIR%\chtestvbxx.vbs")%CRLF%dim Res,I%CRLF%Bin=%BinVal%%CRLF%Bin=Bin%CRLF%Res=0%CRLF%For I = len(Bin) to 1 step -1%CRLF%Dig=mid(Bin,I,1)%CRLF%select case Dig%CRLF%case "0"%CRLF%case "1"%CRLF%Res=Res+(2^(len(Bin)-I))%CRLF%end select%CRLF%Next%CRLF%MsgBox("Binary="&Bin&vbNewLine&"Decimal=" & Res)
ExecuteFile>%DESKTOP_DIR%\chtestvbxx.vbs

  View Snippet Page
Neat. But can you do it without the overhead of creating a file?
hagchr wrote:(3rd line is somehow added by "the snipper" when inserting the snippet, cannot get rid of it. should be deleted)
Let>BinVal=10111010001000010
IncludeFromVar>RegEx>\d,BinVal,0,Matches,NumMatches,1,0,DecVal%CRLF%Let>ctr=0%CRLF%While>ctr<NumMatches%CRLF%Let>ctr=%ctr%+1%CRLF%Let>DecVal={%DecVal%*2}+Matches_%ctr%%CRLF%EndWhile%CRLF%MessageModal>Binary = %BinVal% / Decimal = %DecVal%

  View Snippet Page
Cunning. But it's 5 lines when you step through. The CRLFs mean the extra lines are still there.

Cunning though.

Shall I post my 3 line solution yet?
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
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 » Tue May 20, 2014 6:39 pm

Grovkillen wrote:Jäklar!
Had to Google a translation. English is "damn!". Can we say that on this forum? :?
hagchr wrote:Binary string needs quotation marks
Not if you rewrite them into your vbs code.
"Esteemed jury"? Yes flattery helps. Win, lose or draw, I'm going to have to give you points for tenacity.
Marcus wrote: Neat. But can you do it without the overhead of creating a file?
I second the question.

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 6:46 pm

JRL wrote:Had to Google a translation. English is "damn!". Can we say that on this forum? :?
Google Translate isn't always right. It's more like "darn!"
Let>ME=%Script%

Running: 15.0.27
version history

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 » Tue May 20, 2014 9:40 pm

No need for external files, no need for quotation marks...

Let>BinVal=10111010001000010
Let>Calc="Bin=""%BinVal%"":Res=0:For I = len(Bin) to 1 step -1:Dig=mid(Bin,I,1):select case Dig:case ""0"":case ""1"":Res=Res+(2^(len(Bin)-I)):end select:Next:MsgBox(""Binary=""&Bin & vbCrLf & ""Decimal="" & Res)"
VBEval>Execute(%Calc%),

  View Snippet Page


With MS the only limit is your imagination...

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

You got it! That was my shortest method too. Well done. Only I'd make the vbscript return the result rather than display it so that it can be used later.

Sent from my GT-I9100 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?

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 » Tue May 20, 2014 10:14 pm

Simply amazing! Marcus has been speaking of his "3 line solution". If this is the same, I'm calling it a two working lines solution. Anyone with a one liner? Perhaps there's an undocumented BinToDec> function already built into MS?

hoangvo81
Pro Scripter
Posts: 69
Joined: Tue Feb 07, 2012 8:02 pm

Re: The Unofficial Macro Scheduler Puzzler #9

Post by hoangvo81 » Wed May 21, 2014 12:22 am

Isn't hagchr solution really a one liner if you combine the all the variables into the execute?

Code: Select all

Let>BinVal=10111010001000010
Let>Calc="Bin=""%BinVal%"":Res=0:For I = len(Bin) to 1 step -1:Dig=mid(Bin,I,1):select case Dig:case ""0"":case ""1"":Res=Res+(2^(len(Bin)-I)):end select:Next:MsgBox(""Binary=""&Bin & vbCrLf & ""Decimal="" & Res)"
VBEval>Execute(%Calc%),
to

Code: Select all

VBEval>Execute("Bin=""10111010001000010"":Res=0:For I = len(Bin) to 1 step -1:Dig=mid(Bin,I,1):select case Dig:case ""0"":case ""1"":Res=Res+(2^(len(Bin)-I)):end select:Next:MsgBox(""Binary=""&Bin & vbCrLf & ""Decimal="" & Res)"),
if you don't count the let>bin

then just bounce the calc into the execute and it would still be 1 line.

Code: Select all

let>Binval=10111010001000010
VBEval>Execute("Bin=""%binVal%"":Res=0:For I = len(Bin) to 1 step -1:Dig=mid(Bin,I,1):select case Dig:case ""0"":case ""1"":Res=Res+(2^(len(Bin)-I)):end select:Next:MsgBox(""Binary=""&Bin & vbCrLf & ""Decimal="" & Res)"),

this is just stating the fact that its a one liner really.

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 » Wed May 21, 2014 6:29 am

This is why I just love MS and the forum... things like this just evolve. It start out as a competition but in the end everyone has learned something. :)
Let>ME=%Script%

Running: 15.0.27
version history

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