Skip to content

Build a tower of glasses. Fill them with champagne!

Notifications You must be signed in to change notification settings

ylathouris/moet

Repository files navigation

CircleCI Coverage


Moet

Moet is a programming exercise for the Water Overflow Problem.

Problem



Prerequisites

Before getting started, there are a few things you will need. These are as follows:

  • An internet connection
  • git installed on your machine (used to clone the source code)
  • tox installed on your machine (used to run the tests)
  • Python 3.5 or higher installed on your machine

Installation

This package has not been published to a public repository. The best way to install it is to clone the source code directly.

$ git clone https://github.com/ylathouris/moet
$ cd moet

Once you're in the root directory of the moet repository you can run the installer script. This will create a virtual environment and install moet's dependencies into that environment.

$ ./install.sh

Running The Tests

If you're looking for documentation on how the code works, the tests are the best place to start. This project uses tox, as well as pytest and hypothesis, to run and manage the tests. To execute the tests, simply run the following command from the package root:

$ tox

Starting A Shell

To start using the moet command (CLI), or the API from a Python interpreter, you'll first need to setup a suitable environment. There is a bootstrap to help with this. Simply run the following command from the package root:

$ source .venv/bin/activate

All this does is put you inside the virtual environment that was created during the installation process. To get out of the shell, run

deactivate

Command Line Interface (CLI)

Once you're in a suitable environment. You should have access to the moet command. There some example commands in this section but you can also run:

$ moet --help

Running with the defaults (no arguments)

This builds a tower of glasses with 4 rows and pours 3.75 litres of liquid into the top most glass. This should be enough liquid to completely fill each glass in the tower.

$ moet

Specify the amount of liquid

You can specify the amount of liquid to pour into the top most glass by using the --fill option. For example:

$ moet --fill 2.5

Highlight a glass

You can highlight a specific glass in the tower to get information about the amount of liquid in that glass. There are two ways to do this:

1. Provide the glass ID using the --uid option:

$ moet --fill 2.5 --uid=E

2. Provide the position of the glass (i.e. i and j) using the --position option:

$ moet --fill 2.5 --position 2 1

Show breakdown

You can show a breakdown of the liquid in each glass using the --breakdown option. For example:

$ moet --fill 3.75 --position 4 0 --breakdown

Application Programming Interface (API)

There is also a Python API you can use. Here is an example:

import moet

# Create a tower with 4 rows of glasses. 
tower = moet.create_tower(rows=4)

# Get the rows in the tower.
rows = tower.get_rows()

# Iterate over the rows:
for glasses in rows:
    for glass in glasses:
        print(">", glass.uid, glass.position, glass.quantity)

# Get a specific glass.
glass = tower.get_glass("E")

# Get the parents for that glass.
parents = tower.get_parents(glass)

# Get the children for that glass.
children = tower.get_children(glass)

About

Build a tower of glasses. Fill them with champagne!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published