Exercises for Programmers
57 Challenges to Develop Your Coding Skills
by Brian P. Hogan
Version: P1.0 (September 2015)
Copyright 2015 The Pragmatic Programmers, LLC. This book is licensed to the individual who purchased it. We don't copy-protect it because that would limit your ability to use it for your own purposes. Please don't break this trustyou can use this across all of your devices but please do not share this copy with other members of your team, with friends, or via file sharing services. Thanks.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and The Pragmatic Programmers, LLC was aware of a trademark claim, the designations have been printed in initial capital letters or in all capitals. The Pragmatic Starter Kit, The Pragmatic Programmer, Pragmatic Programming, Pragmatic Bookshelf and the linking g device are trademarks of The Pragmatic Programmers, LLC.
Every precaution was taken in the preparation of this book. However, the publisher assumes no responsibility for errors or omissions, or for damages that may result from the use of information (including program listings) contained herein.
About the Pragmatic Bookshelf
The Pragmatic Bookshelf is an agile publishing company. Were here because we want to improve the lives of developers. We do this by creating timely, practical titles, written by programmers for programmers.
Our Pragmatic courses, workshops, and other products can help you and your team create better software and have more fun. For more information, as well as the latest Pragmatic titles, please visit us at http://pragprog.com.
Our ebooks do not contain any Digital Restrictions Management, and have always been DRM-free. We pioneered the beta book concept, where you can purchase and read a book while its still being written, and provide feedback to the author to help make a better book for everyone. Free resources for all purchasers include source code downloads (if applicable), errata and discussion forums, all available on the book's home page at pragprog.com. Were here to make your life easier.
New Book Announcements
Want to keep up on our latest titles and announcements, and occasional special offers? Just create an account on pragprog.com (an email address and a password is all it takes) and select the checkbox to receive newsletters. You can also follow us on twitter as @pragprog.
About Ebook Formats
If you buy directly from pragprog.com, you get ebooks in all available formats for one price. You can synch your ebooks amongst all your devices (including iPhone/iPad, Android, laptops, etc.) via Dropbox. You get free updates for the life of the edition. And, of course, you can always come back and re-download your books when needed. Ebooks bought from the Amazon Kindle store are subject to Amazon's polices. Limitations in Amazon's file format may cause ebooks to display differently on different devices. For more information, please see our FAQ at pragprog.com/frequently-asked-questions/ebooks. To learn more about this book and access the free resources, go to https://pragprog.com/book/bhwb, the book's homepage.
Thanks for your continued support,
Dave Thomas and Andy Hunt
The Pragmatic Programmers
The team that produced this book includes: Susannah Davidson Pfalzer (editor) Linda Recktenwald (copyeditor) Dave Thomas (layout) Janet Furlow (producer) Ellie Callahan (support)
For international rights, please contact .
Table of Contents
Copyright 2016, The Pragmatic Bookshelf.
Early praise for Exercises for Programmers
If youre looking to pick up a new programming language, you should also pick up this book. Youll learn how to solve problems from first principles, developing a stronger foundation to build on top of. I learned a lot. I expect you will too.
Stephen Orr |
Senior software engineer, Impact Applications |
A wonderful resource for learning new languages using the most effective method: practice. Because the book is language agnostic, it has almost endless replay value, which is a rare quality among technical books.
Jason Pike |
Software developer, theswiftlearner.com |
This is a wonderful book for anyone who wants to start fresh in a new language. Programmers new and old will greatly benefit from this repository of exercises. This book offers comfort for beginners and challenges for advanced programmers.
Alex Henry |
Software engineer quality assurance, JAMF Software |
Acknowledgments
First, thank you. Youre awesome. No, you really are, because youve picked up this book and made a commitment to improving your skills as a software developer. I wrote this book for people just like you, so thank you for reading.
Second, thank you, Dave Thomas, for believing in this idea and for your guidance over the years. Its been an honor and a privilege to learn from you. Your encouragement on this book means a lot, and I appreciate your generosity with your time as you reviewed the exercises and offered suggestions. You and Andy continue to make the world better for programmers, and Im grateful to be able to contribute to that in my small way.
A special thank you to Susannah Pfalzer. You always make my books better than they started out. You seem to catch all the right details, and you guide me to focus on what really matters. This is the sixth book youve helped me with, and Im a better writer because of all your guidance over the years.
Next, thank you, Andy Hunt, Mike Reilly, Michael Swaine, Fahmida Rashid, and Bruce Tate, for your encouragement when I proposed this idea.
The programs in this book are ones Ive been using to teach programming over the last ten years. Thank you to Zachary Baxter, Jordan Berg, Luke Chase, Dee Dee Dale, Jacob Donahoe, Alex Eckblad, Arrio Farugie, Emily Mikl, Aaron Miller, Eric Mohr, Zachary Solofra, Darren Sopiarz, Ashley Stevens, Miah Thalacker, Andrew Walley, and all the other students whove come through my classes and training sessions over the years. The feedback youve provided on my approach to teaching has helped me immensely. And thank you, Kyle Loewenhagen, Jon Cooley, and George Andrews, for helping me grow as a teacher with your feedback and insights.
Thank you, Deb Walsh, for your encouragement and incredible ideas on how to get the best out of students. We share core beliefs about teaching and learning, and I learn so much from our conversations. Thank you for sharing your experience and expertise with me and for your support of my teaching methods.
This book of exercises flows much better and is clarified by the fantastic feedback from a great mix of new and veteran software developers. Each reviewer put an incredible amount of time and effort into working through these problems in their favorite programming language, helping me identify things that didnt make sense or needed improvement. Thank you, Chris C., Alex Henry, Jessica Janiuk, Chris Johnson, Aaron Kalair, Sean Lindsay, Matthew Oldham, Stephen Orr, Jason Pike, Jessica Stodola, Andrew Vahey, and Mitchell Volk, for donating your valuable time to test these exercises and provide suggestions and feedback.
Thank you to my business associates Mitch Bullard, Kevin Gisi, Chris Johnson, Jeff Holland, Erich Tesky, Myles Steinhauser, Chris Warren, and Mike Weber for your support.