Who's gonna win the football game?
MATL, 51*0.9 = 45.9 54 57 58 63 bytes
Thanks to Dennis for removing 3 bytes!
'%i To %i'j0h!3'PDFTS'tkXc=s4:Hh*sSPYD3MdXK?kK0<?Xk
An empty input string is represented in the online compiler as a single newline character.
EDIT (June 8, 2016): The link below includes a modification as per release 18.1.0 of the language (move he first 3
right before Xc
)
Try it online!
I bet on the Broncos.
Explanation
The scores are detected using a single letter, either upper or lowercase (uppercase is shown in the following):
P
for XP (1 point)D
for XD (2 points)F
for FG (3 points) and for FCK (3 points)T
for TD (6 points)S
for S (2 points)
Each of these five letters corresponds uniquely to a score event except that
F
is reused forFG
andFCK
, which have the same score. Thanks to @Dennis for this!D
will detect both TD and XD. SoT
will be assigned 4 points instead of 6 to compensate.
The ordering PDFTS
, saves a few bytes when defining the number array that specifies the points: [1,2,3,4,2]
.
Each event is detected by the presence of one of the above letters in uppercase or lowercase. The comparison is done in three dimensions: input string length (N) × number of teams (2) × number of detected score events (5). Extensive use is made of broadcasting, which is the automatic expansion of an array along a singleton dimension to match the size of a larger array.
'%i To %i' % string with format specifiers for two integers
j0h % input string. Attach 0 so it's never empty. Gives string of length N>0
! % transpose into char array of size N×1
3 % number literal
'PDFTS' % characters to detect the five combined types of score
tk % duplicate and convert to lowercase
Xc % concatenate along the third dimension to produce a 1×5×2 array
= % test for equality with broadcast. Gives N×5×2 array
s % sum along 1st dim. Gives 1×5×2 array
4:Hh % array [1,2,3,4,2] to compute the total score. Size 1×5(×1)
* % multiply with broadcast. Gives 1×5×2 array
s % sum along 2nd dim. Gives 1×1×2 array with the two scores
SP % sort in reverse order along 3rd dim
YD % sprintf. Gives output string with "To"
3M % push array with the two scores again
dXK % difference along 3rd dim. Gives a number. Copy to clipboard K
? % is it non-zero? If so we need to make either lowercase or uppercase
k % make (tentatively) lowercase
K0< % did the uppercase team win?
? % if so...
Xk % make uppercase
% implicitly end the two if's and display string
CJam, 57 55 54 53 50 49 bytes
q_32f^]{"PSFTD"f#:)5Yer1b}%_$(@:-g"ToTOto"2/=\]S*
Try it online!
I have no idea what a Bronco is, so I'll bet on the Panthers.
How it works
q Read all input from STDIN.
_ Push a copy.
32f^ XOR all characters with 32. This swaps case.
] Wrap both strings in an array.
{ }% Map; push the string S, then:
"PSFTD" Push that string (T).
f# Compute the index of each character of S in T.
:) Increment each index.
5Yer Replace 5's with 2's.
1b Add the resulting integers.
"FG" -> [3 0] -> 3
"TD" -> [4 2] -> 6
"XP" -> [0 1] -> 1
"XD" -> [0 2] -> 2
"S" -> [2] -> 2
"FCK" -> [3 0 0] -> 3
(lowercase letters) -> 0
We've now computed the scores of the first (input)
and second (swapped case) team.
_$ Push a copy of the array of scores and sort it.
( Shift out the first (lower) score.
@ Rotate the array of scores on top.
:- Reduce it by subtraction.
g Compute the sign (1, 0 or -1) of the difference.
"ToTOto"2/ Push ["To" "TO" "to"].
= Select the string that corresponds to the sign.
\ Swap it with the lower score.
] Wrap the entire stack in an array.
S* Join the resulting array, separating by spaces.
Pyth, 49 46 43 42 bytes (37.8 bytes with bonus)
jr" to "xh._-FJmsmhx"PSFT"kXd\D\S,rz2z2_SJ
Thanks to @Maltysen for helping me save 4 bytes!
Try it in the Pyth Compiler.
I like covering all bases, so I'll bet on the Broncos.
How it works
jr" to "xh._-FJmsmhx"PSFT"kXd\D\S,rz2z2_SJ Input: z
rz2 Swap the case of z.
, z Pair the result with z.
m Map; for each d in the pair:
Xd\D\S Replace each D with an S.
m Map; for each character k:
x"PSFT"k Compute k's first index on "PSFT".
h Increment the index.
s Compute the sum of the incr. indices.
"FG" -> [3, 0] -> 3
"TD" -> [4, 2] -> 6
"XP" -> [0, 1] -> 1
"XD" -> [0, 2] -> 2
"S" -> [2] -> 2
"FCK" -> [3, 0, 0] -> 3
(lowercase letters) -> 0
J Save the resulting list of scores in J.
-F Reduce J by subtraction.
._ Compute the sign of the difference.
h Add 1.
x 2 XOR the result with 2.
r" to " Pick‡ a function and apply it to " to ".
_SJ Sort and reverse the list of scores.
j Join, separating by the modified string.
‡ r
is a family of functions that operate on strings.
If the first score in
J
(corresponding to swapped casez
, i.e., the original lowercase letters) is lower than the second score, the sign function will return-1
,(-1 + 1) ^ 2 == 2
andr" to "2
isswapcase
, so it returns" TO "
.If the first score is higher than the second score, the sign function will return
1
,(1 + 1) ^ 2 == 0
andr" to "0
islowercase
, so it returns" to "
.If the scores are equal, the sign function will return
0
,(0 + 1) ^ 2 == 3
andr" to "3
istitle
, so it returns" To "
.