# 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. Apr 18, 2017 at 20:56

# 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 Apr 19, 2017 at 14:34
• Ç4+OTn%0Q was another idea I had, but it's worse. Apr 19, 2017 at 17:25
• 7 bytes Dec 8, 2021 at 0:56
• @lyxal No need for uppercase, the 4b in the current answer can simply be т for 7 bytes. Dec 8, 2021 at 11:51

# Python, 39 38 bytes

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


Try it online!

-1 byte thanks to @JonathanAllan

# 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


# Raku, 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
}


# 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.


## 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, 2017 at 0:06
• @Neil Actually, it was using reduce() during the first few minutes of the grace period when I initially posted it. Apr 19, 2017 at 10:50

# 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.

# Haskell, 32 bytes

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 Apr 19, 2017 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. Apr 18, 2017 at 21:23
• Could counting down from 100 save bytes? Also, &31 might work to make your code case insensitive.
– Neil
Apr 19, 2017 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? Apr 19, 2017 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. Apr 19, 2017 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. Apr 19, 2017 at 12:39

# Haskell, 32 bytes

f w=sum[fromEnum c-96|c<-w]==100


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

# 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. Apr 18, 2017 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? Apr 18, 2017 at 21:43
• Hm, I guess that could be done. Not that different from using a global variable in C, for example. Apr 18, 2017 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 Apr 19, 2017 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, 2017 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, 2017 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. Apr 24, 2017 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, 2017 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, 2017 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.

$@+=31&ord for/./g;$_=$@==100  Try it online! • Can you use 31&ord instead? – Neil Apr 19, 2017 at 0:07 • @Neil Hum... I've always been using -96+ for such things.. Thanks a lot for that! (but now I feel like I should go back through my old posts and replace every -96+ :x ) – Dada Apr 19, 2017 at 5:19 • The question specifies arrays are allowed as input. This can thus be briefer as a subroutine: {$@+=31&ord for@_;$@==100} (untested) Apr 19, 2017 at 6:17 • I guess it depends on context - here you're using it in a +=, but in other cases you might waste the saving on parentheses. – Neil Apr 19, 2017 at 7:44 • @msh210 The challenge says your one language's text datatypes. Arrays are hardly Perl's text datatype... (Otherwise it would have saved 1 byte indeed) – Dada Apr 19, 2017 at 7:50 # PowerShell, 36 30 bytes $args|%{$s+=$_-96};$s-eq100  Try it online! Inputs as an array, but I'm wondering if there is a better way to handle characters. EDIT Missed an easy space but @AdmBorkBork kindly let me know :P also, there was in fact a better way to handle the characters! • Hiya - a couple quick golfs. You don't need the parens around [char]$_-96, and you don't need the space between -eq and 100, getting you down to 33. You can also do "$_" instead of [char]$_, getting you down to 32. Try it online! Apr 19, 2017 at 13:01
}Tl_l
^!{100}$ Try it online! Note: Header lowercases input and splits it into words; results appear on separate lines. Edit: Saved far too many bytes thanks to @MartinEnder. • It's a lot shorter to compute the letter values by gradually lowering them while inserting characters: tio.run/nexus/… Apr 19, 2017 at 9:27 # Octave, 18 bytes @(x)sum(x-96)==100  Subtracts 96 from the input string x (lower case), to get the numeric values of the letters. Takes the sum and compares it to 100. Returns a logical 1 for truthy cases, and a logical 0 for false cases. I could save one byte if it was OK to give false for "dollar words" and true for "non-dollar words". # ///, 564210189 185 bytes /~/1\/\///4/11~3/41//6/33//2/66//5/22~a/~b/1~c/4~d/3~e/31~f/34~g/6~h/16~i/46~j/36~k/316~l/346~m/2~n/12~o/42~p/32~q/312~r/342~s/62~t/162~u/462~v/362~w/3162~x/3462~y/22~z/122~5555/0///1/0  Try it online! Prints a 1 if it is a "dollar word", otherwise prints a "0" Input is the following: (Scroll all the way to the right) /~/1\/\///4/11~3/41//6/33//2/66//5/22~a/~b/1~c/4~d/3~e/31~f/34~g/6~h/16~i/46~j/36~k/316~l/346~m/2~n/12~o/42~p/32~q/312~r/342~s/62~t/162~u/462~v/362~w/3162~x/3462~y/22~z/122~5555/0//INPUT WORD HERE/1/0  Works by replacing each letter with its value in unary, then replacing a unary 100 with a 0. It then substitutes whatever the word's value is with a 1. If the word's value is 0, then it will print a 1 because at the end of the code, it is replacing a 0. If the word's value is anything else, it will just print that 0. The golf works by using common occurrences in the code as replacements. # Japt, 13 12 10 bytes L¥U¬x_c %H  ### Explanation: L¥ U¬x _c %H L¥(U¬x(_c %H)) L¥( ) // 100== U¬ // Input split into a char array x( ) // The sum of: _ // At each char: c // Get the char-code and %H // Mod 32  Test it online! 12-bytes: L¥U¬mc m%H x  Try it online! Another 12-byte solution using a different technique L¥U¬x@;CaX Ä  Try it online! • Great job! I think you can save a byte on the first one with m%H instead of m-96 (it'll work on both cases now, bonus!), and one on the second with L¥U¬x@;CaX Ä Apr 19, 2017 at 13:18 • @ETHproductions Thanks! m%H was a nice find. x@ was a great idea too! Apr 19, 2017 at 15:39 • @ETHproductions Got it down to 10 bytes ;) Apr 19, 2017 at 18:10 # Ruby (2.4+), 38 bytes Takes input in lowercase. Requires Ruby 2.4's Array#sum so it won't run on TIO. ->a{a.chars.map{|c|c.ord-96}.sum==100}  • Use String#bytes instead of String#chars so you don't have to call c.ord. Apr 19, 2017 at 2:44 • And use sum on the array instead of map – G B Apr 19, 2017 at 6:07 # Bash + GNU utils, 47 od -An -td1 -vw1|sed 's/^/a+=-96+/;$a!a-100'|bc
`