5 kyu

The Hunger Games - Zoo Disaster!

496 of 2,770dinglemouse

Description:

Story

A freak power outage at the zoo has caused all of the electric cage doors to malfunction and swing open...

All the animals are out and some of them are eating each other!

It's a Zoo Disaster!

Here is a list of zoo animals, and what they can eat

  • antelope eats grass
  • big-fish eats little-fish
  • bug eats leaves
  • bear eats big-fish
  • bear eats bug
  • bear eats chicken
  • bear eats cow
  • bear eats leaves
  • bear eats sheep
  • chicken eats bug
  • cow eats grass
  • fox eats chicken
  • fox eats sheep
  • giraffe eats leaves
  • lion eats antelope
  • lion eats cow
  • panda eats leaves
  • sheep eats grass

Kata Task

INPUT

A comma-separated string representing all the things at the zoo

TASK

Figure out who eats whom until no more eating is possible.

OUTPUT

A list of strings (refer to the example below) where:

  • The first element is the initial zoo (same as INPUT)
  • The last element is a comma-separated string of what the zoo looks like when all the eating has finished
  • All other elements (2nd to last-1) are of the form X eats Y describing what happened

Notes

  • Animals can only eat things beside them

  • Animals always eat to their LEFT before eating to their RIGHT

  • Always the LEFTMOST animal capable of eating will eat before any others

  • Any other things you may find at the zoo (which are not listed above) do not eat anything and are not edible

Example

Input

"fox,bug,chicken,grass,sheep"

Working

1fox can't eat bug
"fox,bug,chicken,grass,sheep"
2bug can't eat anything
"fox,bug,chicken,grass,sheep"
3chicken eats bug
"fox,chicken,grass,sheep"
4fox eats chicken
"fox,grass,sheep"
5fox can't eat grass
"fox,grass,sheep"
6grass can't eat anything
"fox,grass,sheep"
7sheep eats grass
"fox,sheep"
8fox eats sheep
"fox"

Output

["fox,bug,chicken,grass,sheep", "chicken eats bug", "fox eats chicken", "sheep eats grass", "fox eats sheep", "fox"]

Fundamentals

Stats:

CreatedApr 28, 2017
PublishedJun 7, 2017
Warriors Trained12259
Total Skips4151
Total Code Submissions33231
Total Times Completed2770
Java Completions496
JavaScript Completions854
Python Completions1064
Haskell Completions44
C# Completions263
COBOL Completions2
Go Completions53
Rust Completions41
Total Stars520
% of votes with a positive feedback rating96% of 568
Total "Very Satisfied" Votes522
Total "Somewhat Satisfied" Votes44
Total "Not Satisfied" Votes2
Total Rank Assessments8
Average Assessed Rank
5 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • dinglemouse Avatar
  • natan Avatar
  • joecastle Avatar
  • Ultramann Avatar
  • smile67 Avatar
  • Blind4Basics Avatar
  • Voile Avatar
  • hobovsky Avatar
  • akar-0 Avatar
Ad