Skip to content

Commit

Permalink
add exercises for protocols and touch up content
Browse files Browse the repository at this point in the history
  • Loading branch information
BrooklinJazz committed Feb 15, 2022
1 parent 370ac90 commit d9b5f44
Show file tree
Hide file tree
Showing 19 changed files with 709 additions and 119 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/todo
2 changes: 1 addition & 1 deletion exercises/arithmetic.livemd
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ Ten times ten times ten.

```

ten to the power of two hundred and one.
Ten to the power of two hundred and one.

```elixir

Expand Down
96 changes: 0 additions & 96 deletions exercises/bottles_of_beer.livemd

This file was deleted.

95 changes: 95 additions & 0 deletions exercises/bottles_of_soda.livemd
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Bottles Of Soda

## Bottles of Soda

In the Elixir cell below create a module `BottlesOfSoda` with a function `on_the_wall/0`.
See further instructions below, you should implement each step one by one on the `BottlesOfSoda` module

```elixir

```

### Step 1

`on_the_wall/0` should

* From 99 to 1 return a list with the string

```elixir
"
X bottles of soda on the wall.
X bottles of soda.
Take one down, pass it around.
X - 1 bottles of soda on the wall.
"
```

Where the `X` is the number of bottles of soda remaining.

### Step 2

* when X is 1, use the correct grammar:

```elixir
"
1 bottle of soda on the wall.
1 bottle of soda.
Take one down, pass it around.
0 bottles of soda on the wall.
"
```

### Step 3

* When X is 0, use the following phrase:

```elixir
"
No more bottles of soda on the wall, no more bottles of soda.
Go to the store and buy some more, 99 bottles of soda on the wall.
"
```

### Step 4

* Create an `on_the_wall/1` function which takes in a positive **integer** for the `number_of_bottles` of soda on the wall.
* From `number_of_bottles` to `0`, repeat the expected song lyrics.

### Step 5

* Allow the `on_the_wall/1` function to also accept a descending **range** to perform the rhyme from.
i.e. `BottlesOfSoda.on_the_wall(99..50)`.

### Step 6

* Create an `on_the_wall/2` function which accepts an **integer** or a **range** for the first parameter.
* For the second parameter, the function should accept a "string" for the type of beverage.

For example `BottlesOfSoda.on_the_wall(99, "pop")` would start with:

```elixir
"
99 bottles of pop on the wall.
99 bottles of pop.
Take one down, pass it around.
98 bottles of pop on the wall.
"
```

### Step 7

* Create an `on_the_wall/3` function which accepts an **integer** or a **range** for the first parameter.
* For the second parameter, the function should accept a **string** for the type of beverage.
* For the third parameter, the function should accept a **string** for the beverage container.
* Ensure that `on_the_wall/3` function remains gramatically correct for `0` and `1` beverage container.

For example `BottlesOfSoda.on_the_wall(99, "pop", "can")` would start with:

```elixir
"
99 cans of pop on the wall.
99 cans of pop.
Take one down, pass it around.
98 cans of pop on the wall.
"
```
31 changes: 31 additions & 0 deletions exercises/chess_moves.livemd
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Chess Moves

## Overview

You're going to a simplified chess game with a 9 X 9 board.

<!-- livebook:{"force_markdown":true} -->

```elixir
[
[nil, nil, nil],
[nil, nil, nil],
[nil, nil, nil]
]
```

You need to create a `Piece` protocol and `can_move?` function

### Create a Checkers Board

* Create a `Checkers` module with a `new` function that returns a fresh checkers board like so,.

<!-- livebook:{"force_markdown":true} -->

```elixir
[
[nil, nil, nil],
[nil, nil, nil],
[nil, nil, nil]
]
```
27 changes: 27 additions & 0 deletions exercises/custom_rock_paper_scissors.livemd
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Rock Paper Scissors

## Custom Rock Paper Scissors

You're going to create a rock paper scissors game where users can create their own choices.

* Create a `CustomGame` struct.
* Create required keys for `:rock`, `:paper`, `:scissors`.
* Create a `CustomGame.new/3` function that allows users to enter alternate atoms for `:rock`, `:paper`, and `:scissors`.
* Create a `CustomGame.play/3` which expects the return value of `CustomGame.create_game/3` as a parameter.
The second and third parameter should expect custom atoms the user previously defined.

For example,

```elixir
game = CustomGame.new(:grass, :fire, :water)

CustomGame.play(game, :fire, :water)
"water beats fire"

CustomGame.play(game, :water, :water)
"draw"
```

```elixir

```
Loading

0 comments on commit d9b5f44

Please sign in to comment.