Take home assignment for interview at Genius Monkey
Go to file
2024-07-08 12:29:29 -06:00
nix/zls WIP deck methods, added flake, and setup build deps 2024-07-05 08:49:59 -06:00
src Completed all seven deck requests 2024-07-08 11:51:39 -06:00
.envrc WIP deck methods, added flake, and setup build deps 2024-07-05 08:49:59 -06:00
.gitignore WIP deck methods, added flake, and setup build deps 2024-07-05 08:49:59 -06:00
build.zig Added release to readme, changed default build option 2024-07-08 12:29:29 -06:00
build.zig.zon WIP deck methods, added flake, and setup build deps 2024-07-05 08:49:59 -06:00
Code Exercise.pdf Added exercise and readme 2024-07-08 12:13:25 -06:00
flake.lock WIP deck methods, added flake, and setup build deps 2024-07-05 08:49:59 -06:00
flake.nix WIP deck methods, added flake, and setup build deps 2024-07-05 08:49:59 -06:00
README.md Added release to readme, changed default build option 2024-07-08 12:29:29 -06:00

Genius Deck

Specification

A simple web API that manages an in-memory deck of cards.

On starting the API, or after sorting, the default sort order from top to bottom is:

Suits: Spades > Hearts > Clubs > Diamonds
Face Values: 2 > 10 > Jack > Queen > King > Ace

Two of Spades is on top, Ace of Diamonds is at the bottom.

Source code location where the routes are defined: here

Permitted operations are as follows:

GET /deal

Takes the top card off the deck and returns it as json

GET /cheat

Peaks at the top card of the deck and returns it as json

POST /discard

Discards a card previously dealt Expects data in json in the form

{
  "face_value": "Seven",
  "suite": "Spades"
}

POST /cut

Cuts the deck at the index provided, either as query params (/cut?index=10) or json

{
  "index": 10
}

POST /rebuild

Puts the discard pile back into the deck and sorts the resulting deck

POST /sort

Orders the deck in the default sort order (see Specification)

POST /shuffle

Shuffles the current deck of cards in random order

Running

You can navigate to the releases to download a prebuilt binary for your platform, or you can run it locally yourself with Zig:

zig build run
# Or for running with params
zig build run -- -h # help menu

You will need to download Zig 0.13.0 from Zig's releases page, or from your package manager. If you use Nix flakes, a working config with direnv is already present in the repository.

Deck Method Tests

The tests can be run with Zig by running the following command in the root of the project:

zig test src/deck.zig