Skip to content

Dozens of programming exercises broken down by easy, intermediate, advanced, lists/strings, GUI and more. Solutions added frequently.

Notifications You must be signed in to change notification settings

jamogriff/programming-exercises

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 

Repository files navigation

Programming Exercises

The following programming problems were taken from a list compiled by Adrian Neuman. I highly recommend checking out Adrian's page above for some helpful tips before jumping in. Personally I tried to work on an individual problem each day to build up my programming skillset prior to starting the Backend Engineering program at Turing.

How To Navigate this Repo

Since the problems are broken up by difficulty, this repo follows the same convention. In each difficulty directory you will find a x-solutions.rb file. Execute these in the Terminal (for example, ruby easy-solutions.rb) where you'll be greeted by CompuTron. CompuTron will provide the user a choice for what function to execute. Each function corresponds to a specific programming problem below. There will also be some other files in each directory where I expand on one of the concepts covered and build a more substantial program. Feel free to check these out as well.

Solutions

The best way to learn programming is to jump in, make mistakes, and learn from them; however, I already have a lot of prior experience in various languages to serve as a foundation. If you're brand new to programming, it may be helpful to see how I solved the problems in Ruby by viewing the x-solutions.rb files in a text editor like Atom. Now without futher ado...

Easy(ish) Programming Problems

  1. Write a program that prints Hello World to the screen.
  2. Write a program that asks the user for their name and greets them with their name.
  3. Modify the previous program such that only the users Kels and Kelsie are greeted with their names.
  4. Write a program that asks the user for a number n and prints the sum of the numbers 1 to n.
  5. Modify the previous program such that only multiples of three or five are considered in the sum (e.g. 3, 5, 6, 9, 10, 12, 15 for n = 17.
  6. Write a program that asks the user for a number n and gives them the possibility to choose between computing the sum and computing the product of 1,…,n.
  7. Write a program that prints a multiplication table for numbers up to 12.
  8. Write a program that prints all prime numbers. (Note: if your programming language does not support arbitrary size numbers, printing all primes up to the largest number you can easily represent is fine too.)
  9. Write a guessing game where the user has to guess a secret number. After every guess the program tells the user whether their number was too large or too small. At the end the number of tries needed should be printed. It counts only as one try if they input the same number multiple times consecutively.
  10. Write a program that prints the next 20 leap years.

Lists, Strings

  1. Write a function that returns the largest element in a list.
  2. Write function that reverses a list, preferably in place.
  3. Write a function that checks whether an element occurs in a list.
  4. Write a function that returns the elements on odd positions in a list.
  5. Write a function that computes the running total of a list.
  6. Write a function that tests whether a string is a palindrome.
  7. Write three functions that compute the sum of the numbers in a list: using a for-loop, a while-loop and recursion. (Subject to availability of these constructs in your language of choice.)
  8. Write a function on_all that applies a function to every element of a list. Use it to print the first twenty perfect squares. The perfect squares can be found by multiplying each natural number with itself. The first few perfect squares are 1*1= 1, 2*2=4, 3*3=9, 4*4=16. Twelve for example is not a perfect square because there is no natural number m so that m*m=12. (This question is tricky if your programming language makes it difficult to pass functions as arguments.)
  9. Write a function that concatenates two lists. [a,b,c], [1,2,3][a,b,c,1,2,3]
  10. Write a function that combines two lists by alternatingly taking elements (e.g. [a,b,c], [1,2,3][a,1,b,2,c,3].

In Process of Transferring the Rest of the Problems...

About

Dozens of programming exercises broken down by easy, intermediate, advanced, lists/strings, GUI and more. Solutions added frequently.

Topics

Resources

Stars

Watchers

Forks