Definition

A dollar word is a word where when each of its letters is given a cent value, from a = 1 to z = 26, and the letters are summed, the result is 100. Here is an example on CodeReview, and here is a list of dollar words I found online.

Input

Input will be alphabetical from a-z, in your one language's text datatypes (arrays are allowed). You do not need to account for any other input - there will be no spaces, apostrophes, or hyphens. You can take as lowercase, uppercase, or a combination. Trailing newlines are allowed.

Output

Output a truthy value if the input is a dollar word, and a falsey value if it is not.

Test Cases

Truthy:

buzzy
boycott
identifies
ttttt

Falsey:

zzz
zzzzzzz
abcdefghiljjjzz
tttt
basic

This is code-golf, so the shortest answer in bytes wins! Standard loopholes and rules apply. Tie goes to first poster.

• Title has dollar words in it, sorry if it threw you off. – Stephen Apr 18 '17 at 20:56

GS2, 6 bytes

▲1Θd←q

Input must be in uppercase.

Try it online!

How it works

Θ       Combine the previous two tokens into a block and map it over the input.
▲             Push 64.
1            Subtract 64 from the character on the stack.
d      Take the sum of the resulting character array.
←     Push 100.
q    Compare the two items on the stack for equality.

Python, 39 38 bytes

lambda s:sum(ord(i)-96for i in s)==100

Try it online!

-1 byte thanks to @JonathanAllan

05AB1E, 8 bytes

Code:

Ç96-O4bQ

Uses the CP-1252 encoding. Try it online!

Explanation:

Ç          # Convert the string into a list of character codes
96-       # Subtract 96 of each element
O      # Take the sum
4b    # Push 100 (4 in binary)
Q   # Check if equal
• Tn works too :P – Magic Octopus Urn Apr 19 '17 at 14:34
• Ç4+OTn%0Q was another idea I had, but it's worse. – Magic Octopus Urn Apr 19 '17 at 17:25

Perl 6, 21 bytes

{100==[+] .ords X%32}

Try it

Alternate:

{Ⅽ==[+] .ords X%32}

Try it

Note that the is ROMAN NUMERAL ONE HUNDRED U+216D with a unival of … 100
Which takes 3 bytes to encode.

Expanded:

{  # bare block lambda with implicit parameter $_ 100 # is 100 == # equal to [+] # the sum of the following .ords # the ordinals of the input (implicit method call on$_)
X[%]  # crossed using the modulus operator
32    # with 32 to get 65..90 or 97..122 to become 1..26
}

MATL, 8 bytes

96-s100=

Uses lowercase input.

Try it online!

Explanation

The code is as readable as it gets:

96-   % Implicitly input string. Subtract 96 from each char interpreted as ASCII code
s     % Sum of array
100=  % Does it equal 100? Implicitly display

JavaScript (ES6), 46 bytes

Returns 0 or 1.

let f =

w=>[...w].map(c=>p-=parseInt(c,36)-9,p=100)|!p

console.log(f('buzzy'))
console.log(f('qwerty'))

• Interestingly when I tried reduce and recursion they both came out 2 bytes longer. – Neil Apr 19 '17 at 0:06
• @Neil Actually, it was using reduce() during the first few minutes of the grace period when I initially posted it. – Arnauld Apr 19 '17 at 10:50

f s=sum[1|c<-s,_<-['a'..c]]==100

Try it online!

The idea is to make a list of characters from a to the given character for each character in the list, and check that the total length is 100.

Other attempts:

f s=sum[1|c<-s,_<-['a'..c]]==100

f s=100==length((\c->['a'..c])=<<s)
(==100).length.(>>= \c->['a'..c])
(==100).length.(=<<)(\c->['a'..c])
(==100).length.(enumFromTo 'a'=<<)
f s=100==length(do c<-s;['a'..c])

Too bad enumFromTo is so long.

• You're right that the length is a shame—(100==).length.(enumFromTo 'a' =<<) is such a clean use of point-free-ness – Julian Wolf Apr 19 '17 at 23:58

C, 45 43 bytes

Thanks to @Neil for saving two bytes and making the solution case-insensitive!

n;f(char*s){for(n=100;*s;)n-=*s++&31;n=!n;}

Try it online!

