Author Topic: (challange - newbie) in between two numbers  (Read 7622 times)

0 Members and 1 Guest are viewing this topic.

JohnK

  • Administrator
  • Seagull
  • Posts: 10627
(challange - newbie) in between two numbers
« on: January 05, 2005, 11:07:09 AM »
I want a way to see if a number is inbetween to numbers.
For example:
Is the number 4 inbetween the numbers 2 89?

Write a lisp that will tell me. The lisp should return either "T" or "nil"

Rules: Make a post when you have your lisp complete. After three hours we will post our lisp solutions.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
(challange - newbie) in between two numbers
« Reply #1 on: January 05, 2005, 11:40:10 AM »
I can name that tune in 23 characters.... of course I am not a newbie ..
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

whdjr

  • Guest
(challange - newbie) in between two numbers
« Reply #2 on: January 05, 2005, 11:40:51 AM »
Ah man.  Why you gotta go put rules on this one? :D

CADaver

  • Guest
(challange - newbie) in between two numbers
« Reply #3 on: January 05, 2005, 01:12:21 PM »
Quote from: Keith
I can name that tune in 23 characters.... of course I am not a newbie ..
Are you counting spaces?

dubb

  • Swamp Rat
  • Posts: 1105
(challange - newbie) in between two numbers
« Reply #4 on: January 05, 2005, 01:17:53 PM »
are there any hints...?

JohnK

  • Administrator
  • Seagull
  • Posts: 10627
(challange - newbie) in between two numbers
« Reply #5 on: January 05, 2005, 01:28:05 PM »
Sure dubb, Use a logical test.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
(challange - newbie) in between two numbers
« Reply #6 on: January 05, 2005, 01:41:57 PM »
Quote from: CADaver
Quote from: Keith
I can name that tune in 23 characters.... of course I am not a newbie ..
Are you counting spaces?


Counting spaces
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

JohnK

  • Administrator
  • Seagull
  • Posts: 10627
(challange - newbie) in between two numbers
« Reply #7 on: January 05, 2005, 01:46:06 PM »
Okay, anyone done yet?
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

whdjr

  • Guest
(challange - newbie) in between two numbers
« Reply #8 on: January 05, 2005, 01:57:26 PM »
Code: [Select]
(defun inbetween (num1 num2 num3)
  (and (> num1 num2)
       (< num1 num3)
  )
)


Here's mine.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
(challange - newbie) in between two numbers
« Reply #9 on: January 05, 2005, 02:03:53 PM »
< post deleted >
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

JohnK

  • Administrator
  • Seagull
  • Posts: 10627
(challange - newbie) in between two numbers
« Reply #10 on: January 05, 2005, 02:04:27 PM »
Outstanding!

Why did you choose "and"?
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

whdjr

  • Guest
(challange - newbie) in between two numbers
« Reply #11 on: January 05, 2005, 02:06:57 PM »
Quote from: Se7en
Outstanding!

Why did you choose "and"?


Because with and they both have to be true or it's false.
You did ask for a T or nil answer.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
(challange - newbie) in between two numbers
« Reply #12 on: January 05, 2005, 02:13:21 PM »
Optimized for size ... functionalized ... essentially the same as Will's ...
Code: [Select]

(defun inbetween (@t @l @u)
  (and(< @l @t)(> @u @t))
)
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
(challange - newbie) in between two numbers
« Reply #13 on: January 05, 2005, 02:19:47 PM »
< post deleted >
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

JohnK

  • Administrator
  • Seagull
  • Posts: 10627
(challange - newbie) in between two numbers
« Reply #14 on: January 05, 2005, 02:22:45 PM »
Quote from: whdjr
Because with and they both have to be true or it's false.
You did ask for a T or nil answer.


Aweosme!

Now, Can you tell me any problems you might see with this procedure the way it is?
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

JohnK

  • Administrator
  • Seagull
  • Posts: 10627
(challange - newbie) in between two numbers
« Reply #15 on: January 05, 2005, 02:24:25 PM »
...you just told them the answer!?
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

whdjr

  • Guest
(challange - newbie) in between two numbers
« Reply #16 on: January 05, 2005, 02:29:26 PM »
All that means is that as a programmer you need to code it properly.  duh.. :D

SMadsen

  • Guest
(challange - newbie) in between two numbers
« Reply #17 on: January 05, 2005, 03:15:57 PM »
All that means is that programmers in Seattle are leaving big security holes in MSIE :D

Oh, no one saw my contribution? :lol:

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
(challange - newbie) in between two numbers
« Reply #18 on: January 05, 2005, 03:22:35 PM »
precisely ... The rules were followed .... the numbers were given and the code was written to match the numbers, not the other way around. Of course, it IS good practice to code to many scenarios, BUT if you quantify the syntax and code to that, the overhead is significantly lower.

It is always best to code to the simplest form, otherwize you end up creating bloatware just like Microsoft, I remember when Windows could be loaded on a 100MB drive and have tons of extra space... now you are required a minimum of 2GB just to install windows where 8Mb of memory was sufficient for most programming 10 years ago, now you almost MUST have 512Mb. The issue has to do with the size of the code and the gobs of things put in the code that are designed to circumvent user stupidity.

To "fix" the code so the user can enter the range values .. use this:
Code: [Select]

(defun inbetween (@t @l @u)
  (and(< (min @l @u) @t)(> (max @l @u) @t))
)
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
(challange - newbie) in between two numbers
« Reply #19 on: January 05, 2005, 04:07:02 PM »
To determine if x is between a and b ...

(< a x b)

What am I missing?
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

SMadsen

  • Guest
(challange - newbie) in between two numbers
« Reply #20 on: January 05, 2005, 04:53:30 PM »
Quote from: MP
What am I missing?

Sequence of arguments is all. Not necessarily an issue as much as a convenience, I would say.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
(challange - newbie) in between two numbers
« Reply #21 on: January 05, 2005, 05:18:18 PM »
Cool MP, good to see you.
Here is your code the other way. :)
Code: [Select]
(defun between (mid start end) (< start mid end))

(between 5 1 10)
(between 1 3 10)
(between 5 8 10)
(between 5 5 10)

T
nil
nil
nil
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

JohnK

  • Administrator
  • Seagull
  • Posts: 10627
(challange - newbie) in between two numbers
« Reply #22 on: January 05, 2005, 09:43:19 PM »
Hey MP, Hows life been treating ya?

Well this thread was about the newbies, but it kinda got overrun a bit.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org