10
I got into code-golfing recently and tried to write the smallest tautogram checker.
A tautogram is a sentence in which all words start with the same letter, for example: Flowers flourish from France.
Given a sentence as input, determine whether it is a tautogram.
Test Cases
Flowers flourish from France
True
This is not a Tautogram
False
I came up with this python code (because it is my main language):
print(True if len(list(set([x.upper()[0] for x in __import__('sys').argv[1:]]))) == 1 else False)
Usage:
python3 tautogram.py Flowers flourish from France
# True
python3 tautogram.py This is not a Tautogram
# False
The sentence may contain commas and periods, but no other special characters, only upper and lower case letters and spaces.
Its size is 98 bytes. Is there a smaller solution in any language?
1
Is it intended as a
– Arnauld – 2019-03-25T19:26:38.623tips
question limited toPython
? If so, these both tags should be added.2Heya friend! This site is usually reserved for explicitly defined problems. Things like "can the input contain punctuation" should be answered before posting, but other than that this is a great first question comparatively to the other new-user questions we usually see. Judging by your examples I'd just clarify that the only characters in the input will be "[A-Za-z ]" and your question will be purely objective. I'd scope out some other questions around here, else this may honestly be a better fit on overflow. – Magic Octopus Urn – 2019-03-25T19:27:35.090
1What do you mean by punctuation? Which characters are included? – Embodiment of Ignorance – 2019-03-25T19:35:47.057
1@MagicOctopusUrn Sometimes when you ask for a short solution in stackOverflow the refer to this site :) – Luis felipe De jesus Munoz – 2019-03-25T19:45:01.253
@EmbodimentofIgnorance Commas and periods, since others are special characters – Jaime Tenorio – 2019-03-25T19:49:20.397
6Welcome to PPCG! A few more test cases (including punctuation) would be a great addition to this challenge. – AdmBorkBork – 2019-03-25T20:10:27.400
1Btw, in your code, you can take out the if, printing the boolean works – Quintec – 2019-03-25T21:00:58.020
1Need the 2 outputs be consistent or will any truthy/falsey values suffice? – Shaggy – 2019-03-25T21:32:08.840
1Some potential extra test cases, to clarify:
Flowers flourish, from France
,Flowers flourish ,from France
,Flowers flourish from France.
,Flowers flourish from France .
,.Flowers flourish from France
,Flo.wers flourish fr,om France
– trichoplax – 2019-03-25T21:32:51.733With no definition of a sentence structure this is unclear. Is ", ," a valid input? Is ",This tolerable" or " This tolerable"? What about "This , ,tolerable, "? ...and what should they output? – Jonathan Allan – 2019-03-25T22:29:21.407
I'm surprised so many regulars answered rather than seeking clarity! – Jonathan Allan – 2019-03-25T22:35:51.643
1@JonathanAllan, it was pretty clear to me when originally posted that we should split on spaces and then check if the first character of every string was the same. – Shaggy – 2019-03-26T09:58:59.650
@Shaggy only because you made assumptions (I agree they were most likely correct, but as it stands they may not be). – Jonathan Allan – 2019-03-26T10:04:00.377
@JonathanAllan I answered based on the logical definition of "given a sentence."
This , ,tolerable,
isn't a sentence, for example. – AdmBorkBork – 2019-03-26T12:24:27.700@AdmBorkBork "may contain" does not specify this and could allow perfectly normal (English?) sentences to be edited to less normal ones. Regardless, this is not a fruitful discussion; I already said "most likely correct", but I cannot make it so; that is the OPs prerogative. – Jonathan Allan – 2019-03-26T12:44:41.733