Week 00 Weekly Exercises

Objectives

  • Introduce you to basic Rust syntax by completing basic (1511 esque) Rust programs

Activities To Be Completed

The following is a list of all the markedactivities available to complete this week...

The following practice activities are optional and are not marked, or required to be completed for the week.

    Every exercise this week is not marked, as it's all for practice!

Getting Started

Create a new directory for this week's exercises called lab00, change to this directory, and fetch the provided code for this week by running these commands:

mkdir lab00
cd lab00
6991 fetch lab 00

Or, if you're not working on CSE, you can download the provided code as a tar file.

Exercise:
Our first rust program

Now that you've installed a rust toolchain, it's time to write your first rust program!

Your task is to create a rust program that acts just like the following example.

6991 rustc blazingly_fast.rs
./blazingly_fast
Hello world!
I am a bit rusty with this new language!
This program is 🚀 blazingly fast 🚀

Exercise:
Some basic input

Your task is to write a program, repeat.rs that reads a single line of input and then prints the line back out.

For example,

cd repeat
6991 cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.00s
     Running `target/debug/repeat`
hello there
hello there
6991 cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.00s
     Running `target/debug/repeat`
echo!
echo!
6991 cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.00s
     Running `target/debug/repeat`
it seems that our program has stumbled across what appears to be a rather lengthy line
it seems that our program has stumbled across what appears to be a rather lengthy line

Exercise:
FizzBuzz

You have been given a program, fizzbuzz.rs, that prints the numbers from 1 to 5.

Your task is to modify the program such that that prints all numbers from 1 to 100 inclusive, but for multiples of three prints Fizz instead of the number and for multiples of five prints Buzz. For numbers which are multiples of both three and five, the program should print FizzBuzz.

For example,

cd fizzbuzz
6991 cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.00s
     Running `target/debug/fizzbuzz`
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
<...>
97
98
Fizz
Buzz
If you're done these exercises, and want to keep reading (you are not required to!) then you should start with The Rust Programming Language Book.

Note that the topic ordering in the book is different to the ordering of the topics in this course!