Skip to content

Instantly share code, notes, and snippets.

@bnjns
Last active June 21, 2022 12:54
Show Gist options
  • Save bnjns/06f26559c2709188e03379cd3c0f3e2f to your computer and use it in GitHub Desktop.
Save bnjns/06f26559c2709188e03379cd3c0f3e2f to your computer and use it in GitHub Desktop.

Text Statistics Tool

🧐 Background

You are given the following text:

lorem ipsum dolor sit amet consectetur lorem ipsum et mihi quoniam et adipiscing elit.sed quoniam et advesperascit et mihi ad villam revertendum est nunc quidem hactenus ex rebus enim timiditas non ex vocabulis nascitur.nummus in croesi divitiis obscuratur pars est tamen divitiarum.nam quibus rebus efficiuntur voluptates eae non sunt in potestate sapientis.hoc mihi cum tuo fratre convenit.qui ita affectus beatum esse numquam probabis duo reges constructio interrete.de hominibus dici non necesse est.eam si varietatem diceres intellegerem ut etiam non dicente te intellego parvi enim primo ortu sic iacent tamquam omnino sine animo sint.ea possunt paria non esse.quamquam tu hanc copiosiorem etiam soles dicere.de quibus cupio scire quid sentias.universa enim illorum ratione cum tota vestra confligendum puto.ut nemo dubitet eorum omnia officia quo spectare quid sequi quid fugere debeant nunc vero a primo quidem mirabiliter occulta natura est nec perspici nec cognosci potest.videmusne ut pueri ne verberibus quidem a contemplandis rebus perquirendisque deterreantur sunt enim prima elementa naturae quibus auctis virtutis quasi germen efficitur.nam ut sint illa vendibiliora haec uberiora certe sunt.cur deinde metrodori liberos commendas.mihi inquam qui te id ipsum rogavi nam adhuc meo fortasse vitio quid ego quaeram non perspicis.quibus ego vehementer assentior.cur iustitia laudatur mihi enim satis est ipsis non satis.quid est enim aliud esse versutum nobis heracleotes ille dionysius flagitiose descivisse videtur a stoicis propter oculorum dolorem.diodorus eius auditor adiungit ad honestatem vacuitatem doloris.nos quidem virtutes sic natae sumus ut tibi serviremus aliud negotii nihil habemus.

Here are a few facts and definition about the text above:

  • Everything is lowercase.
  • There are only letters, full stops (.), and single whitespace characters.
  • A word is defined as a sequence of letters delimited by either a whitespace or a full stop . character.
  • A full stop character is not considered a word. A full stop is never preceded or followed by whitespace.
  • Any two words are separated either by a single whitespace character (dolor sit), or by a full stop with no spaces (elit.sed)
  • A sentence is defined as a sequence of words delimited by a full stop . character.

⛏️ Task

Write a solution that can provide the following statistics:

  1. How many words are there in the text? (260)
  2. How many sentences are there in the text? (22)
  3. What is the length of the longest word? (15)
  4. Which six words occur the most in the text? (non, est, enim, ut, quid, mihi)
  5. What percentage of the words only occur once, excluding duplicates? (82%, rounded down)
  6. What is the average number of words per sentence? (11, rounded down)
  7. Which three two-word phrases occur the most in the text? ("lorem ipsum", "et mihi", "quoniam et")

💡 Tips

  • You are free to copy paste the text above as a string in your preferred language, there is no need to read from a file
  • We have cleaned up the text to meet the definition above, and for now you do not need to worry about the general case
  • Treat this like you are building a product we wish to eventually deploy
  • Strive to write clear and maintainable code; performance comes later
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment