Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Finding the Area of a Circle  (Read 7086 times)

0 Members and 1 Guest are viewing this topic.

Salmon Trout

  • Guest
Re: Finding the Area of a Circle
« Reply #15 on: February 25, 2016, 01:33:43 PM »
You could even put it somewhere on your PATH, set the default vbscript engine to Cscript, and call it by name:
And, of course, if you haven't already done so, set the default Cscript logo option to NOLOGO.

Salmon Trout

  • Guest
Re: Finding the Area of a Circle
« Reply #16 on: February 26, 2016, 01:03:00 AM »
Python oneliner similar to eval.vbs:
Code: [Select]
import sys; from math import *; print eval(sys.argv[1])
Use decimal point to avoid int results from integer values in Python 2.xx e.g. 3/2.0 (I believe Python 3 defaults to float?)

Examples

C:\>eval.py 5/3
1

C:\>eval.py 5/3.0
1.66666666667

C:\>eval.py sqrt(3)
1.73205080757

C:\>eval.py pi
3.14159265359

C:\>eval.py e
2.71828182846
« Last Edit: February 26, 2016, 01:27:14 AM by Salmon Trout »

zask

    Topic Starter


    Intermediate

    • Experience: Experienced
    • OS: Other
    Re: Finding the Area of a Circle
    « Reply #17 on: April 07, 2016, 09:51:51 PM »
    Scaling it down is one way to do this, but you will lose precision. Same as the 3.14 turning into 314 where you only have precision to 3.14xxxxxxxxxxx-> and no other digits to infinity.

    You can scale it down to do the math and then in the end scale it back up to avoid exceeding 32 bit integer when the product of the equation itself will exceed 32 bit but the answer itself is smaller than 32-bit. With your equation you could bring it to 31 for 3.1, losing the hundreths precision, but it gets ugly fast when you reduce the precision. This use for greater than 32 bit is best for a real language intended for large numbers and precision. Something that batch isnt very good at alone.

    This is something that is far more easier to accomplish with just about any language other than batch as well as you would have a greater depth of precision if you did this with a real programming language geared for mathematical equations such as I have a program I wrote that does crypto shuffling and I was looking for poor keys that would shuffle back to their original characters for up to 1 Trillion Keys. It took an 8-core AMD FX-8350 at 4000Mhz a week to process all of these keys at 125 Billion Keys processed per core running full tilt. I had to use Long Long INT's to achieve this with C++.

    In the end I added a routine that counts between 2 arrays matching pairs for each element and it avoids use of keys that exceed a specified allowance of matching input and output characters. I can set it to 0 and Z will never come back out as Z etc. or set it to 2 in which 2 characters can be same with rest shuffled etc. So the week of crunching was pretty much a waste but interesting as to how many combinations had 10 or more unshuffled characters which would make the output weak and potentially able to be decrypted too easily.

    okay good to know, could i maybe borrow one of your C++ examples?

    zask

      Topic Starter


      Intermediate

      • Experience: Experienced
      • OS: Other
      Re: Finding the Area of a Circle
      « Reply #18 on: April 12, 2016, 07:23:14 PM »
      You don't have to delete it if you don't want to. It's only 45 bytes. (About 7 years ago I thought I had independently invented this!)
      Code: [Select]
      Wscript.echo eval(WScript.Arguments(0))You could even put it somewhere on your PATH, set the default vbscript engine to Cscript, and call it by name:

      C:\>type c:\batch\eval.vbs
      Wscript.echo eval(WScript.Arguments(0))

      C:\>dir c:\batch\eval.vbs
       Volume in drive C is WIN-SSD1
       Volume Serial Number is 9C5F-D658

       Directory of c:\batch

      11/03/2007  18:21                45 eval.vbs
                     1 File(s)             45 bytes
                     0 Dir(s)  34,618,871,808 bytes free

      C:\>eval 2+1
      3

      C:\>eval now
      24/02/2016 20:41:11

      C:\>eval weekdayname(weekday(now))
      Wednesday

      C:\>eval 4*ATN(1)
      3.14159265358979

      C:\>for /f "delims=" %A in ('eval 35.333/2.277') do @set result=%A

      c:\>echo %result%
      15.5173473869126

      C:\>eval weekdayname(weekday(now))
      Wednesday



      wow thats a very helpful peace of code, thank you.