• Seems like you can save a byte by setting n=0 globally and then skipping the first clause of the loop spec, no? edit: never mind—I guess that would only work for the very first call. – Julian Wolf Apr 18 '17 at 21:23
• Could counting down from 100 save bytes? Also, &31 might work to make your code case insensitive. – Neil Apr 19 '17 at 0:09
• Out of curiosity, how does n=!n work? I understand it checks if n is zero, because based on some test I see !0 returns 1; !15 returns 0; and !-15 returns 0 as well. But why? Which operand is ! in C when using it as !integer? – Kevin Cruijssen Apr 19 '17 at 12:11
• @KevinCruijssen ! is just the logical not. In C, 0 means false, and any other integer value means true. So !0 == 1, and !n == 0 for every n != 0. – Steadybox Apr 19 '17 at 12:15
• @Steadybox Ah, I didn't knew this part: "and any other integer value means true", but it indeed makes sense. I always (incorrectly) thought of it as 0=false; 1=true instead, hence my confusion. Thanks for the answer. – Kevin Cruijssen Apr 19 '17 at 12:39

This works for lowercase input. For uppercase, s/96/64/. Mixed-case support would add a bunch of bytes.

Mathematica, 23 bytes

100==Tr@LetterNumber@#&

Pure function taking a string (or an array of letters) as input, case-insensitive, and returning True or False. Here Tr just adds the letter-numbers together; everything else is self-explanatory.

Jelly, 9 7?* 8 bytes

ɠO%32S⁼³

Full program, outputting 1 if the input is a dollar word, or 0 if not.

Try it online!

How?

ɠO%32S⁼³ - Main link
ɠ        - read a line of input from STDIN
O       - cast to ordinals
%32    - mod 32 (vectorises) (-3*32=96 from lowercase; -2*32=64 from uppercase)
S   - sum
³ - literal: 100
⁼  - equal?

* Could it be 7 bytes?

The only reason this took input with ɠ was to keep ³ as the literal 100 rather than the 3rd command line input (1st program input).

A way to avoid that would be, as pointed out by Dennis, to create 100 using the raw literal form ȷ2 which is 102. This leads to another 8 byte O%32S=ȷ2, but this is now an unnamed monadic function (as well as operating as a full program with a 3rd argument).

Since, in golf, one may create variables or helper functions which restrict the program in which they may reside (one cannot reuse the name in-scope without stopping the function from being reusable), maybe restricting the program to only taking input from STDIN may also be acceptable, in which case the 7 byte O%32S=³ would be acceptable here as an unnamed function.

• Alternatively, O%32S=ȷ2. Works for uppercase and lowercase input. – Dennis Apr 18 '17 at 21:18
• @Dennis It may be borderline but wouldn't O%32S⁼³ actually be a valid entry as it does define an unnamed, reusable function, so long as the rest of the program it is in does not use command line arguments for input? – Jonathan Allan Apr 18 '17 at 21:43
• Hm, I guess that could be done. Not that different from using a global variable in C, for example. – Dennis Apr 18 '17 at 21:59

Alice, 23 bytes

/o!
\i@/e)q&w[?'-+k3-n

Try it online!

Input should be lower case. Prints 1 for dollar words and 0 otherwise.

Explanation

Time to show off Alice's tape and some advanced control flow. Despite being fairly good at working with integers and strings individually, Alice has no built-ins to a) determine a string's length, b) convert between characters and their code points. The reason for this is that all of Alice's commands either map integers to integers or strings to strings. But both of those would require mapping strings to integers or vice versa, so they don't fit into either of Alice's modes.

However, in addition to it's stack, Alice also has a tape and Cardinal and Ordinal mode interpret the data on the tape in different ways

• In Cardinal mode, it's a regular tape familiar from other languages like Brainfuck. You can store one integer in each cell and you can move a tape head around. The tape is infinitely long and initially holds a -1 in every cell. The cells are also indexed and the tape head starts at index 0.
• Ordinal mode has its own tape head (also starting at index 0) and it interprets the tape as a list of strings. Strings are terminated by non-character cells (i.e. any values which are not a valid Unicode code point), in particular -1. So for Ordinal mode, the tape is initially filled with empty strings.

This tape can be used for both of the above operations: to get a string length, we write it to the tape in Ordinal mode, seek the terminating -1 in Cardinal mode and retrieve the position of the tape head. To convert characters to their code points, we simply read them off the tape in Cardinal mode.

