In the heart of the 1600s, amidst the bustling streets of Westminster, there lived an English poet whose name was whispered only among scholars and dreamers. He was not a poet of love, nor of war, but of mysteries hidden beneath the stars, where the lines between numbers and legends blurred into one.

With quill in hand, the poet gazed out of his candlelit window, his mind teeming with riddles as old as the moon. He pondered the nature of balance—of fate, of life, and of the cosmic dance that tied everything together. But how, he wondered, could one capture the essence of harmony in mere words?

That night, under the watchful eye of the heavens, he began to write.

The poet’s ink flowed with purpose, crafting a tale of Zopraria—a mystical land where dragons roamed freely and stars sang the songs of time. His intention was clear, yet veiled. What seemed a simple fable of gems and sages was in truth a puzzle, a riddle dressed in the silk of myth. To those who sought only story, it was a grand adventure. But to those with minds sharp enough to see beyond, it was a challenge—a mathematical enigma, shrouded in the elegance of verse.

He imagined a sage, whose hands held not only wisdom but the weight of balance itself. The stars had whispered to the sage, urging him to divide radiant gems into two vessels, so that their weight might be nearly equal. The balance, they said, was the key to the heavens’ blessings.

And so, the tale was born. Its words, like the gems of the stars, held more than beauty—they held a secret. For behind each verse lay a mathematical truth, waiting to be uncovered by those brave enough to dig deeper.

The poet knew this riddle would echo through the ages, whispered in the halls of libraries, pondered over by those who sought both beauty and logic. It was his gift to the world—an eternal puzzle, wrapped in the wonder of dragons, sages, and celestial harmonies.

Now, the tale has resurfaced, nestled within the pages of an old book from 1984, waiting for new eyes to unravel its mystery. And it was here, on September 6, that the challenge began anew…

**September 6, 2024: The Challenge Begins**

There I was, in the musty, dim-lit corner of an old library, flipping through a book from 1984 whose name escapes me. As my fingers brushed over the “More to Read…” section, I encountered something unexpected—an *Old English Poem*. Yes, folks, *a mathematical riddle wrapped in the flowing robes of poetic verse*.

Now, I’m not usually one for poetry. High school left me with an allergic reaction to anything that rhymed. But this poem? Oh, this one was different. It spoke to me. Or rather, it confused me for a solid six hours until my brain started to resemble mashed potatoes. Yet, something stuck with me—gems.

Here’s the poem:

In Zopraria’s endless, wondrous lands, where stars serenely hum,

And ancient dragons guard the skies, where time and tides are one,

A wise old sage lived quietly, whose knowledge spanned all time,

Whose hands could weave through magic’s threads as poets craft in rhyme.

One day, from heaven’s lofty heights, on wings of fire and gold,

A gift descended to the sage, as myths and legends told:

A treasure vast—of radiant gems, like fragments of the stars,

Yet tied to fate’s own prophecy, with rules as old as Mars.

The heavens whispered down to him, a message soft, but clear:

"Divide these glowing gems in two, with careful heart and ear.

Let both your crafted vessels hold a weight so nearly shared,

That harmony between them stands, in balance bright and fair.

But hear us, sage, if flawless match is lost beyond your ken,

Despair not in your quest, for still your journey shall not end.

For even if the balance tips, yet slight the shift may be,

The heavens still shall smile on thee, and blessings will run free."

The sage, with heart both brave and wise, began his sacred test,

To fashion vessels near the same, and give the stars his best.

The dragons circled high above, while angels paused in flight,

For in this task of balance lay a truth as pure as light.

The gems, like secrets from the past, before the sage did turn,

With every choice, the fates took shape, and hearts began to burn.

Though daunting was the work ahead, the stars did still admire

The sage who sought, with steady hand, to balance cosmic fire.

And how the story reached its end, beneath those endless skies,

Is only known to those who seek, and dare to lift their eyes.

In Zopraria’s boundless realms, where tales of old endure,

Some say the sage still ponders on, his heart and mind as pure.

For in the silent heavens lies a balance fine and rare,

A harmony that only those with steady hands may share.

What is this doing in a math book? Did the dragons get lost? This isn't a new Puzzle, a Puzzle from the 1600s, written somewhere near modern-day Westminster.

