something

This commit is contained in:
Ben Harris 2018-03-12 16:49:17 -04:00
parent 914532c7b5
commit f42732013a
9 changed files with 799 additions and 3 deletions

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
public enum Plant
{
@ -11,12 +12,41 @@ public enum Plant
public class KindergartenGarden
{
private List<string> roster;
private Dictionary<string, List<Plant>> plants;
private static readonly IDictionary<char, Plant> PlantCodesToPlants = new Dictionary<char, Plant>
{
{ 'V', Plant.Violets },
{ 'R', Plant.Radishes },
{ 'C', Plant.Clover },
{ 'G', Plant.Grass }
};
public KindergartenGarden(string diagram)
{
roster = new List<string>
{
"Alice", "Bob", "Charlie", "David",
"Eve", "Fred", "Ginny", "Harriet",
"Ileana", "Joseph", "Kincaid", "Larry"
};
BuildFromDiagram(diagram);
}
public KindergartenGarden(string diagram, IEnumerable<string> students)
{
roster = students.ToList();
BuildFromDiagram(diagram);
}
private void BuildFromDiagram(string diagram)
{
var rows = diagram.Split("\n");
foreach (var student in roster)
{
}
}
public IEnumerable<Plant> Plants(string student)

88
elixir/etl/README.md Normal file
View File

@ -0,0 +1,88 @@
# ETL
We are going to do the `Transform` step of an Extract-Transform-Load.
### ETL
Extract-Transform-Load (ETL) is a fancy way of saying, "We have some crufty, legacy data over in this system, and now we need it in this shiny new system over here, so
we're going to migrate this."
(Typically, this is followed by, "We're only going to need to run this
once." That's then typically followed by much forehead slapping and
moaning about how stupid we could possibly be.)
### The goal
We're going to extract some scrabble scores from a legacy system.
The old system stored a list of letters per score:
- 1 point: "A", "E", "I", "O", "U", "L", "N", "R", "S", "T",
- 2 points: "D", "G",
- 3 points: "B", "C", "M", "P",
- 4 points: "F", "H", "V", "W", "Y",
- 5 points: "K",
- 8 points: "J", "X",
- 10 points: "Q", "Z",
The shiny new scrabble system instead stores the score per letter, which
makes it much faster and easier to calculate the score for a word. It
also stores the letters in lower-case regardless of the case of the
input letters:
- "a" is worth 1 point.
- "b" is worth 3 points.
- "c" is worth 3 points.
- "d" is worth 2 points.
- Etc.
Your mission, should you choose to accept it, is to transform the legacy data
format to the shiny new format.
### Notes
A final note about scoring, Scrabble is played around the world in a
variety of languages, each with its own unique scoring table. For
example, an "E" is scored at 2 in the Māori-language version of the
game while being scored at 4 in the Hawaiian-language version.
## Running tests
Execute the tests with:
```bash
$ elixir etl_test.exs
```
### Pending tests
In the test suites, all but the first test have been skipped.
Once you get a test passing, you can unskip the next one by
commenting out the relevant `@tag :pending` with a `#` symbol.
For example:
```elixir
# @tag :pending
test "shouting" do
assert Bob.hey("WATCH OUT!") == "Whoa, chill out!"
end
```
Or, you can enable all the tests by commenting out the
`ExUnit.configure` line in the test suite.
```elixir
# ExUnit.configure exclude: :pending, trace: true
```
For more detailed information about the Elixir track, please
see the [help page](http://exercism.io/languages/elixir).
## Source
The Jumpstart Lab team [http://jumpstartlab.com](http://jumpstartlab.com)
## Submitting Incomplete Solutions
It's possible to submit an incomplete solution so you can see how others have completed the exercise.

16
elixir/etl/etl.exs Normal file
View File

@ -0,0 +1,16 @@
defmodule ETL do
@doc """
Transform an index into an inverted index.
## Examples
iex> ETL.transform(%{"a" => ["ABILITY", "AARDVARK"], "b" => ["BALLAST", "BEAUTY"]})
%{"ability" => "a", "aardvark" => "a", "ballast" => "b", "beauty" =>"b"}
"""
@spec transform(map) :: map
def transform(input) do
Enum.reduce(input, %{}, fn {count, words}, acc ->
Enum.reduce(words, acc, &Map.put(&2, String.downcase(&1), count))
end)
end
end

84
elixir/etl/etl_test.exs Normal file
View File

@ -0,0 +1,84 @@
if !System.get_env("EXERCISM_TEST_EXAMPLES") do
Code.load_file("etl.exs", __DIR__)
end
ExUnit.start()
ExUnit.configure(trace: true)
defmodule TransformTest do
use ExUnit.Case
# @tag :pending
test "transform one value" do
old = %{1 => ["WORLD"]}
expected = %{"world" => 1}
assert ETL.transform(old) == expected
end
@tag :pending
test "transform more values" do
old = %{1 => ["WORLD", "GSCHOOLERS"]}
expected = %{"world" => 1, "gschoolers" => 1}
assert ETL.transform(old) == expected
end
@tag :pending
test "more keys" do
old = %{1 => ["APPLE", "ARTICHOKE"], 2 => ["BOAT", "BALLERINA"]}
expected = %{
"apple" => 1,
"artichoke" => 1,
"boat" => 2,
"ballerina" => 2
}
assert ETL.transform(old) == expected
end
@tag :pending
test "full dataset" do
old = %{
1 => ~W(A E I O U L N R S T),
2 => ~W(D G),
3 => ~W(B C M P),
4 => ~W(F H V W Y),
5 => ~W(K),
8 => ~W(J X),
10 => ~W(Q Z)
}
expected = %{
"a" => 1,
"b" => 3,
"c" => 3,
"d" => 2,
"e" => 1,
"f" => 4,
"g" => 2,
"h" => 4,
"i" => 1,
"j" => 8,
"k" => 5,
"l" => 1,
"m" => 3,
"n" => 1,
"o" => 1,
"p" => 3,
"q" => 10,
"r" => 1,
"s" => 1,
"t" => 1,
"u" => 1,
"v" => 4,
"w" => 4,
"x" => 8,
"y" => 4,
"z" => 10
}
assert ETL.transform(old) == expected
end
end

View File

@ -7,8 +7,27 @@ defmodule Garden do
It decodes that string into the various gardens for each student and returns
that information in a map.
"""
@names ~w(alice bob charlie david eve fred ginny harriet ileana joseph kincaid larry)a
@flowers %{C: :clover, G: :grass, R: :radishes, V: :violets}
@spec info(String.t(), list) :: map
def info(info_string, student_names) do
def info(info_string, student_names \\ @names) do
[row1, row2] = String.split(info_string, "\n")
student_names
|> Enum.sort()
|> Enum.with_index()
|> Enum.into(%{}, fn {name, indx} ->
{name, (indx * 2)..(indx * 2 + 1)}
end)
|> Enum.into(%{}, fn {name, range} ->
{name,
(String.slice(row1, range) <> String.slice(row2, range))
|> String.codepoints()
|> Enum.map(fn plant ->
@flowers[String.to_existing_atom(plant)]
end)
|> List.to_tuple()}
end)
end
end

View File

@ -3,7 +3,7 @@ if !System.get_env("EXERCISM_TEST_EXAMPLES") do
end
ExUnit.start()
ExUnit.configure(exclude: :pending, trace: true)
ExUnit.configure(trace: true)
defmodule GardenTest do
use ExUnit.Case

68
elixir/meetup/README.md Normal file
View File

@ -0,0 +1,68 @@
# Meetup
Calculate the date of meetups.
Typically meetups happen on the same day of the week. In this exercise, you
will take a description of a meetup date, and return the actual meetup date.
Examples of general descriptions are:
- The first Monday of January 2017
- The third Tuesday of January 2017
- The wednesteenth of January 2017
- The last Thursday of January 2017
The descriptors you are expected to parse are:
first, second, third, fourth, fifth, last, monteenth, tuesteenth, wednesteenth,
thursteenth, friteenth, saturteenth, sunteenth
Note that "monteenth", "tuesteenth", etc are all made up words. There was a
meetup whose members realized that there are exactly 7 numbered days in a month
that end in '-teenth'. Therefore, one is guaranteed that each day of the week
(Monday, Tuesday, ...) will have exactly one date that is named with '-teenth'
in every month.
Given examples of a meetup dates, each containing a month, day, year, and
descriptor calculate the date of the actual meetup. For example, if given
"The first Monday of January 2017", the correct meetup date is 2017/1/2.
## Running tests
Execute the tests with:
```bash
$ elixir meetup_test.exs
```
### Pending tests
In the test suites, all but the first test have been skipped.
Once you get a test passing, you can unskip the next one by
commenting out the relevant `@tag :pending` with a `#` symbol.
For example:
```elixir
# @tag :pending
test "shouting" do
assert Bob.hey("WATCH OUT!") == "Whoa, chill out!"
end
```
Or, you can enable all the tests by commenting out the
`ExUnit.configure` line in the test suite.
```elixir
# ExUnit.configure exclude: :pending, trace: true
```
For more detailed information about the Elixir track, please
see the [help page](http://exercism.io/languages/elixir).
## Source
Jeremy Hinegardner mentioned a Boulder meetup that happens on the Wednesteenth of every month [https://twitter.com/copiousfreetime](https://twitter.com/copiousfreetime)
## Submitting Incomplete Solutions
It's possible to submit an incomplete solution so you can see how others have completed the exercise.

26
elixir/meetup/meetup.exs Normal file
View File

@ -0,0 +1,26 @@
defmodule Meetup do
@moduledoc """
Calculate meetup dates.
"""
@type weekday ::
:monday
| :tuesday
| :wednesday
| :thursday
| :friday
| :saturday
| :sunday
@type schedule :: :first | :second | :third | :fourth | :last | :teenth
@doc """
Calculate a meetup date.
The schedule is in which week (1..4, last or "teenth") the meetup date should
fall.
"""
@spec meetup(pos_integer, pos_integer, weekday, schedule) :: :calendar.date()
def meetup(year, month, weekday, schedule) do
end
end

View File

@ -0,0 +1,465 @@
if !System.get_env("EXERCISM_TEST_EXAMPLES") do
Code.load_file("meetup.exs", __DIR__)
end
ExUnit.start()
ExUnit.configure(exclude: :pending, trace: true)
defmodule MeetupTest do
use ExUnit.Case
# @tag :pending
test "monteenth of may 2013" do
assert Meetup.meetup(2013, 5, :monday, :teenth) == {2013, 5, 13}
end
@tag :pending
test "monteenth of august 2013" do
assert Meetup.meetup(2013, 8, :monday, :teenth) == {2013, 8, 19}
end
@tag :pending
test "monteenth of september 2013" do
assert Meetup.meetup(2013, 9, :monday, :teenth) == {2013, 9, 16}
end
@tag :pending
test "tuesteenth of march 2013" do
assert Meetup.meetup(2013, 3, :tuesday, :teenth) == {2013, 3, 19}
end
@tag :pending
test "tuesteenth of april 2013" do
assert Meetup.meetup(2013, 4, :tuesday, :teenth) == {2013, 4, 16}
end
@tag :pending
test "tuesteenth of august 2013" do
assert Meetup.meetup(2013, 8, :tuesday, :teenth) == {2013, 8, 13}
end
@tag :pending
test "wednesteenth of january 2013" do
assert Meetup.meetup(2013, 1, :wednesday, :teenth) == {2013, 1, 16}
end
@tag :pending
test "wednesteenth of february 2013" do
assert Meetup.meetup(2013, 2, :wednesday, :teenth) == {2013, 2, 13}
end
@tag :pending
test "wednesteenth of june 2013" do
assert Meetup.meetup(2013, 6, :wednesday, :teenth) == {2013, 6, 19}
end
@tag :pending
test "thursteenth of may 2013" do
assert Meetup.meetup(2013, 5, :thursday, :teenth) == {2013, 5, 16}
end
@tag :pending
test "thursteenth of june 2013" do
assert Meetup.meetup(2013, 6, :thursday, :teenth) == {2013, 6, 13}
end
@tag :pending
test "thursteenth of september 2013" do
assert Meetup.meetup(2013, 9, :thursday, :teenth) == {2013, 9, 19}
end
@tag :pending
test "friteenth of april 2013" do
assert Meetup.meetup(2013, 4, :friday, :teenth) == {2013, 4, 19}
end
@tag :pending
test "friteenth of august 2013" do
assert Meetup.meetup(2013, 8, :friday, :teenth) == {2013, 8, 16}
end
@tag :pending
test "friteenth of september 2013" do
assert Meetup.meetup(2013, 9, :friday, :teenth) == {2013, 9, 13}
end
@tag :pending
test "saturteenth of february 2013" do
assert Meetup.meetup(2013, 2, :saturday, :teenth) == {2013, 2, 16}
end
@tag :pending
test "saturteenth of april 2013" do
assert Meetup.meetup(2013, 4, :saturday, :teenth) == {2013, 4, 13}
end
@tag :pending
test "saturteenth of october 2013" do
assert Meetup.meetup(2013, 10, :saturday, :teenth) == {2013, 10, 19}
end
@tag :pending
test "sunteenth of may 2013" do
assert Meetup.meetup(2013, 5, :sunday, :teenth) == {2013, 5, 19}
end
@tag :pending
test "sunteenth of june 2013" do
assert Meetup.meetup(2013, 6, :sunday, :teenth) == {2013, 6, 16}
end
@tag :pending
test "sunteenth of october 2013" do
assert Meetup.meetup(2013, 10, :sunday, :teenth) == {2013, 10, 13}
end
@tag :pending
test "first monday of march 2013" do
assert Meetup.meetup(2013, 3, :monday, :first) == {2013, 3, 4}
end
@tag :pending
test "first monday of april 2013" do
assert Meetup.meetup(2013, 4, :monday, :first) == {2013, 4, 1}
end
@tag :pending
test "first tuesday of may 2013" do
assert Meetup.meetup(2013, 5, :tuesday, :first) == {2013, 5, 7}
end
@tag :pending
test "first tuesday of june 2013" do
assert Meetup.meetup(2013, 6, :tuesday, :first) == {2013, 6, 4}
end
@tag :pending
test "first wednesday of july 2013" do
assert Meetup.meetup(2013, 7, :wednesday, :first) == {2013, 7, 3}
end
@tag :pending
test "first wednesday of august 2013" do
assert Meetup.meetup(2013, 8, :wednesday, :first) == {2013, 8, 7}
end
@tag :pending
test "first thursday of september 2013" do
assert Meetup.meetup(2013, 9, :thursday, :first) == {2013, 9, 5}
end
@tag :pending
test "first thursday of october 2013" do
assert Meetup.meetup(2013, 10, :thursday, :first) == {2013, 10, 3}
end
@tag :pending
test "first friday of november 2013" do
assert Meetup.meetup(2013, 11, :friday, :first) == {2013, 11, 1}
end
@tag :pending
test "first friday of december 2013" do
assert Meetup.meetup(2013, 12, :friday, :first) == {2013, 12, 6}
end
@tag :pending
test "first saturday of january 2013" do
assert Meetup.meetup(2013, 1, :saturday, :first) == {2013, 1, 5}
end
@tag :pending
test "first saturday of february 2013" do
assert Meetup.meetup(2013, 2, :saturday, :first) == {2013, 2, 2}
end
@tag :pending
test "first sunday of march 2013" do
assert Meetup.meetup(2013, 3, :sunday, :first) == {2013, 3, 3}
end
@tag :pending
test "first sunday of april 2013" do
assert Meetup.meetup(2013, 4, :sunday, :first) == {2013, 4, 7}
end
@tag :pending
test "second monday of march 2013" do
assert Meetup.meetup(2013, 3, :monday, :second) == {2013, 3, 11}
end
@tag :pending
test "second monday of april 2013" do
assert Meetup.meetup(2013, 4, :monday, :second) == {2013, 4, 8}
end
@tag :pending
test "second tuesday of may 2013" do
assert Meetup.meetup(2013, 5, :tuesday, :second) == {2013, 5, 14}
end
@tag :pending
test "second tuesday of june 2013" do
assert Meetup.meetup(2013, 6, :tuesday, :second) == {2013, 6, 11}
end
@tag :pending
test "second wednesday of july 2013" do
assert Meetup.meetup(2013, 7, :wednesday, :second) == {2013, 7, 10}
end
@tag :pending
test "second wednesday of august 2013" do
assert Meetup.meetup(2013, 8, :wednesday, :second) == {2013, 8, 14}
end
@tag :pending
test "second thursday of september 2013" do
assert Meetup.meetup(2013, 9, :thursday, :second) == {2013, 9, 12}
end
@tag :pending
test "second thursday of october 2013" do
assert Meetup.meetup(2013, 10, :thursday, :second) == {2013, 10, 10}
end
@tag :pending
test "second friday of november 2013" do
assert Meetup.meetup(2013, 11, :friday, :second) == {2013, 11, 8}
end
@tag :pending
test "second friday of december 2013" do
assert Meetup.meetup(2013, 12, :friday, :second) == {2013, 12, 13}
end
@tag :pending
test "second saturday of january 2013" do
assert Meetup.meetup(2013, 1, :saturday, :second) == {2013, 1, 12}
end
@tag :pending
test "second saturday of february 2013" do
assert Meetup.meetup(2013, 2, :saturday, :second) == {2013, 2, 9}
end
@tag :pending
test "second sunday of march 2013" do
assert Meetup.meetup(2013, 3, :sunday, :second) == {2013, 3, 10}
end
@tag :pending
test "second sunday of april 2013" do
assert Meetup.meetup(2013, 4, :sunday, :second) == {2013, 4, 14}
end
@tag :pending
test "third monday of march 2013" do
assert Meetup.meetup(2013, 3, :monday, :third) == {2013, 3, 18}
end
@tag :pending
test "third monday of april 2013" do
assert Meetup.meetup(2013, 4, :monday, :third) == {2013, 4, 15}
end
@tag :pending
test "third tuesday of may 2013" do
assert Meetup.meetup(2013, 5, :tuesday, :third) == {2013, 5, 21}
end
@tag :pending
test "third tuesday of june 2013" do
assert Meetup.meetup(2013, 6, :tuesday, :third) == {2013, 6, 18}
end
@tag :pending
test "third wednesday of july 2013" do
assert Meetup.meetup(2013, 7, :wednesday, :third) == {2013, 7, 17}
end
@tag :pending
test "third wednesday of august 2013" do
assert Meetup.meetup(2013, 8, :wednesday, :third) == {2013, 8, 21}
end
@tag :pending
test "third thursday of september 2013" do
assert Meetup.meetup(2013, 9, :thursday, :third) == {2013, 9, 19}
end
@tag :pending
test "third thursday of october 2013" do
assert Meetup.meetup(2013, 10, :thursday, :third) == {2013, 10, 17}
end
@tag :pending
test "third friday of november 2013" do
assert Meetup.meetup(2013, 11, :friday, :third) == {2013, 11, 15}
end
@tag :pending
test "third friday of december 2013" do
assert Meetup.meetup(2013, 12, :friday, :third) == {2013, 12, 20}
end
@tag :pending
test "third saturday of january 2013" do
assert Meetup.meetup(2013, 1, :saturday, :third) == {2013, 1, 19}
end
@tag :pending
test "third saturday of february 2013" do
assert Meetup.meetup(2013, 2, :saturday, :third) == {2013, 2, 16}
end
@tag :pending
test "third sunday of march 2013" do
assert Meetup.meetup(2013, 3, :sunday, :third) == {2013, 3, 17}
end
@tag :pending
test "third sunday of april 2013" do
assert Meetup.meetup(2013, 4, :sunday, :third) == {2013, 4, 21}
end
@tag :pending
test "fourth monday of march 2013" do
assert Meetup.meetup(2013, 3, :monday, :fourth) == {2013, 3, 25}
end
@tag :pending
test "fourth monday of april 2013" do
assert Meetup.meetup(2013, 4, :monday, :fourth) == {2013, 4, 22}
end
@tag :pending
test "fourth tuesday of may 2013" do
assert Meetup.meetup(2013, 5, :tuesday, :fourth) == {2013, 5, 28}
end
@tag :pending
test "fourth tuesday of june 2013" do
assert Meetup.meetup(2013, 6, :tuesday, :fourth) == {2013, 6, 25}
end
@tag :pending
test "fourth wednesday of july 2013" do
assert Meetup.meetup(2013, 7, :wednesday, :fourth) == {2013, 7, 24}
end
@tag :pending
test "fourth wednesday of august 2013" do
assert Meetup.meetup(2013, 8, :wednesday, :fourth) == {2013, 8, 28}
end
@tag :pending
test "fourth thursday of september 2013" do
assert Meetup.meetup(2013, 9, :thursday, :fourth) == {2013, 9, 26}
end
@tag :pending
test "fourth thursday of october 2013" do
assert Meetup.meetup(2013, 10, :thursday, :fourth) == {2013, 10, 24}
end
@tag :pending
test "fourth friday of november 2013" do
assert Meetup.meetup(2013, 11, :friday, :fourth) == {2013, 11, 22}
end
@tag :pending
test "fourth friday of december 2013" do
assert Meetup.meetup(2013, 12, :friday, :fourth) == {2013, 12, 27}
end
@tag :pending
test "fourth saturday of january 2013" do
assert Meetup.meetup(2013, 1, :saturday, :fourth) == {2013, 1, 26}
end
@tag :pending
test "fourth saturday of february 2013" do
assert Meetup.meetup(2013, 2, :saturday, :fourth) == {2013, 2, 23}
end
@tag :pending
test "fourth sunday of march 2013" do
assert Meetup.meetup(2013, 3, :sunday, :fourth) == {2013, 3, 24}
end
@tag :pending
test "fourth sunday of april 2013" do
assert Meetup.meetup(2013, 4, :sunday, :fourth) == {2013, 4, 28}
end
@tag :pending
test "last monday of march 2013" do
assert Meetup.meetup(2013, 3, :monday, :last) == {2013, 3, 25}
end
@tag :pending
test "last monday of april 2013" do
assert Meetup.meetup(2013, 4, :monday, :last) == {2013, 4, 29}
end
@tag :pending
test "last tuesday of may 2013" do
assert Meetup.meetup(2013, 5, :tuesday, :last) == {2013, 5, 28}
end
@tag :pending
test "last tuesday of june 2013" do
assert Meetup.meetup(2013, 6, :tuesday, :last) == {2013, 6, 25}
end
@tag :pending
test "last wednesday of july 2013" do
assert Meetup.meetup(2013, 7, :wednesday, :last) == {2013, 7, 31}
end
@tag :pending
test "last wednesday of august 2013" do
assert Meetup.meetup(2013, 8, :wednesday, :last) == {2013, 8, 28}
end
@tag :pending
test "last thursday of september 2013" do
assert Meetup.meetup(2013, 9, :thursday, :last) == {2013, 9, 26}
end
@tag :pending
test "last thursday of october 2013" do
assert Meetup.meetup(2013, 10, :thursday, :last) == {2013, 10, 31}
end
@tag :pending
test "last friday of november 2013" do
assert Meetup.meetup(2013, 11, :friday, :last) == {2013, 11, 29}
end
@tag :pending
test "last friday of december 2013" do
assert Meetup.meetup(2013, 12, :friday, :last) == {2013, 12, 27}
end
@tag :pending
test "last saturday of january 2013" do
assert Meetup.meetup(2013, 1, :saturday, :last) == {2013, 1, 26}
end
@tag :pending
test "last saturday of february 2013" do
assert Meetup.meetup(2013, 2, :saturday, :last) == {2013, 2, 23}
end
@tag :pending
test "last sunday of march 2013" do
assert Meetup.meetup(2013, 3, :sunday, :last) == {2013, 3, 31}
end
@tag :pending
test "last sunday of april 2013" do
assert Meetup.meetup(2013, 4, :sunday, :last) == {2013, 4, 28}
end
end