home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.programming      Programming issues that transcend langua      57,431 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 56,761 of 57,431   
   Stefan Ram to Richard Heathfield   
   Re: A little puzzle.   
   14 Dec 22 13:23:38   
   
   From: ram@zedat.fu-berlin.de   
      
   Richard Heathfield  writes:   
   >Your problem is closely related to the very first question I was   
   >ever posed (in early 1982), by a friend who needed to be able to   
   >establish cleanly in a single expression whether a keypress was a   
   >digit (ASCII 48-57). The relevant dialect of BASIC didn't have   
   >anything like an isdigit function.   
   >The friend was on the point of giving up on me when I handed him   
   >                  ABS(K-52.5)<4.5   
      
     "K >= 48 AND K <= 57" also is a single expression in BASIC.   
      
     For the problem to find whether a point x is in an interval [a,b],   
     I'd rotate the problem, so that the interval starts at 0.   
      
   x =( x - a )% max   
   b =( b - a )% max   
   return 0 <= x <= b   
      
     Here I have used Python's floored modulo operator and Python   
     notation for "0 <= x and x <= b".   
      
     For the case that only a and b are given, but not whether   
     the interval is [a,b] or [b,a], I'd choose that interval   
     the length of which is smaller than 12 (if possible).   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca