Is the date alphabetical?
Clash Royale CLAN TAG#URR8PPP
up vote
5
down vote
favorite
Write a function or program that accepts a date (as a string in YYYY-MM-DD
format) as input and returns a truthy value if that date is "alphabetical," and a falsey value if it isn't.
An alphabetical date is a date whose month, day and year are in alphabetical order when expressed as a string (and when considered specifically in M - D - Y order). For example, Sept. 26 2018 is an alphabetical date:
September 26th 2018 -> September twenty-sixth two thousand eighteen
September
Twenty-sixth
Two thousand eighteen
Another way to think of this challenge: "are the elements of a given date lexically sorted?"
Notes:
- 2018 is represented as "two thousand eighteen," not "twenty eighteen" or "two zero one eight."
- 26th is represented as "twenty-sixth," not "twenty-six."
- Each element of the date is considered as a whole. This is why 2018 doesn't automatically fail even though the "e" in eighteen comes before the "t" in two.
The following dates are not alphabetical:
- September 2nd 2018 ("second" should sort ahead of "September")
- April 30th 4000 ("four thousand" should sort ahead of "thirtieth")
Additional Rules:
- You will receive the date as a string, formatted like
YYYY-MM-DD
. The year will always have four digits, and the month and day will always have two digits each. Zero-padding is not represented in the string conversion (e.g., '2000-01-01' is 'January first two thousand' as you'd expect). - You may assume that dates will always be valid (no February 30th, no Smarch 1st) and that the value of the year will be positive (no dates B.C.), but the date may be far in the future ("in the year
twonine thousand..."). - You should return a truthy or falsey value, not necessarily a boolean
True
orFalse
. If you do this in Javascript and want to return'0'
and0
that's fine. Of course, if you want to return a boolean, feel free. - Standard loopholes are forbidden.
- This is
code-golf
More Examples of Alphabetical Dates
- 2066-01-02 (January second, two thousand sixty-six)
- 1000-04-08 (April eighth, one thousand)
- 6000-08-01 (August first, six thousand)
More Examples of Non-Alphabetical Dates
- 1066-01-02 (January second, one thousand sixty-six)
- 1000-04-07 (April seventh, one thousand)
- 8000-08-01 (August first, eight thousand)
code-golf
add a comment |Â
up vote
5
down vote
favorite
Write a function or program that accepts a date (as a string in YYYY-MM-DD
format) as input and returns a truthy value if that date is "alphabetical," and a falsey value if it isn't.
An alphabetical date is a date whose month, day and year are in alphabetical order when expressed as a string (and when considered specifically in M - D - Y order). For example, Sept. 26 2018 is an alphabetical date:
September 26th 2018 -> September twenty-sixth two thousand eighteen
September
Twenty-sixth
Two thousand eighteen
Another way to think of this challenge: "are the elements of a given date lexically sorted?"
Notes:
- 2018 is represented as "two thousand eighteen," not "twenty eighteen" or "two zero one eight."
- 26th is represented as "twenty-sixth," not "twenty-six."
- Each element of the date is considered as a whole. This is why 2018 doesn't automatically fail even though the "e" in eighteen comes before the "t" in two.
The following dates are not alphabetical:
- September 2nd 2018 ("second" should sort ahead of "September")
- April 30th 4000 ("four thousand" should sort ahead of "thirtieth")
Additional Rules:
- You will receive the date as a string, formatted like
YYYY-MM-DD
. The year will always have four digits, and the month and day will always have two digits each. Zero-padding is not represented in the string conversion (e.g., '2000-01-01' is 'January first two thousand' as you'd expect). - You may assume that dates will always be valid (no February 30th, no Smarch 1st) and that the value of the year will be positive (no dates B.C.), but the date may be far in the future ("in the year
twonine thousand..."). - You should return a truthy or falsey value, not necessarily a boolean
True
orFalse
. If you do this in Javascript and want to return'0'
and0
that's fine. Of course, if you want to return a boolean, feel free. - Standard loopholes are forbidden.
- This is
code-golf
More Examples of Alphabetical Dates
- 2066-01-02 (January second, two thousand sixty-six)
- 1000-04-08 (April eighth, one thousand)
- 6000-08-01 (August first, six thousand)
More Examples of Non-Alphabetical Dates
- 1066-01-02 (January second, one thousand sixty-six)
- 1000-04-07 (April seventh, one thousand)
- 8000-08-01 (August first, eight thousand)
code-golf
1
Lousy Smarch weather.
â AdmBorkBork
2 hours ago
@Arnauld Um, no? Looks like 2018-09-02 is falsy, while 2018-09-26 is truthy (when given as in the question).
â Erik the Outgolfer
2 hours ago
@EriktheOutgolfer Right. I totally misread the challenge. (Maybe it should be rephrased as Is the date lexically sorted? or something like that.)
â Arnauld
2 hours ago
@Arnauld I tweaked the first paragraph and included a line with your suggested wording a bit further in, hopefully to the delight of future readers. Thank you!
â souldeux
2 hours ago
add a comment |Â
up vote
5
down vote
favorite
up vote
5
down vote
favorite
Write a function or program that accepts a date (as a string in YYYY-MM-DD
format) as input and returns a truthy value if that date is "alphabetical," and a falsey value if it isn't.
An alphabetical date is a date whose month, day and year are in alphabetical order when expressed as a string (and when considered specifically in M - D - Y order). For example, Sept. 26 2018 is an alphabetical date:
September 26th 2018 -> September twenty-sixth two thousand eighteen
September
Twenty-sixth
Two thousand eighteen
Another way to think of this challenge: "are the elements of a given date lexically sorted?"
Notes:
- 2018 is represented as "two thousand eighteen," not "twenty eighteen" or "two zero one eight."
- 26th is represented as "twenty-sixth," not "twenty-six."
- Each element of the date is considered as a whole. This is why 2018 doesn't automatically fail even though the "e" in eighteen comes before the "t" in two.
The following dates are not alphabetical:
- September 2nd 2018 ("second" should sort ahead of "September")
- April 30th 4000 ("four thousand" should sort ahead of "thirtieth")
Additional Rules:
- You will receive the date as a string, formatted like
YYYY-MM-DD
. The year will always have four digits, and the month and day will always have two digits each. Zero-padding is not represented in the string conversion (e.g., '2000-01-01' is 'January first two thousand' as you'd expect). - You may assume that dates will always be valid (no February 30th, no Smarch 1st) and that the value of the year will be positive (no dates B.C.), but the date may be far in the future ("in the year
twonine thousand..."). - You should return a truthy or falsey value, not necessarily a boolean
True
orFalse
. If you do this in Javascript and want to return'0'
and0
that's fine. Of course, if you want to return a boolean, feel free. - Standard loopholes are forbidden.
- This is
code-golf
More Examples of Alphabetical Dates
- 2066-01-02 (January second, two thousand sixty-six)
- 1000-04-08 (April eighth, one thousand)
- 6000-08-01 (August first, six thousand)
More Examples of Non-Alphabetical Dates
- 1066-01-02 (January second, one thousand sixty-six)
- 1000-04-07 (April seventh, one thousand)
- 8000-08-01 (August first, eight thousand)
code-golf
Write a function or program that accepts a date (as a string in YYYY-MM-DD
format) as input and returns a truthy value if that date is "alphabetical," and a falsey value if it isn't.
An alphabetical date is a date whose month, day and year are in alphabetical order when expressed as a string (and when considered specifically in M - D - Y order). For example, Sept. 26 2018 is an alphabetical date:
September 26th 2018 -> September twenty-sixth two thousand eighteen
September
Twenty-sixth
Two thousand eighteen
Another way to think of this challenge: "are the elements of a given date lexically sorted?"
Notes:
- 2018 is represented as "two thousand eighteen," not "twenty eighteen" or "two zero one eight."
- 26th is represented as "twenty-sixth," not "twenty-six."
- Each element of the date is considered as a whole. This is why 2018 doesn't automatically fail even though the "e" in eighteen comes before the "t" in two.
The following dates are not alphabetical:
- September 2nd 2018 ("second" should sort ahead of "September")
- April 30th 4000 ("four thousand" should sort ahead of "thirtieth")
Additional Rules:
- You will receive the date as a string, formatted like
YYYY-MM-DD
. The year will always have four digits, and the month and day will always have two digits each. Zero-padding is not represented in the string conversion (e.g., '2000-01-01' is 'January first two thousand' as you'd expect). - You may assume that dates will always be valid (no February 30th, no Smarch 1st) and that the value of the year will be positive (no dates B.C.), but the date may be far in the future ("in the year
twonine thousand..."). - You should return a truthy or falsey value, not necessarily a boolean
True
orFalse
. If you do this in Javascript and want to return'0'
and0
that's fine. Of course, if you want to return a boolean, feel free. - Standard loopholes are forbidden.
- This is
code-golf
More Examples of Alphabetical Dates
- 2066-01-02 (January second, two thousand sixty-six)
- 1000-04-08 (April eighth, one thousand)
- 6000-08-01 (August first, six thousand)
More Examples of Non-Alphabetical Dates
- 1066-01-02 (January second, one thousand sixty-six)
- 1000-04-07 (April seventh, one thousand)
- 8000-08-01 (August first, eight thousand)
code-golf
code-golf
edited 1 hour ago
asked 2 hours ago
souldeux
1896
1896
1
Lousy Smarch weather.
â AdmBorkBork
2 hours ago
@Arnauld Um, no? Looks like 2018-09-02 is falsy, while 2018-09-26 is truthy (when given as in the question).
â Erik the Outgolfer
2 hours ago
@EriktheOutgolfer Right. I totally misread the challenge. (Maybe it should be rephrased as Is the date lexically sorted? or something like that.)
â Arnauld
2 hours ago
@Arnauld I tweaked the first paragraph and included a line with your suggested wording a bit further in, hopefully to the delight of future readers. Thank you!
â souldeux
2 hours ago
add a comment |Â
1
Lousy Smarch weather.
â AdmBorkBork
2 hours ago
@Arnauld Um, no? Looks like 2018-09-02 is falsy, while 2018-09-26 is truthy (when given as in the question).
â Erik the Outgolfer
2 hours ago
@EriktheOutgolfer Right. I totally misread the challenge. (Maybe it should be rephrased as Is the date lexically sorted? or something like that.)
â Arnauld
2 hours ago
@Arnauld I tweaked the first paragraph and included a line with your suggested wording a bit further in, hopefully to the delight of future readers. Thank you!
â souldeux
2 hours ago
1
1
Lousy Smarch weather.
â AdmBorkBork
2 hours ago
Lousy Smarch weather.
â AdmBorkBork
2 hours ago
@Arnauld Um, no? Looks like 2018-09-02 is falsy, while 2018-09-26 is truthy (when given as in the question).
â Erik the Outgolfer
2 hours ago
@Arnauld Um, no? Looks like 2018-09-02 is falsy, while 2018-09-26 is truthy (when given as in the question).
â Erik the Outgolfer
2 hours ago
@EriktheOutgolfer Right. I totally misread the challenge. (Maybe it should be rephrased as Is the date lexically sorted? or something like that.)
â Arnauld
2 hours ago
@EriktheOutgolfer Right. I totally misread the challenge. (Maybe it should be rephrased as Is the date lexically sorted? or something like that.)
â Arnauld
2 hours ago
@Arnauld I tweaked the first paragraph and included a line with your suggested wording a bit further in, hopefully to the delight of future readers. Thank you!
â souldeux
2 hours ago
@Arnauld I tweaked the first paragraph and included a line with your suggested wording a bit further in, hopefully to the delight of future readers. Thank you!
â souldeux
2 hours ago
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
2
down vote
JavaScript (ES6), 102 bytes
Saved 4 bytes thanks to @Shaggy
Returns $0$ or $1$.
s=>'_414044406550'[[,m,d]=s.split`-`,+m]<(d=`_268328715819832871$6e10-188`[+d])&d<'_6A9338704'[s[0]]
Try it online!
104 bytes
â Shaggy
1 hour ago
@Shaggy Oops... Thism=
was, of course, completely useless. Thanks. :)
â Arnauld
1 hour ago
add a comment |Â
up vote
0
down vote
Wolfram Language 160 bytes
Returns True
or False
.
(t=ToExpression;i=IntegerName;d=StringSplit@DateString[Interpreter["Date"]@#,"MonthName"," ","Day"," ","Year"]/.m_,d_,y_:> m,i@t@d,t@y~i~"Words";d==Sort@d)&
Explanation, in steps
StrtingSplit@DateString[Interpreter["Date"]@#,"MonthName"," ","Day"," ","Year"]&["2018-09-26"]
returns
"September", "26", "2018"
/.m_,d_,y_:> m,IntegerName@ToExpression@d,ToExpression@y~IntegerName~"Words"
replaces the output with
"September", "twenty-six", "two thousand, eighteen"
and assigns this list of strings to d
.
d=Sort@d
returns True
if the list, d, is lexically sorted; otherwise it returns False
.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
JavaScript (ES6), 102 bytes
Saved 4 bytes thanks to @Shaggy
Returns $0$ or $1$.
s=>'_414044406550'[[,m,d]=s.split`-`,+m]<(d=`_268328715819832871$6e10-188`[+d])&d<'_6A9338704'[s[0]]
Try it online!
104 bytes
â Shaggy
1 hour ago
@Shaggy Oops... Thism=
was, of course, completely useless. Thanks. :)
â Arnauld
1 hour ago
add a comment |Â
up vote
2
down vote
JavaScript (ES6), 102 bytes
Saved 4 bytes thanks to @Shaggy
Returns $0$ or $1$.
s=>'_414044406550'[[,m,d]=s.split`-`,+m]<(d=`_268328715819832871$6e10-188`[+d])&d<'_6A9338704'[s[0]]
Try it online!
104 bytes
â Shaggy
1 hour ago
@Shaggy Oops... Thism=
was, of course, completely useless. Thanks. :)
â Arnauld
1 hour ago
add a comment |Â
up vote
2
down vote
up vote
2
down vote
JavaScript (ES6), 102 bytes
Saved 4 bytes thanks to @Shaggy
Returns $0$ or $1$.
s=>'_414044406550'[[,m,d]=s.split`-`,+m]<(d=`_268328715819832871$6e10-188`[+d])&d<'_6A9338704'[s[0]]
Try it online!
JavaScript (ES6), 102 bytes
Saved 4 bytes thanks to @Shaggy
Returns $0$ or $1$.
s=>'_414044406550'[[,m,d]=s.split`-`,+m]<(d=`_268328715819832871$6e10-188`[+d])&d<'_6A9338704'[s[0]]
Try it online!
edited 10 mins ago
answered 1 hour ago
Arnauld
65k581274
65k581274
104 bytes
â Shaggy
1 hour ago
@Shaggy Oops... Thism=
was, of course, completely useless. Thanks. :)
â Arnauld
1 hour ago
add a comment |Â
104 bytes
â Shaggy
1 hour ago
@Shaggy Oops... Thism=
was, of course, completely useless. Thanks. :)
â Arnauld
1 hour ago
104 bytes
â Shaggy
1 hour ago
104 bytes
â Shaggy
1 hour ago
@Shaggy Oops... This
m=
was, of course, completely useless. Thanks. :)â Arnauld
1 hour ago
@Shaggy Oops... This
m=
was, of course, completely useless. Thanks. :)â Arnauld
1 hour ago
add a comment |Â
up vote
0
down vote
Wolfram Language 160 bytes
Returns True
or False
.
(t=ToExpression;i=IntegerName;d=StringSplit@DateString[Interpreter["Date"]@#,"MonthName"," ","Day"," ","Year"]/.m_,d_,y_:> m,i@t@d,t@y~i~"Words";d==Sort@d)&
Explanation, in steps
StrtingSplit@DateString[Interpreter["Date"]@#,"MonthName"," ","Day"," ","Year"]&["2018-09-26"]
returns
"September", "26", "2018"
/.m_,d_,y_:> m,IntegerName@ToExpression@d,ToExpression@y~IntegerName~"Words"
replaces the output with
"September", "twenty-six", "two thousand, eighteen"
and assigns this list of strings to d
.
d=Sort@d
returns True
if the list, d, is lexically sorted; otherwise it returns False
.
add a comment |Â
up vote
0
down vote
Wolfram Language 160 bytes
Returns True
or False
.
(t=ToExpression;i=IntegerName;d=StringSplit@DateString[Interpreter["Date"]@#,"MonthName"," ","Day"," ","Year"]/.m_,d_,y_:> m,i@t@d,t@y~i~"Words";d==Sort@d)&
Explanation, in steps
StrtingSplit@DateString[Interpreter["Date"]@#,"MonthName"," ","Day"," ","Year"]&["2018-09-26"]
returns
"September", "26", "2018"
/.m_,d_,y_:> m,IntegerName@ToExpression@d,ToExpression@y~IntegerName~"Words"
replaces the output with
"September", "twenty-six", "two thousand, eighteen"
and assigns this list of strings to d
.
d=Sort@d
returns True
if the list, d, is lexically sorted; otherwise it returns False
.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Wolfram Language 160 bytes
Returns True
or False
.
(t=ToExpression;i=IntegerName;d=StringSplit@DateString[Interpreter["Date"]@#,"MonthName"," ","Day"," ","Year"]/.m_,d_,y_:> m,i@t@d,t@y~i~"Words";d==Sort@d)&
Explanation, in steps
StrtingSplit@DateString[Interpreter["Date"]@#,"MonthName"," ","Day"," ","Year"]&["2018-09-26"]
returns
"September", "26", "2018"
/.m_,d_,y_:> m,IntegerName@ToExpression@d,ToExpression@y~IntegerName~"Words"
replaces the output with
"September", "twenty-six", "two thousand, eighteen"
and assigns this list of strings to d
.
d=Sort@d
returns True
if the list, d, is lexically sorted; otherwise it returns False
.
Wolfram Language 160 bytes
Returns True
or False
.
(t=ToExpression;i=IntegerName;d=StringSplit@DateString[Interpreter["Date"]@#,"MonthName"," ","Day"," ","Year"]/.m_,d_,y_:> m,i@t@d,t@y~i~"Words";d==Sort@d)&
Explanation, in steps
StrtingSplit@DateString[Interpreter["Date"]@#,"MonthName"," ","Day"," ","Year"]&["2018-09-26"]
returns
"September", "26", "2018"
/.m_,d_,y_:> m,IntegerName@ToExpression@d,ToExpression@y~IntegerName~"Words"
replaces the output with
"September", "twenty-six", "two thousand, eighteen"
and assigns this list of strings to d
.
d=Sort@d
returns True
if the list, d, is lexically sorted; otherwise it returns False
.
answered 1 hour ago
DavidC
23.5k243100
23.5k243100
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f172847%2fis-the-date-alphabetical%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
Lousy Smarch weather.
â AdmBorkBork
2 hours ago
@Arnauld Um, no? Looks like 2018-09-02 is falsy, while 2018-09-26 is truthy (when given as in the question).
â Erik the Outgolfer
2 hours ago
@EriktheOutgolfer Right. I totally misread the challenge. (Maybe it should be rephrased as Is the date lexically sorted? or something like that.)
â Arnauld
2 hours ago
@Arnauld I tweaked the first paragraph and included a line with your suggested wording a bit further in, hopefully to the delight of future readers. Thank you!
â souldeux
2 hours ago