45
9
While writing my essay for Shakespeare, I realized that I needed to shorten my quote references to more manageable lengths. I had previously been writing this:
(Act 1, Scene 2, Lines 345-346)
But I've now been told to write them like this:
(I.ii.345-6)
Clearly, I need some golfed code to golf my Shakespeare quote references down a bit.
The Task
Write a program or function that, given a string input following Template 1 or 2, print or return a string following Template 3 or 4, respectively. You only have to support Acts 1 through 5 and Scenes 1 through 9.
Templates
Template 1
(Act x, Scene y, Lines a-b)
You may assume that x
never exceeds 5, y
never exceeds 9, a
and b
are always positive integers not exceeding your language's maximum positive standard integer value, and a
is always exclusively less than b
.
Template 2
(Act x, Scene y, Line a)
Same conditions as Template 1, excluding information about b
.
Template 3
(x.y.a-b)
Where x
is a capital roman numeral, y
is a lowercase roman numeral, a
and b
are numbers, and b
is shortened to only the digits less than the first differing digit of equal significance from a
.
Template 4
(x.y.a)
Same conditions as Template 3, excluding information about b
.
Test Cases
Let f(s)
be the function defined in the Task. ""
denotes a string value.
>>> f("(Act 1, Scene 2, Lines 345-346)")
"(I.ii.345-6)"
>>> f("(Act 3, Scene 4, Lines 34-349)")
"(III.iv.34-349)"
>>> f("(Act 5, Scene 9, Lines 123-234)")
"(V.ix.123-234)"
>>> f("(Act 3, Scene 4, Line 72)")
"(III.iv.72)"
>>> f("(Act 2, Scene 3, Lines 123-133)")
"(II.iii.123-33)"
>>> f("(Act 4, Scene 8, Lines 124-133)")
"(IV.viii.124-33)"
For the purposes of this challenge, the following arabic to roman numeral translations must be supported:
1 i I
2 ii II
3 iii III
4 iv IV
5 v V
6 vi (you do not have to support past 5)
7 vii
8 viii
9 ix
Are text files allowed? – Dat – 2017-05-29T20:33:13.910
@Dat In what sense? Input, output, both? – Addison Crump – 2017-05-29T20:34:39.313
Text file as an input. – Dat – 2017-05-29T20:35:50.767
@Dat Absolutely fine. If you need a text file output, that's fine, too. Found it in the defaults for I/O. – Addison Crump – 2017-05-29T20:36:07.137
And do bytes from text file count? – Dat – 2017-05-29T20:40:44.717
Second test case is wrong. It should be
"(V.ix.123-234)"
– Luke – 2017-05-29T20:41:26.393@Dat Not if they're just your input. If they're more than just your input, no. – Addison Crump – 2017-05-29T20:41:30.897
@Luke Typo. Thanks. :D – Addison Crump – 2017-05-29T20:41:51.760
21I'm really hoping for an answer in SPL. – L3viathan – 2017-05-29T21:18:39.293
5Test case:
(Act 1, Scene 2, Lines 345-3499)
– dzaima – 2017-05-29T21:33:55.207@dzaima Ooh. Good point, magnitude check. – Addison Crump – 2017-05-29T21:34:59.430
11Who´s up for an answer in Shakespeare? – Titus – 2017-05-30T00:15:08.767
@Titus Are you nominating yourself? – MickyT – 2017-05-30T00:57:05.017
The last two test cases do not match any of the templates. They should use
Lines
instead ofLine
. – Grimmy – 2017-05-30T14:12:53.717“b is shortened to only the digits less than the first differing digit from a”: I interpret this as meaning that
34-349
should be shortened to34-9
(9 being the first differing digit), but the test case contradicts that. A clarification would be great. – Grimmy – 2017-05-30T14:19:16.5771@Grimy Fixed #1, is #2 good? – Addison Crump – 2017-05-30T14:23:19.870
Yep, they’re both good, now. Great question, btw! – Grimmy – 2017-05-30T15:58:10.433
Somebody likes Shakespeare. – Erik the Outgolfer – 2017-05-30T22:37:47.573