This puzzle series (first published here) is based on analysing words.
Some of the statements in your puzzle input was generated by AI - hence some of the rather quirky sentence structures and words.
This article contains spoilers!
In fact, the whole article is a spoiler as it contains solutions to the puzzles. If you are trying to solve the puzzles yourself and just want some pointers to get you started, stop reading when you have enough, and return if you get stuck again, or just want to compare your solution to mine!
So, let's do some analysis to determine some parameters for the statements.
The small business owner spent his entire weekend reviewing spreadsheets to ensure he paid his taxes correctly
The web developer advised his client to be ISO-compliant so the site remains accessible to all global users
The traditional greeting was a warm "Hi oo!" sounded by the village elders whenever a friendly ship docked at the bayThe words (which may be hyphenated) contain a number of letters. Find two averages, mean and median, of the number of letters in the words of each statement and determine how many means are below, equal and above their respective medians. (Since these means and medians are for the whole statement in each case, they can be termed the population mean and median, or parameters, for the statement in question. This distinction will become relevant later.)
The full list (your puzzle input) can be found here.
One way to validate your answer is that the product of these counts is 3496. (You could factorise this but you would still need to determine which factor was which!)
I will assume you know how to get the lines in your input into separate events. I have chosen to put each line into a field called Statement.
For each event (line/statement), we need to extract the words. The rex command is well suited to this.
| rex max_match=0 field=Statement "(?i)(?<word>\b[a-z-]+\b)"There are a few things to note here:
Next, we want to remove the hyphens from the words.
| eval word=mvmap(word, replace(word, "-", ""))Now, we can establish the number of letters in the words.
| eval letters=mvmap(word, len(word))There are three types of average available, mean (or arithmetic mean), median, and mode. We are only interested in mean and median at this point. Since each statement is unique, we can use these aggregation functions over the multivalue fields in the events.
| eventstats mean(letters) as population_mean median(letters) as population_median by StatementNote that I have called these population_mean and population_median as they apply to the whole statement, not just part of the statement. (This distinction becomes clearer later.)
To complete this part of the puzzle, we need to determine whether the mean is greater than the median, or vice versa, or whether they are equal.
| eval relative_mean_median=case(population_mean < population_median, -1, population_mean > population_median, 1, true(), 0)We can now count the statements which fall into each category.
| stats count by relative_mean_medianTo validate and display this in a user-friendly way, I have appeended the following:
| eval relative=mvindex(split("Below,Equal,Above", ","), relative_mean_median + 1)
| table relative count
| transpose 0 header_field=relative
| fields - column
| eval product=Below*Equal*AboveFollowing on from the previous part of the Word-play puzzle, taking all possible samples of 5 consecutive words in each statement, determine the mean and median number of letters in the words in the sample. Sometimes, these sample means and medians (a.k.a. statistics) will be below, equal or above the corresponding population mean and median (a.k.a. parameters) for the statement as a whole - this difference is called a sampling error. These sampling errors can be in opposite directions, i.e. the sample mean will be above the population mean, while the sample median will be below the population median, and vice versa; I have chosen to call these sampling error anomalies. (Where the sample mean and median are both above or both below the population mean and median, I have chosen to call these higher or lower reinforced sampling errors respectively.) The challenge is to find which statement has the most sampling error anomalies.
(Caveat: I think it is important to point out that I am not a trained statistician and have conjured the terms "sampling error anomalies" and "(lower/higher) reinforced sampling errors" from my own imagination for the purposes of this puzzle, and they may not have any real value in statistical/data analysis. Apologies to any trained statisticians, mathematicians and data scientists, etc. if these terms are used elsewhere for a different purpose. Please feel free to provide the correct terms, if they exists!)
For this part, we need to identify which statement has the highest number of sampling error anomalies for the number of letters in the words in the samples and statement.
Having established the population mean and median, find the indexes into the multivalue field of words which start the group of five words, and create the groups of five words.
| eval groups=mvrange(0, mvcount(word) - 4)
| eval fives=mvmap(groups, mvjoin(mvindex(word, groups, groups + 4), " "))Expand the groups of five words. We could use the mvexpand command to do this, but mvexpand is known to have issues around memory usage etc. so, the stats command can be used just as effectively.
| stats count as _count by Statement population_mean population_median fivesNote the use of population_mean and population_median in the by clause; since these are constant for each statement, this is a simple way of carrying the fields through (otherwise, they might be lost with the stats command).
Now, we can split up the words in each group and determine the number of letters in each word.
| eval word=split(fives, " ")
| eval letters=mvmap(word, len(word))Determine the sample mean and median for each group of five words. (Note that the previous step split five into a new field called word, thus preserving an identifier for the group.)
| eventstats mean(letters) as sample_mean median(letters) as sample_median by Statement population_mean population_median fivesCalculate the direction of the sampling error for the sample mean and median.
| eval mean_sampling_error=case(sample_mean < population_mean, -1, sample_mean > population_mean, 1, true(), 0)
| eval median_sampling_error=case(sample_median < population_median, -1, sample_median > population_median, 1, true(), 0)Sum the number of anomalies for each statement. (By multiplying the sampling error indicators together, we can determine if one is below while the other is above their respective population averages.)
| eventstats sum(eval(if(mean_sampling_error * median_sampling_error < 0, 1, 0))) as anomalies by StatementTo find the statement with the most sampling error anomalies, simply sort in descending order and take the first event.
| sort 0 -anomalies
| head 1
| table StatementIn order to validate that you have found the correct statement, you could do this:
| stats count by Statement mean_sampling_error median_sampling_error anomalies
| sort 0 -anomalies
| streamstats dc(Statement) as _row
| where _row=1For this part, you need to determine how many US States are not represented by anagrams of their name in any statement - the anagrams can be made from up to 5 consecutive words. Where a word is used in the anagram, it must be the complete word, not just part of it.
One way to validate your answer is that the number of letters in the names of the US States without anagrams divided by the number of US States without anagrams is 8.5.
Starting with the statements, create indexes into the multivalue field of words which start the group along with the number of additional words needed in the group.
| eval words=mvrange(0,5)
| mvexpand words
| rex max_match=0 field=Statement "(?i)(?<word>\b[a-z-]+\b)"
| eval word=mvmap(word, replace(word, "-", ""))
| eval groups=mvrange(0,mvcount(word)-words)Sort the letters from each group of (up to five) words. This makes comparing anagrams easier since the letters are in a defined order.
| eval consecutive=mvmap(groups,mvjoin(mvsort(split(lower(mvjoin(mvindex(word,groups,groups+words),"")),"")),""))Gather the sorted groups of letters for each statement.
| stats values(consecutive) as consecutive by StatementGet a list of all the US States.
| eval States=split("Alabama,Alaska,Arizona,Arkansas,California,Colorado,Connecticut,Delaware,Florida,Georgia,Hawaii,Idaho,Illinois,Indiana,Iowa,Kansas,Kentucky,Louisiana,Maine,Maryland,Massachusetts,Michigan,Minnesota,Mississippi,Missouri,Montana,Nebraska,Nevada,New Hampshire,New Jersey,New Mexico,New York,North Carolina,North Dakota,Ohio,Oklahoma,Oregon,Pennsylvania,Rhode Island,South Carolina,South Dakota,Tennessee,Texas,Utah,Vermont,Virginia,Washington,West Virginia,Wisconsin,Wyoming",",")Create sorted anagrams from the names of the US States (so that they can be easily compared to the anagrams of the groups of words in the statements).
| eval state_anagrams=mvmap(States,mvjoin(mvsort(split(lower(replace(States," ","")),"")),""))For each of the US States, check if its anagram can be found in the multivalue fields with anagrams of all the possible groups of consecutive words. (Comparing a single value to a multivalue field will return true if the single value is present in the multivalue field.)
| eval index=mvrange(0, mvcount(States))
| eval State=mvjoin(mvmap(index,if(mvindex(state_anagrams,index)=consecutive,mvindex(States,index),"")),"")Create two multivalue fields, one for the US States with matching anagrams, and one for all the US States.
| stats values(State) as State values(States) as StatesJoin the two lists and count the occurrences of each US State. Where the US State appears only once, it must be because there was no anagram of its name in the groups of up to 5 words.
| eval State=mvappend(States, State)
| stats count as _count by State
| where State != "" and _count=1In order to validate your answer, you could try something like this.
| eval _letters=len(replace(State, " ", ""))
| eventstats sum(_letters) as letters count
| eval validation=letters/countSimilar to the previous part, you are now looking for anagrams of US States or their capital city, but this time only consider between 2 and 4 consecutive words, i.e. 2, 3 or 4 consecutive words.
One way to validate your answer is that there are 40 letters in the names of the US States without appropriate anagrams.
Starting with the statements, create indexes into the multivalue field of words which start the group along with the number of additional words needed in the group.
| eval words=mvrange(1,4)
| mvexpand words
| rex max_match=0 field=Statement "(?i)(?<word>\b[a-z-]+\b)"
| eval word=mvmap(word, replace(word, "-", ""))
| eval groups=mvrange(0,mvcount(word)-words)Sort the letters from each group of (between two and four) words. This makes comparing anagrams easier since the letters are in a defined order, and gather the sorted groups of letters for each statement.
| eval consecutive=mvmap(groups,mvjoin(mvsort(split(lower(mvjoin(mvindex(word,groups,groups+words),"")),"")),""))
| stats values(consecutive) as consecutive by StatementGet a list of all the US States and their capital city, and create sorted anagrams from the names of the US States and their capital city (so that they can be easily compared to the anagrams of the groups of words in the statements).
| eval States=split("Alabama,Alaska,Arizona,Arkansas,California,Colorado,Connecticut,Delaware,Florida,Georgia,Hawaii,Idaho,Illinois,Indiana,Iowa,Kansas,Kentucky,Louisiana,Maine,Maryland,Massachusetts,Michigan,Minnesota,Mississippi,Missouri,Montana,Nebraska,Nevada,New Hampshire,New Jersey,New Mexico,New York,North Carolina,North Dakota,Ohio,Oklahoma,Oregon,Pennsylvania,Rhode Island,South Carolina,South Dakota,Tennessee,Texas,Utah,Vermont,Virginia,Washington,West Virginia,Wisconsin,Wyoming",",")
| eval Capitals=split("Montgomery,Juneau,Phoenix,Little Rock,Sacramento,Denver,Hartford,Dover,Tallahassee,Atlanta,Honolulu,Boise,Springfield,Indianapolis,Des Moines,Topeka,Frankfort,Baton Rouge,Augusta,Annapolis,Boston,Lansing,Saint Paul,Jackson,Jefferson City,Helena,Lincoln,Carson City,Concord,Trenton,Santa Fe,Albany,Raleigh,Bismarck,Columbus,Oklahoma City,Salem,Harrisburg,Providence,Columbia,Pierre,Nashville,Austin,Salt Lake City,Montpelier,Richmond,Olympia,Charleston,Madison,Cheyenne",",")
| eval state_anagrams=mvmap(States,mvjoin(mvsort(split(lower(replace(States," ","")),"")),""))
| eval capital_anagrams=mvmap(Capitals,mvjoin(mvsort(split(lower(replace(Capitals," ","")),"")),""))For each of the US States, check if its anagram or the anagram for its capital city can be found in the multivalue fields with anagrams of all the possible groups of consecutive words.
| eval index=mvrange(0, mvcount(States))
| eval State=mvjoin(mvmap(index,if(mvindex(state_anagrams,index)=consecutive or mvindex(capital_anagrams,index)=consecutive,mvindex(States,index),"")),"")Create two multivalue fields, one for the US States with matching anagrams (either US State name or its capital city), and one for all the US States.
| stats values(State) as State values(States) as StatesJoin the two lists and count the occurrences of each US State. Where the US State appears only once, it must be because there was no anagram of its name or its capital city in the groups of up to two to four words.
| eval State=mvappend(States, State)
| stats count as _count by State
| where State != "" and _count=1In order to validate your answer, you could try something like this.
| eventstats sum(eval(len(State))) as lettersThis series of puzzles demonstrates the difference between parameters and statistics. It also shows how multivalue indexes can be used with the mvmap command to process multiple correlated multivalue fields, and how multivalue fields can be compared to single values.
Have questions or thoughts? Comment on this article or in Slack #puzzles channel. Whichever you prefer.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Have a tip, real-world lesson, or project to share? We’ll partner with you to refine your draft, sharpen your headings, and spotlight your work.