The other two important features used in this solution are the return stack and an iterator. Alice has a return stack which is usually filled when using the jump command j, and which you can pop an address from to jump back with k. However, it's also possible to push the current address to the return stack without jumping anywhere with w. If we combine w with the repeat command &, we can push the current address to the return stack n times. Now each time we reach k, one copy is popped off the return stack and we perform another iteration from w (starting at the cell after it, because the IP moves before executing another command). When the return stack becomes empty, k does nothing at all and the IP simply passes through. Hence &w...k pops an integer n and then executes ... n+1 times, which gives us a very concise way to express a simple for loop.

On to the code itself...

/     Reflect to SE. Switch to Ordinal.
i     Read the input word as a string.
Bounce off bottom boundary, move NE.
!     Store the input word on the tape.
Bounce off top boundary, move SE.
/     Reflect to E. Switch to Cardinal.
e     Push -1.
)     Seek right on the tape for a -1, which finds the -1 terminating
the input word.
q     Push the tape head's position, which gives us the string length N.
&w    Repeat this loop n+1 times (see above for an explanation)...
[     Move the tape head left by one cell.
?     Retrieve the code point of the character in that cell.
'    Push 96.
-     Subtract it from the code point to convert the letters to 1...26.
+     Add the result to a running total. This total is initialised to
zero, because in Cardinal mode, the stack is implicitly filled with
an infinite amount of zeros at the bottom.
k    End of loop.
Note that the above loop ran once more than we have characters in the
string. This is actually really convenient, because it means that we've
added a "-1 character" to the running total. After subtracting 96 to
convert it to its "letter value" this gives 97. So dollar words will
actually result in 100 - 97 = 3, which we can check against for one
byte less than for equality with 100.
3-   Subtract 3 to give 0 for dollar words.
n    Logical NOT. Turns 0 (dollar words) into 1 and everything else into 0.
The IP wraps around to the beginning of the first line.
\    Reflect to NE. Switch to Ordinal.
o    Implicitly convert the result to a string and print it.
Bounce off top boundary, move SE.
@    Terminate the program.
• Nice! I got 41 with my first try – Cows quack Apr 19 '17 at 10:09

R, 55 54 bytes

function(x)sum(match(el(strsplit(x,"")),letters))==100

-1 byte thanks to BLT

• returns a function that does the required computation, which returns TRUE and FALSE as one would expect.

• takes input in as lowercase; would only be a switch from letters to LETTERS for all uppercase

• function(x)sum(match(el(strsplit(x,"")),letters))==100 saves a byte. – BLT Apr 19 '17 at 0:35

Ruby, 25 bytes

->s{s.sum-s.size*64==100}

Works for uppercase.

I see a couple of more complex Ruby entries, but it really is this simple. s.sum adds the ASCII codes of the input string, and from this we subtract 64 times the length of the string.

Example of use

f=->s{s.sum-s.size*64==100}

puts f["ZZZ"]
• This only works on Ruby 2.4 and currently does not work on TIO – G B Apr 24 '17 at 5:51
• @GB thanks for the comment but I'm running on 2.2.6 and it works fine for me. The feature has been documented since 1.9.3. It works on TIO.run and Ideone.com for me too. – Level River St Apr 24 '17 at 19:32
• You are right, I thought it was the same as Array#sum, which is new in 2.4 – G B Apr 25 '17 at 5:29
• Actually, it's not the sum of ASCII values, the definition is "Returns a basic n-bit checksum of the characters in str". This works in this case, of course. – G B Apr 26 '17 at 9:34

Java 8, 36 bytes

s->s.chars().map(c->c%32).sum()==100

Try it online!

Note: case independent.

05AB1E, 9 bytes

5bIvAyk>-

Try it online!

Explanation

As 1 is the only truthy value in 05AB1E we can save a byte using subtraction over comparing to 100.

5b         # convert 5 to binary (results in 101)
Iv       # for each letter in input word
Ayk    # get the index of the letter in the alphabet
>   # increment
-  # subtract from total

Perl 5, 30 bytes

-1 byte thanks to @Neil (31& instead of -96+).

29 bytes of code + -p flag.

}Tl`_l