Welcome to Computer Science by Example! Here you can learn computer programming through a series of exercises. Each exercise is built on top of the previous applying a new concept.

To work on the exercises, you will need:

- a desktop or laptop computer with a keyboard and a screen;
- a compiler or interpreter for your programming language of choice; and
- your brain.

If you need help, read the Computer Science by Example book online or buy a physical copy (TBA).

The exercise index is divided into volumes and chapters matching the Computer Science by Example book. After solving each of the exercises, you are invited to submit your solution to an automated online judge which will give you a score and track your progress through your very own user page. Try to get a 1/1 score before moving to the next exercise.

The online judge supports solutions in: Python, C, Haskell, C++, C#, Java, JavaScript, Lua or Ruby.

This first volume of exercises introduces programming and algorithms.

Exercises in this chapter introduce basic programming concepts, such as: printing and reading from standard I/O, functions, number operations, conditionals and repetition. Beginner programmers can use this chapter to learn their first programming language. Experienced programmers can use this chapter to learn a new programming language.

- hello — writing to the screen
- cscx — writing to the screen
- repeat1 — reading and writing of integers
- hi1 — reading and writing of strings of characters
- age1 — reading and writing of integers and strings of characters
- swap1 — reading and writing of integers and strings of characters
- triple1 — functions and integer operations
- inc1 — functions and integer operations
- add1 — functions and integer operations
- mult1 — functions and integer operations
- box1 — functions and integer operations
- oddeven1 — conditionals (if)
- order1 — conditionals (if)
- good1 — conditionals (if-else-if)
- signum1 — conditionals (if-else-if)
- triangle1 — a geometry challenge
- factorial1 — recursion
- power1 — recursion
- fibonacci1 — recursion
- hello2 — repetition and loops
- total — repetition and loops
- countdown1 — repetition and loops
- seq1 — repetition and loops

Exercises in this chapter involve fundamental programming concepts. Some exercises are more challenging versions of exercises from previous chapter. Beginner programmers can use this chapter to improve their programming skills. Experienced programmers can use this chapter while learning a new programming language.

- repeat — repetition, loops and detecting EOF
- hi — reading from standard input
- age — reading and writing variables
- swap — reading and writing variables
- owes — reading and writing variables
- triple — functions and integer operations
- inc — functions and integer operations
- add — functions and integer operations
- mult — functions and integer operations
- pi — floating point numbers
- box — floating point numbers
- oddeven — conditionals (if)
- order — conditionals (if)
- good — conditionals (if-else-if)
- bmi — conditionals (if-else-if)
- triangle — a challenge
- calc — conditionals (case)
- factorial — recursion
- power — recursion
- fibonacci — recursion
- index-string — string indexing
- repeat-list — lists
- index-ints — list indexing
- replace — list modification

Exercises in this chapter involve the mathematical foundations of Computer Science: positional numeral systems, logic and boolean algebra, sets and relations. These exercises can be used both as an introduction to these topics or as additional exercises by students working through an academic module.

- digit-sum — decimal digits
- digit-count — decimal digits
- digit-reverse — decimal digits
- digit-palindrome — decimal digits
- bin2dec — binary digits (bits)
- dec2bin — binary digits (bits)
- hex2dec — hexadecimal digits
- dec2hex — hexadecimal digits
- base2base — digits in any base
- bool-not — boolean negation
- bool-and-or — boolean conjunction and disjunction
- discount — boolean expressions
- timetable — boolean expressions
- intersect — boolean expressions
- bool-calc — boolean operations
- set-member — set membership
- set-ui — set union and intersection
- set-calc — set operations
- set-size — set cardinality
- rel-ltom — relation representation
- rel-mtol — relation representation
- rel-member — relation membership
- rel-properties — relation properties
- rel-composition — relation composition

Exercises in this chapter involve the implementation of some common and basic algorithms.

- gcd — greatest common divisor
- lcm — least common multiple
- roundiv — rounded division of integers
- primes — finding primes
- cash — minimizing banknotes, change-making problem
- max-subarray — maximum subarray
- sorting — sorting arrays
- (More to be added.)

Exercises in this chapter involve practical computer foundations used in system’s programming.

- file-write — writing to files
- file-read — reading from files
- run-count — file I/O
- hello-cmd — handling command line arguments
- erro — error output
- errxit — controlling the exit code
- bytes2bits — bytes to bits
- bits2bytes — bits to byte
- kilobytes — byte conversions
- bconv — byte conversions
- file-size — computing the file size
- hconv — hertz conversions
- (More to be added.)

To be added.

To be added.

- function1 — function from points
- function — function from points
- ordinal — formatting ordinal abbreviations

*CScx, Copyright © 2020-2021 Rudy Matela, All rights reserved.*

Email: rudy [at] cscx [dot] org

I am interested in publishing a print book and ebook following the exercises presented here. The first 4 chapters are currently freely available online. If you are an editor and like the idea, contact me at rudy [at] cscx [dot] org.

If you find errors on the website like broken links, typos or incorrect/ambiguous exercise descriptions, feel free to mail me at rudy [at] cscx [dot] org.

The exercises here assume secondary education knowledge (High School / ages 17 and up). However, younger students who have not completed secondary education but are interested in programming may also benefit from these exercises (ages 13 and up).

CScx is not the first of its kind: there are other online judges, some of them are more than 10 years old. However, most online judges are focused on competitive programming problems. Here on CScx the focus is rather on introducing programming step by step with curated exercises with increasing difficulty.

More exercises will be added in the future, for example, on the topics of data structures and graphs. I may potentially release the exercise test sets for educational use in the future. This way, teachers, lecturers and professors teaching programming and CS modules will be able to run their own exercise sets.

CScx is powered by Udge Online Judge.

Copyright © 2020-2021 Rudy Matela

All rights reserved