m|Y bR|ain is We|iRd. F(o)R T(h)E La|sT fi(v)e YE|ars O|R s|o, (I) ha|ve C(u)T wO|rds in h(a)lf wh|En (I) s(e)e Th|em. Wh|EN I started Do|ing it, it To|oK a meN|TaL effort - B(u)T I almost cou(l)dn't N(o)T d|o it. N(o)w, I d|o it in the back of my head, a(n)d hardly ev|en not|iCe it. However, I thought this wo|uld make a great challenge.
Definitions
For this challenge, each letter is given a point score, based on my judgement of its width in a sans-serif font. You will use this width to cut a word into two halves of equal width. The characters that this challenge will use are the alphabet in lower and upper cases, apostrophe, and hyphen.
Width Characters
1 i l I '
2 f j r t -
3 a b c d e g h k n o p q s u v x y z
4 m w A B C D E F G H J K L N O P Q R S T U V X Y Z
5 M W
For my explanations and test cases, |
denotes the location in which a word can be cleanly split in half. (
and )
on either side of a letter indicate that that letter will be split in half to create a clean split.
Input
Input will consist of a single "word" (which is not required to be in the dictionary). You can take this word in whatever text input you would like (String, char array, etc.). This word will only contain letters, '
, and -
(see above table). Because of what you will do with this word (see below), case of input is left to the developer's discretion. Trailing newlines allowed if needed.
The Task
Permutate through all forms of the input (all letters at all possible upper or lower case positions). For example, for input it's
, the below is all permutations:
it's
it'S
iT's
iT'S
It's
It'S
IT's
IT'S
To split a permutation of a word in half, the points on one side of the word must be the same as the points of the other side of the word. However, if a letter is stuck in between two even sections, you can also cut a letter cleanly in half.
Please note that "half" does not mean that you have moved halfway into the string. "Half" means that the points on both sides are equal.
Examples:
W
is 5 points. i
is 1 point. Splitting the permutation Wiiiii
in half will result in W | iiiii
, with 5 points on each side of the |
.
T
is 3 points. Splitting the permutation TTTT
in half will result in TT | TT
, with 6 points on each side of the |
.
w
is 4 points. a is 3 points. Splitting the permutation waw
in half will result in w (a) w
, with 5.5 points on each side. The points from a
are distributed to both sides, as a
is split in half.
Output
Your output is an integer of the number of unique permutations of the input that can be cleanly split in half. Trailing newlines allowed if needed.
Test Cases
I will be outputting all valid permutations of the input for the test cases. Remember that that is not part of the specs for you.
In my intermediate output, the numbers indicate the point value of the letter above them, so the output is a bit easier to visualize.
Input: a
( a )
3
( A )
4
Output: 2
Input: in
Output: 0
Input: ab
A | B
4 4
a | b
3 3
Output: 2
Input: abc
A ( B ) C
4 4 4
A ( b ) C
4 3 4
a ( B ) c
3 4 3
a ( b ) c
3 3 3
Output: 4
Input: will
W ( I ) L l
5 1 4 1
W ( I ) l L
5 1 1 4
W ( i ) L l
5 1 4 1
W ( i ) l L
5 1 1 4
w I | L l
4 1 4 1
w I | l L
4 1 1 4
w i | L l
4 1 4 1
w i | l L
4 1 1 4
Output: 8
Input: stephen
S T E ( P ) H E N
4 4 4 4 4 4 4
S T E ( p ) H E N
4 4 4 3 4 4 4
S T E | p h e n
4 4 4 3 3 3 3
S T e ( P ) H E n
4 4 3 4 4 4 3
S T e ( P ) H e N
4 4 3 4 4 3 4
S T e ( P ) h E N
4 4 3 4 3 4 4
S T e ( p ) H E n
4 4 3 3 4 4 3
S T e ( p ) H e N
4 4 3 3 4 3 4
S T e ( p ) h E N
4 4 3 3 3 4 4
S t E ( P ) H e n
4 2 4 4 4 3 3
S t E ( P ) h E n
4 2 4 4 3 4 3
S t E ( P ) h e N
4 2 4 4 3 3 4
S t E ( p ) H e n
4 2 4 3 4 3 3
S t E ( p ) h E n
4 2 4 3 3 4 3
S t E ( p ) h e N
4 2 4 3 3 3 4
S t e ( P ) h e n
4 2 3 4 3 3 3
S t e p | H E N
4 2 3 3 4 4 4
S t e ( p ) h e n
4 2 3 3 3 3 3
s T E ( P ) H E n
3 4 4 4 4 4 3
s T E ( P ) H e N
3 4 4 4 4 3 4
s T E ( P ) h E N
3 4 4 4 3 4 4
s T E ( p ) H E n
3 4 4 3 4 4 3
s T E ( p ) H e N
3 4 4 3 4 3 4
s T E ( p ) h E N
3 4 4 3 3 4 4
s T e ( P ) H e n
3 4 3 4 4 3 3
s T e ( P ) h E n
3 4 3 4 3 4 3
s T e ( P ) h e N
3 4 3 4 3 3 4
s T e ( p ) H e n
3 4 3 3 4 3 3
s T e ( p ) h E n
3 4 3 3 3 4 3
s T e ( p ) h e N
3 4 3 3 3 3 4
s t E ( P ) h e n
3 2 4 4 3 3 3
s t E p | H E N
3 2 4 3 4 4 4
s t E ( p ) h e n
3 2 4 3 3 3 3
s t e P | H E N
3 2 3 4 4 4 4
s t e p | H E n
3 2 3 3 4 4 3
s t e p | H e N
3 2 3 3 4 3 4
s t e p | h E N
3 2 3 3 3 4 4
Output: 37
Input: splitwords
S P L I T | W O r d s
4 4 4 1 4 5 4 2 3 3
<snip>
s p l i t w | o R d S
3 3 1 1 2 4 3 4 3 4
Output: 228
Input: 'a-r
' a ( - ) R
1 3 2 4
' a | - r
1 3 2 2
Output: 2
Input: '''''-
' ' ' ( ' ) ' -
1 1 1 1 1 2
Output: 1
Victory
This is code-golf, so shortest answer in bytes wins. You must be able to output all test cases (so, all inputs up to 10 characters) in a reasonable amount of time. Do not artificially cap your input.
Bounty
I do not know if this is in the realm of possibility. However, you're golfers - you'll do anything for rep. I am offering a 200 rep bounty (I'll start it once this bounty condition is fulfilled, as it seems basically impossible to me) for a program that outputs the correct output for antidisestablishmentarianism
in under 15 seconds on an average computer (aka mine). Please note that this test case must not be hard coded in any way.
@DigitalTrauma crushed my bounty, coming in well under two seconds. Check out his answer here.
antidisestablishmentarianism
(non-golfy) is83307040
(and matching all test cases) but it takes ~37 seconds on my laptop (mind you it is Python). Anyone also have a count for it? \$\endgroup\$