Message Boards Message Boards

0
|
4381 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Perform simple search within List for required value - above or below?

Posted 8 years ago

Hi there,

Given the data list of even numbers squared below.

{4, 16, 36, 64, 100, 144, 196, 256, 324, 400, 484, 576, 676, 784, 900}

I am trying to setup the coding to find - the first element lower than 121 which would give the value = 100

Please advise the coding to achieve this. Many thanks for your help this & attention. Lea...

POSTED BY: Lea Rebanks
2 Replies

This works on your list:

myList = {4, 16, 36, 64, 100, 144, 196, 256, 324, 400, 484, 576, 676, 
   784, 900};
Select[myList, # < 121 &] // Last
POSTED BY: Gianluca Gorni
Posted 8 years ago

Excellent answer - Many thanks & really appreciated.

POSTED BY: Lea Rebanks
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract