Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

School Grades

school_grades.livemd

School Grades

Mix.install([
  {:kino, github: "livebook-dev/kino", override: true},
  {:kino_lab, "~> 0.1.0-dev", github: "jonatanklosko/kino_lab"},
  {:vega_lite, "~> 0.1.4"},
  {:kino_vega_lite, "~> 0.1.1"},
  {:benchee, "~> 0.1"},
  {:ecto, "~> 3.7"},
  {:math, "~> 0.7.0"},
  {:faker, "~> 0.17.0"},
  {:utils, path: "#{__DIR__}/../utils"},
  {:tested_cell, git: "https://github.com/BrooklinJazz/tested_cell"}
])

Navigation

Return Home Report An Issue

Must Register

Representatives from your local school system have contacted you with a problem they hope technology can solve.

School administrators need to ensure that all children between the ages of 5 and 16 are registered with a school.

They have a list of all children within the area. They need to determine based on their birthday if they will be between 5 and 16 by the cut off period of December 31st in the provided year.

The school has provided you a list of potential students. You need to filter it down to only the students who must be registered with a school.

students = [
  %{name: "Suzy", birthday: ~D[2017-12-31]},
  %{name: "Irina", birthday: ~D[2018-01-01]},
  %{name: "Victor", birthday: ~D[2005-12-31]},
  %{name: "Dina", birthday: ~D[2006-01-01]}
]

School.must_register(students, 2022)
[
  %{name: "Suzy", birthday: ~D[2015-03-23]},
  %{name: "Dina", birthday: ~D[2006-01-01]}
]

Enter your solution below.

defmodule School do
  def must_register(students, year) do
  end
end

Utils.feedback(:school_must_register, School)

School Grades

Happy with your work the administrators come back to you and ask if you can help them with another problem.

Students in this school are organized by grade according to their birthdays. They are currently manually updating existing student information to determine their grade. They would instead like to automate this process.

Given a list of students, organize them according to their grade.

They are only concerned with implementing this system with the following grade cutoffs.

  • Grade 1: Jan 1 2016 - Dec 31 2016
  • Grade 2: Jan 1 2015 - Dec 31 2015
  • Grade 3: Jan 1 2014 - Dec 31 2014
  • Grade 4: Jan 1 2013 - Dec 31 2013
  • Grade 5: Jan 1 2014 - Dec 31 2014

This assumes the current year is 2022. The cutoffs should account for the given year. Where grade 1 students are 6 years old and grade 5 students are 10 years old.

students = [
  %{name: "Name1", birthday: ~D[2016-01-01]},
  %{name: "Name2", birthday: ~D[2016-12-31]},
  %{name: "Name3", birthday: ~D[2015-01-01]},
  %{name: "Name4", birthday: ~D[2015-12-31]},
  %{name: "Name5", birthday: ~D[2014-01-01]},
  %{name: "Name6", birthday: ~D[2014-12-31]},
  %{name: "Name7", birthday: ~D[2013-01-01]},
  %{name: "Name8", birthday: ~D[2013-12-31]},
  %{name: "Name9", birthday: ~D[2012-01-01]},
  %{name: "Name10", birthday: ~D[2012-12-31]},
]

School.grades(students, 2022)
%{
  grade1: [
    %{name: "Name1", birthday: ~D[2016-01-01]},
    %{name: "Name2", birthday: ~D[2016-12-31]}
  ],
  grade2: [
    %{name: "Name3", birthday: ~D[2015-01-01]},
    %{name: "Name4", birthday: ~D[2015-12-31]},
  ],
  grade3: [
    %{name: "Name5", birthday: ~D[2014-01-01]},
    %{name: "Name6", birthday: ~D[2014-12-31]},
  ],
  grade4: [
    %{name: "Name7", birthday: ~D[2013-01-01]},
    %{name: "Name8", birthday: ~D[2013-12-31]},
  ],
  grade5: [
    %{name: "Name9", birthday: ~D[2012-01-01]},
    %{name: "Name10", birthday: ~D[2012-12-31]},
  ]
}

Enter your solution below.

defmodule School do
  def grades(students, year) do
  end
end

Utils.feedback(:school_grades, School)

Commit Your Progress

Run the following in your command line from the project folder to track and save your progress in a Git commit.

$ git add .
$ git commit -m "finish school grades exercise"