15
2
Introduction:
Since it's almost Halloween, I was just thinking of some random Halloween-themed challenges. Eventually I was reading through Frankenstein's wikipedia page, and came across the following text:
The creature
Part of Frankenstein's rejection of his creation is the fact that he does not give it a name, which causes a lack of identity. Instead it is referred to by words such as "wretch", "monster", "creature", "demon", "devil", "fiend", and "it". When Frankenstein converses with the creature in Chapter 10, he addresses it as "vile insect", "abhorred monster", "fiend", "wretched devil", and "abhorred devil".
Challenge:
Given two integers (year and chapter), output a string based on the following rules:
- If the year is less than 1818: output an empty string †
- If the year is exactly 1818 and the chapter is below 10: output a random string from the list
["wretch", "monster", "creature", "demon", "devil", "fiend", "it"]
- If the year is exactly 1818 and the chapter is 10 or higher: output a random string from the list
["vile insect", "abhorred monster", "fiend", "wretched devil", "abhorred devil"]
- Is the year above 1818 (and thus the book was published), return
"Frankenstein's Monster"
.
Challenge rules:
- You can choose whether to output in lowercase, uppercase, or a combination.
- The year will always be in the range
1500-2017
- The chapter will always be in the range
1-24
(if I googled correctly, the book has 24 chapters) - † Instead of outputting an empty string for option 1, you are also allowed to output
null
,undefined
,false
,0
, or any other value of your choice not part of the other three options (please specify what you've used in your answer). - The output may not contain any leading or trailing spaces/tabs, nor any leading new-lines. It may contain one optional trailing new-line.
General rules:
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language. - Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters, full programs. Your call.
- Default Loopholes are forbidden (especially 'Fake random numbers').
- If possible, please add a link with a test for your code.
- Also, please add an explanation if necessary.
Test cases:
year,chapter possible outputs:
1700,1 ""; null; undefined; false; 0; etc.
1700,12 ""; null; undefined; false; 0; etc.
1817,10 ""; null; undefined; false; 0; etc.
1818,1 "wretch"; "monster"; "creature"; "demon"; "devil"; "fiend"; "it"
1818,9 "wretch"; "monster"; "creature"; "demon"; "devil"; "fiend"; "it"
1818,10 "vile insect"; "abhorred monster"; "fiend"; "wretched devil"; "abhorred devil"
1818,11 "vile insect"; "abhorred monster"; "fiend"; "wretched devil"; "abhorred devil"
1818,18 "vile insect"; "abhorred monster"; "fiend"; "wretched devil"; "abhorred devil"
1819,1 "Frankenstein's Monster"; "frankenstein's monster"; "FRANKENSTEIN'S MONSTER"
1819,18 "Frankenstein's Monster"; "frankenstein's monster"; "FRANKENSTEIN'S MONSTER"
2017,24 "Frankenstein's Monster"; "frankenstein's monster"; "FRANKENSTEIN'S MONSTER"
I didn't know brace expansion was a thing in Perl at all... Using that approach, there's a great solution for the known knowns challenge! Try it online!
– Dom Hastings – 2017-10-27T07:53:42.923@DomHastings Ooh I didn’t know you could quote spaces like that. That’s -3 bytes here! – Grimmy – 2017-10-27T08:34:27.427
Glad I was able to help! I'll definitely have to try and remember this, I guess it's because
<...>
assumes globs? – Dom Hastings – 2017-10-27T08:38:56.0631<> is either readline or glob, depending on… stuff (classic Perl: the grammar is ambiguous, but the parser tries to DWYM). When it’s a glob, it closely mimics shell globs, including the brace expansion that’s a common feature in shells. – Grimmy – 2017-10-27T09:45:21.403
Could you perhaps add a TIO-link to your answer. :) It's currently the shortest answer, but I just want to make sure everything works before I accept it as the shortest. – Kevin Cruijssen – 2017-11-13T13:43:30.257
@KevinCruijssen I added a TIO link. Note that the TIO code uses
-l
for aesthetic reasons only (without it, the outputs are all concatenated on a single line, making them hard to read). Since the trailing newline is optional, that flag shouldn’t be counted in my answer’s score. – Grimmy – 2017-11-13T16:23:05.777@Grimy Thanks for adding the TIO link. And funny how you output
wretched monster
as <1818 output. :) But you're indeed right, it's not part of the other options, so indeed allowed. I've accepted your answer as the shortest. – Kevin Cruijssen – 2017-11-14T07:44:09.713