I tried asking AI for help, but it seemed as confused as I was.

It thought I created it, which I didn’t. But, what about GPT-4? Let’s ask if it knows a shit. It accidentally became my English Teacher.

Ok, Need to decode it myself. Let’s try.

**September 9, 2024: A Clue Emerges**

After a few days of intense mental gymnastics (and consuming far too much coffee), I began to suspect something:

“

Divide these glowing gems in two, with careful heart and ear.

Let both your crafted vessels hold a weight so nearly shared,

That harmony between them stands, in balance bright and fair.

But hear us, sage, if flawless match is lost beyond your ken,“

Despair not in your quest, for still your journey shall not end.

For even if the balance tips, yet slight the shift may be,

The heavens still shall smile on thee, and blessings will run free.

This is the main part of the story and just look at it.

After some brainstorming, I mean, torturing myself for more than 3 days straight, the clue I got was:

Maybe the “gems” are numbers, and the “vessels” are sets. Maybe it’s about splitting these gems—these numbers—into two nearly equal piles. But if they didn’t have sets back in the 1600s, what on Earth were they thinking?

**September 15, 2024: Eureka Moment**

After much pondering, scribbling, and publishing supplementary articles that were probably overkill, I’ve arrived at a breakthrough: this ancient fable of dragons and stars is actually about something rather practical.

### The Challenge

From the perspective of C.S., yeah, I would do this in the form of C.S. first and then Mathematics later, or maybe not. Lord knows.

**We are given a list of integers. Our task is to split the list into two sub-lists such that the absolute difference of their sums is minimized. If a perfect split exists, we need to return the two lists. Otherwise, return the two lists where the sum difference is the smallest possible.**

I know, this ain’t perfect. But, I can understand this only from that piece of text.

### Example:

```
Input: [3, 1, 4, 2, 2]
Output: ([2, 4], [3, 1, 2])
```

In this example, splitting the list into [2, 4] and [1, 3, 2] gives sums of 6 and 6, and the absolute difference is 0.

The goal is to split the list into two parts with sums as close as possible. This happens to be quite relevant to modern-day problems like:

**Load Balancing:**Imagine you have multiple servers that need to handle tasks. To ensure no single server is overloaded, you would want to distribute tasks such that the load is as evenly balanced as possible.**Resource Allocation:**In project management, you might need to distribute resources (like budget or manpower) across different projects in a way that minimizes disparities.**Scheduling:**When scheduling jobs or activities, you might want to ensure that time or resources are distributed as evenly as possible.

**September 16, 2024: Time to Code**

```
from itertools import combinations
def minimize_difference(lst):
total_sum = sum(lst)
n = len(lst)
# Generate all possible subsets
best_diff = float('inf')
best_split = ([], [])
for i in range(1, n//2 + 1):
for subset in combinations(lst, i):
subset_sum = sum(subset)
other_sum = total_sum - subset_sum
diff = abs(subset_sum - other_sum)
if diff < best_diff:
best_diff = diff
best_split = (list(subset), [x for x in lst if x not in subset])
return best_split
# Example usage
lst = [3, 1, 4, 2, 2]
result = minimize_difference(lst)
print("Split lists:", result)
```

This code works better than my brain after three days of decoding an Old English poem. The irony is not lost on me.

### Code Explanation

So, what’s happening here? Basically, this brute-force approach tries every possible subset to find the best split. It’s not the fastest method (my laptop got a little warm), but it’s reliable. Here’s the scoop:

**Generate all Possible Subsets:**We use the`combinations`

function to explore every possible subset of the list. It’s like dividing those mystical gems into different piles—trial and error with style.**Calculate Sum and Difference:**For each subset, the sum is calculated and compared with the remaining gems (or numbers). The goal is to get the smallest difference between the sums.**Update Best Split:**We track the subset that gives us the closest match. Because hey, even dragons need balance.

**Conclusion**

What did I learn from all this? Sometimes, the wisdom of ancient sages and their celestial gems boils down to one thing: math is everywhere, even in poetic tales of yore. So, while the heavens may smile on us with blessings, the real joy is in writing code that does the heavy lifting for you.

You can find the original diary entry here: https://dev.to/kavya-sahai-god/a-poetic-challenge–24m1