Programming Problems & Solutions : “How to Format Arrays as Phone Numbers with NUnit Testing”. The introduction to this series is here and includes all links to every post in the series. If you’d like to watch the video (see just below this), or the AI code up (it’s at the bottom of the post) they’re available! But if you just want to work through the problem keep reading, I cover most of what is in the video plus a slightly different path down below.
The AI continuation and lagniappe is at the bottom of this post.
In the world of software development, sometimes a seemingly simple task has lessons to teach such as language features and problem-solving. Today, I’m diving into a fun coding challenge that does exactly that: writing a method in C# that takes an array of 10 integers and returns these numbers formatted as a phone number. This exercise is perfect for understanding array manipulation, string formatting, and how to effectively use testing frameworks like NUnit to verify our solution.
Programming Problems & Solutions: “Finding the Maximum Sum Path in a Binary Tree” is the first in this series. The introduction to this series is here and includes all links to every post in the series. If you’d like to watch the video (see just below this), or the AI code up (it’s at the bottom of the post) they’re available! But if you just want to work through the problem keep reading, I cover most of what is in the video plus a slightly different path down below.
Scroll to the bottom to see the AI work through of the code base.
Doing a little dive into the world of binary trees. If you’re in college, just got out, or having flashbacks to algorithms and data structures classes, this will be familiar territory. It’s been a hot minute since I’ve toiled through these, so figured it’d be fun to dive in again for some more modern purpose. I’m going to – over the course of the next few weeks – work through a number of algorithm and data structures problems, puzzles, katas, or what have you – and then once complete work through them with various AI tools. I’ll measure the results in whatever ways seem to bring good defining characteristics of the system and post the results. So join me, on this journey into algorithms, data structures, and a dose of AI (actually LLMs and ML but…) systems and services.
Hello fellow coders, AI nerdists (ok, IYKYK, “machine learning LLMs nerdists), and language enthusiasts! Adron here, ready to dive into an exciting new series that’s all about pushing the boundaries of our programming prowess. If you’ve followed my work, you know I’m often delving into exploring the depths of code (or systems in general), optimizing it, and sharing those insights with all of you. This time, we’re taking things up a notch by blending the art of manual code slinging and then shifting over and giving the power of artificial intelligence (AI) a try. Ok, my nitpick has already struck. This isn’t really AI but is really just the power of LLMs and machine learning, the ole’ Chat GPT and CoPilot and Claude and whatever else, that I’ll be diving into. Let’s go and put em’ to the test.
The Journey
Our journey starts with tackling programming problems the old-fashioned way: rolling up our sleeves and solving them manually. This is where we lay the groundwork, understand the problem’s intricacies, and come up with a solution that, while not perfect, gets the job done. Then, we refactor our code, streamlining and optimizing it to make it more efficient and elegant.
Enter the AI
Once we’ve got a solid foundation, it’s time to bring in the big guns – artificial intelligence. We’ll explore various AI tools, from ChatGPT-4 to Claude and beyond, to see how they tackle the same problems. Each AI brings its unique approach and strengths to the table, and we’ll break down their solutions, comparing them to our manual efforts.
Why This Matters
In today’s fast-paced tech world, understanding how to leverage AI in our coding practices is crucial. This series isn’t just about showcasing cool AI tools; it’s about understanding their capabilities, limitations, and how they can augment our problem-solving skills. By the end of this journey, you’ll have a deeper appreciation for both human ingenuity and AI’s potential.
What to Expect
In each post, you’ll find:
The Hand Crafted Solution: A detailed walkthrough of solving the problem by hand.
Refactoring: Steps to optimize and clean up the manual solution.
AI Solution: A deep dive into how different AI tools approach the problem.
Comparative Analysis: A side-by-side comparison of manual and AI-generated solutions, highlighting strengths, weaknesses, and key takeaways.
The links to the code repository and respective before and after of each code base commits.
A video walk through of the code and process I went through to get to the solution presented in each video & blog post.
A ordered list of the posts as I complete them at the bottom of this post. For starters, as this post has gone live the first post of the series is also live now.
So, get those keyboards and processors ready, grab your favorite code editor, overclock your proc, and join me on this ride through the world of coding with AI. Let’s push the boundaries of what’s possible, one problem at a time.
Stay tuned and happy thrashing coding!
The Ordered List of Coding with AI: A Comparative Series Posts
If you’re just starting out learning Java, here are the top 5 things you can do to get started effectively:
Set Up Your Development Environment:
Install the Java Development Kit (JDK) on your computer. You can download it from the official Oracle website or use an open-source distribution like OpenJDK. It can be confusing at first, because there are a bunch of versions you *could* get started with depending on a million different variables, just pick the latest though and get going.
Choose a code editor or Integrated Development Environment (IDE) like Eclipse, IntelliJ IDEA, or Visual Studio Code to write and run your Java code. IDEs offer features like code completion and debugging, which can be very helpful for beginners.
Learn the Basics of Java:
Start with the fundamental concepts of Java, such as variables, data types, operators, and control structures (if statements, loops).
Understand the object-oriented programming (OOP) principles that Java is based on, including classes, objects, inheritance, encapsulation, and polymorphism. Even if you do not use any of these and you’re taking a different approach (functional, top-down, etc) it’s really important to at least learn and understand the OOP concepts and capabilities of Java, as at some point you will see these and to understand what is going on, you’ll need to understand this part of Java.
I’ve been working with Java a ton this year, more so than the previous years, so I decided to put together the top three Java libraries for accessing MongoDB that I’ve been using. That top 3 list shapes up like this.
MongoDB Java Driver: This is the official Java driver provided by MongoDB. It allows Java applications to connect to MongoDB and work with data. The driver supports synchronous and asynchronous interaction with MongoDB and provides a rich set of features for database operations.
Key Methods:
MongoClients.create(): To create a new client connection to the database.
MongoDatabase.getCollection(): To access a collection from the database.
MongoCollection.find(): To find documents within a collection.
Morphia: Morphia is an Object-Document Mapper (ODM) for MongoDB and Java. It provides a higher-level, object-oriented API to interact with MongoDB, and maps Java objects to MongoDB documents.
Key Methods:
Datastore.createQuery(): To create a query for the type of entity you want to retrieve.
Datastore.save(): To save an entity to the database.
Query.asList(): To execute a query and get the results as a list.
Spring Data MongoDB: Part of the larger Spring Data project, Spring Data MongoDB provides integration with MongoDB to work with the data as easily as if it were a relational database. It’s a popular choice for Spring-based applications.
Key Methods:
MongoRepository.findAll(): To find all documents in a collection.
MongoRepository.save(): To save a given entity.
MongoRepository.findById(): To find a document by its ID.
These libraries offer comprehensive methods for connecting to and working with MongoDB from Java applications. They are widely used in the Java community and are supported by a large number of developers and organizations. Let’s dive deeper with each, and also more specifically talk about some of their respective query methods.
You must be logged in to post a comment.