Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Hey Monks, I come here seeking help from our mathematicians again, as I'm feeling apathetic today and am having a brain fart moment.

My objective is to find out if my car is parked within a 1.1 metre proximity of where it should be. This will identify whether the vehicle is in my garage or not. I then will read the vehicle's charge level, and using an LED strip on the garage wall, indicate the level on that strip, and if it's below a threshold, sound an audible alarm to remind me to plug the car in to recharge it. I will be using motion and sonar proximity sensors to identify when I've come into the house as to turn the warning off if I don't plug the car in (the car will indicate if the charger is plugged in via my software, and I'll disable the alert when this happens too).

Anyway, with GPS, the fifth decimal place indicates the 1.1 metre area I'm looking to find. My question is, how do I compare the known set location, say 3.1566789, with the actual location of the vehicle, say 3.1565323, and verify whether that they are within at least five decimal places of one another?

I don't know why I'm having this moment, I know it's a silly, easy thing. It'll likely come to me the second I hit submit. I know I could regex the numbers out, but I'd rather have a math calculation as I want to apply it to other areas.

I have no code for this simple example, so I'll just post the following to at least make it perlish.

use 5.10.0; $p=japh;push@a,w();$s=j4;sub n{"8fbac6c6e252"};unshift@a, "b4d6c7ea52a7";$k=crypt($s,$p);$o="aeafa7cfdbd58c";@h= map{sprintf"%x",ord$_}split//,$k;push@a,$o;$a[3]=pop@a; $a[2]=n();sub w{"bcb3d8dec8dd"}$x.=$_ for@a;@b=($x=~m/..?/g); push@z,@h until @z>@b;for(@b){push@japh,hex($_)-hex($z [$n]);$n++;}say map{chr$_}@japh;

Cheers,

-stevieb


In reply to Check whether two numbers are within a range by stevieb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-18 05:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found