# [✓] Make a test using pattern matching for pairs of numbers?

Posted 2 months ago
312 Views
|
2 Replies
|
2 Total Likes
|
 I need to make a test that resolves to true or false for this problem, given a list of pairs of numbers for example:- testno={{2,47},{3,22},{5,12},{7,8},{11,4},{13,3},{17,2},{19,2},{23,2},{29,1},{31,1},{37,1},{41,1},{43,1},{47,1}} and a smaller list of pairs of numbers num={{2,12},{3,2},{11,1}}; num1={{2,12},{3,2},{17,3}} Lets say the designation is {a, b} for each pair of numbers. The first test is do all "a" position numbers from "num" appear at some place in the "a" positions of "testno" and if so are the magnitude of the corresponding "b" position numbers in "testno" greater than or equal to the corresponding "b" position numbers in "num"? in the example shown "num" passes the test, however, num1 would fail. In the final setup the number of elements of both "testno" and "num" can vary even to where the lengths of both are the same. I know this can be done by using some form of do loop or even table and test each sub element in turn, but I am sure there is a more elegant way with pattern matching, any pointers would be welcome.
2 Replies
Sort By:
Posted 2 months ago
 My attempt: test[{a_, b_}] := Or @@ Cases[testno, {a, c_} -> (c >= b)]; And @@ Map[test, num] And @@ Map[test, num1]