me learning programing
Thursday, November 23, 2023

PASCAL, ONCE UPON A TIME: 2. Me and Pascal

by Albert Xian

A Code Odyssey in Changzhou: My Dance with Pascal

In the autumnal embrace of November 2012, as a fourth grader with stars in my eyes, I unwittingly embarked on a whimsical journey into the land of Pascal. This adventure didn't stem from a fiery passion for programming but was more like being whisked away by a gentle breeze — a suggestion from my math teacher. This breeze led me to an extra-curricular course, a secret garden where young math and science wizards congregated. It was a realm where the seeds for future academic glories were sown, a magical forge preparing young minds for the epic quests of high school and university admissions.

Meanwhile, my hometown Changzhou, a hidden jewel in the southwest of Jiangsu Province in China, was silently nurturing a revolution in the world of programming education. The conductor of this symphony was the illustrious Cao Wen, a maestro in the realm of informatics. After donning his armour of computer science knowledge from Fudan University in 1989, he set forth to the Department of Informatics Technology at my future alma mater, Changzhou Senior High School. He was a pioneer, charting new courses as China embarked on the maiden voyage of the National Olympiad in Informatics. In 2009, under the banner of the Changzhou Municipal Ministry of Education, the "Cao Wen Master Studio" was born, a lighthouse guiding the ships of young programming enthusiasts.

Photos of My Alma Mater, Changzhou Senior High School of Jiangsu Province
Photos of My Alma Mater, Changzhou Senior High School of Jiangsu Province

Picture a training system similar to nurturing budding athletes in sports like basketball or football. Here, young saplings, barely in grades 4 and 5, were sculpted and chiselled, their weekends and holidays resonating with the symphony of algorithms and loops. This multi-tiered odyssey, stretching from beginner to advanced, was the gateway to the sanctum of the elite training class. This ground-breaking quest was a beacon, unparalleled in the annals of China and the world. The fruits? A constellation of young stars, blazing trails in provincial, national, and international arenas like IOI, Top Coder, and ACM-ICPC, securing their passage to prestigious universities.

One of the my high school alumni, Yi Wu, IOI 2010 Silver Medalist, Team China Captain
Yi Wu, IOI 2010 Silver Medalist, Team China Captain

My story, however, was a different flavour in this rich tapestry. My name never soared among the celestial champions on the fabled Wall of Fame. My journey was less about conquering and more about surviving in this enchanted forest of code. From grade 4 to 8, my path was strewn with challenges, a labyrinth of loops, arrays, and enigmatic algorithms. With a shaky foundation in math, my only compass was the rote memorization of patterns and codes. Bereft of coding knowledge in my family and facing a dearth of resources for fledgling programmers on the Chinese internet, especially in the ancient dialect of Pascal, I was like a lone wanderer in an uncharted realm. Fortunately, surviving the gauntlet of elimination, I found my place in the regular training class, among a constellation of young prodigies. There, with these brilliant minds, I felt a curious mix of wonder and excitement, but all emotions transformed into a sense of loss with no accomplishment. I could not find my way to stand out.

Writing till this moment, looking back at that time, a sense of relief washes over me all of a sudden. Those prodigies, my peers and predecessors, eventually went to the echelons of academia and industry, achieving feats in world-class universities, leading tech giants, and renowned research institutions. Their journeys, marked by rare achievements, were not the everyday norm but the exceptional tales in the grand narrative of life. As a young child, I often found myself in the shadows of these towering figures, struggling to see my own potential amidst such brilliance. This comparison, though unintentional, began to dim my own light, my confidence and passion flickering under the weight of immense expectations.

In this tapestry of experiences, I learned that it's not just about striving to be the best among the best. It's about discovering what resonates within us, finding joy in our pursuits, and carving out our own niche in the vast expanse of possibilities. Our stories, though they may not always align with those of the prodigies, are still narratives of success in their own right, painted with the colours of our unique passions and dreams.

My journey in computer science, filled with passion but also doubts, made me question if I should continue during the application season at Grade 12. My interest remained, but the challenges I faced shook my confidence, leaving me to ponder if a different approach might have solidified my choice for university. It ended up for me to major in a Math program where I can still program but not all my life about.

Sometimes, I can't help but wonder what my future might have been like had my early experience in programming at primary school been different.

The ANSWER will always remain UNKNOWN.

Let us try a simple program that I had done in primary school

Problem Description:

During P.E. classes, Tom's teacher often organizes games for the students. This time, the teacher has the students play a ball-passing game.

The rules of the game are as follows: n students stand in a circle, and one student, say, Tom, starts with the ball. When the teacher blows the whistle, the ball-passing begins. Each student can pass the ball to either of the two students standing next to them (left or right). When the teacher blows the whistle again, the ball-passing stops. The student who is holding the ball at that moment and hasn't passed it yet is the loser and has to perform a show for everyone.

The clever Tom came up with an interesting question: How many different ways can the ball be passed starting from Tom and, after m passes, end up back with Tom again? Two methods of passing are considered different if and only if the sequence of students receiving the ball, in the order they received it, is different. For example, with 3 students - Tom (1), Jack (2), and Harry (3) - and assuming Tom is number 1, there are 2 ways for the ball to be passed 3 times and return to Tom: 1->2->3->1 and 1->3->2->1.

Input Description: A single line containing two integers, n and m, separated by a space, where n and m satisfy the conditions (3 ≤ n ≤ 30, 1 ≤ m ≤ 30).

Output Description: A single line containing one integer, representing the number of different ways to pass the ball according to the rules of the game.

Example:

Input:

3 3

Output:

2

HINT: This problem can be solved using dynamic programming (DP), specifically using a Recursive Approach to explore the different ways the ball can be passed back to the starting player.

When we rewind the clock to the late 1960s and early 1970s, Pascal emerges as a beacon in the realm of programming. Crafted with finesse by Niklaus Wirth, Pascal wasn't just a language - it was an emblem of a changing tide both in classrooms and cubicles. By chance, I met Pascal in the mid-2010s and gained so many experiences in later years, which made this blog series possible. This would be the first blog of the series, Pascal, Once Upon a Time. I’ll cover many of these topics in future blogs!