Python & Fifth Grade โ€” A Math Challenge from Serbia ๐ŸŒ๐Ÿง 

Bosko Savic
4 min readJan 16, 2024

--

In the world of mathematics competitions, young minds are often challenged with problems that test their reasoning, conceptual understanding, and problem-solving skills. A fascinating problem from a Serbian math competition for fifth graders involves set theory and Venn diagrams โ€” fundamental tools for exploring mathematical concepts.๐Ÿงฎ

Competitionโ€™s exercise for all grades can be found: here

The Riddle ๐Ÿง

Let T be the set of all even numbers less than 50. Represent with a Venn diagram the sets:

  • A = {a โˆˆ T | a is divisible by 3},
  • B = {b โˆˆ T | b is divisible by 4},
  • C = {c โˆˆ T | c is divisible by 5}.

Determine A \ (B โˆฉ C). ๐Ÿ“Š

This exercise not only reinforces the arithmetic skills of divisibility but also encourages students to visualize mathematical relationships through the construction of a Venn diagram โ€” a diagram that shows all possible logical relations between a finite collection of different sets.

Now, the challenge is to determine A \ (B โˆฉ C), which essentially means finding the elements in set A that are not in the intersection of sets B and C.

Letโ€™s see how computational thinking can complement traditional math competition strategies using Python! ๐Ÿ

Step 1: Defining the Set T

We kick things off by defining set T, which contains all even numbers less than 50. With a dash of Python magic, we generate this set using the range() function:

# Define the set T as all even numbers less than 50
T = set(range(2, 50, 2))

# {2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48}

Step 2: Defining the Sets A, B, and C

Next, we define sets A, B, and C, employing similar Python wizardry:

# Set A: Divisible by 3
A = {a for a in T if a % 3 == 0} # {36, 6, 42, 12, 48, 18, 24, 30}

# Set B: Divisible by 4
B = {b for b in T if b % 4 == 0} # {32, 4, 36, 8, 40, 12, 44, 16, 48, 20, 24, 28}

# Set C: Divisible by 5
C = {c for c in T if c % 5 == 0} # {40, 10, 20, 30}

Here, we employ set comprehensions to create sets A, B, and C. These sets contain numbers from T that are divisible by 3, 4, and 5, respectively. The modulo operator `%` checks for divisibility.

Step 3: Calculating A \ (B โˆฉ C)

Now, letโ€™s crunch some numbers. We calculate the intersection of sets B and C and then determine the elements in set A that are not in this intersection:

# Intersection of B and C
B_inter_C = B.intersection(C) # {40, 20}

# A \ (B โˆฉ C)
result = A - B_inter_C # {36, 6, 42, 12, 48, 18, 24, 30}

And there we have it! A solution in just a few lines of Python code. ๐Ÿ˜Ž

Pay Attention to Brackets!

When working with set comprehensions, itโ€™s crucial to remember the brackets. ๐Ÿง

  • ๐Ÿ‘ Correct: {x for x in some_list if condition} - This creates a set with elements that meet the condition.
  • โŒ Incorrect: {} - This creates an empty dictionary, not a set.

Make sure to use the correct brackets to avoid unexpected Python surprises! ๐Ÿ˜„๐Ÿ‘Œ

Visualizing with Venn Diagrams

By using the Python library matplotlib-venn, we can visualize our sets with a Venn Diagram, showing the unique and shared elements.

Practical Example: TURF Analysis

Letโ€™s take our understanding of sets to a real-world scenario with TURF (Total Unduplicated Reach and Frequency) analysis:

Imagine each set represents kidsโ€™ preferences for bubble gum flavors:

  • ๐Ÿ“ Set A: 3 kids prefer strawberry.
  • ๐Ÿ Set B: 6 kids are all about green apple.
  • ๐Ÿ‡ Set C: 1 kid has a taste for grape.

When we analyze their overlaps:

  • ๐Ÿ“๐Ÿ 4 kids enjoy both strawberry and green apple (intersection of Sets A and B).
  • ๐Ÿ“๐Ÿ‡ 1 kid likes strawberry and grape together (intersection of Sets A and C).
  • ๐Ÿ๐Ÿ‡ 2 kids delight in the mix of green apple and grape (intersection of Sets B and C).
  • ๐Ÿ“๐Ÿ๐Ÿ‡ No kid likes all three flavors (intersection of Sets A, B, and C).

To achieve the widest unique reach:

  • Start with Set B (green apple), which has 6 unique enthusiasts.
  • Add Set A (strawberry), bringing in 3 additional unique fans.
  • Consider Set C (grape), which contributes just 1 more unique admirer.

Therefore, to reach the most kids, youโ€™d offer green apple and strawberry flavors, reaching 9 unique kids in total (6 from green apple, 3 from strawberry). Adding grapes would only increase the unique reach by 1 additional kid, making it less impactful compared to the other two in terms of unduplicated reach. ๐Ÿ“ˆ

In summary, TURF analysis suggests focusing on the flavors that will attract the largest unique audience, which in this case would be green apple and strawberry bubble gums.

So, whether youโ€™re a young math enthusiast or a seasoned data analyst, Pythonโ€™s prowess in bridging the gap between abstract concepts and tangible solutions continues to be a valuable asset in your journey of exploration and discovery.

Happy coding and math solving! ๐ŸŒŸ๐Ÿงฎ๐Ÿ

--

--