Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

euphoria
communitycreator

What is the match_any() method in Euphoria?

NDUKWE CHIDERA K.

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The match_any() method in Euphoria implements a search algorithm, which traverses the values of a list in search of a match with the values of another list. Simply put, this function checks if any value from a set of values can be found in another set of values.

When the match_any() method finds a match, it returns 1. Otherwise, when no match is found, it returns 0.

For instance, suppose we have two variables A = “in” and B = “minimal”. If we say match_any of A in B, that is match_any(A,B), the return value will be 1. This is because both “i” and “n” from A match some characters in “minimal” of variable B.

Syntax

Let’s look at the syntax of this method:

match_any(search_value, to_search, start_from)

Parameter values

  • search_value: This is the value whose match is being searched for in another set of values.
  • to_search: This is the variable whose values are to be searched for a match with any of the search_value.
  • start_from: This is the position at which we want the search for a match to begin. This is an optional parameter and has a default value of the first index.

Return value

This method returns the value 1 if a match is found and the value 0 if no match is found.

Example

Let’s look at an example of the match_any() method.

include std/search.e
sequence myseq1, myseq2, myseq3
myseq1 = "This is educative"
myseq2 = "iuc"
myseq3 = "wyz"
puts(1,"\"i\" or \"u\" or \"c\" can be found in \"This is educative\" so it returns :")
print(1,match_any(myseq2, myseq1))
puts(1,"\n none of \"wyz\" can be found in \"This is educative\" so it returns :")
print(1, match_any(myseq3, myseq1))
puts(1,"\n 2 comes before start_from parameter :")
print(1, match_any({2}, {1,2,3,4,5}, 4))
Try it out!

Explanation

  • Line 1: We include the search.e module from the standard library.

  • Line 3: We declare some variables.

  • Lines 5–7: We assign values to the variables we declared.

  • Line 10: We use the match_any method to check if any of the characters in "uic" can be found in the value "This is educative". Then, we print the result.

  • Line 13: We use the match_any method to check if any of the characters in "wyz" can be found in the value "This is educative". Then, we print the result.

  • Line 13: We use the match_any method to check if 2 can be found in the set {1,2,3,4,5}, starting from the index position 4. Then, we print the result.

RELATED TAGS

euphoria
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring