47
\$\begingroup\$

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

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

70 Answers 70

1
\$\begingroup\$

Pyth, 15 bytes

Vz=+ZhxGN)qZ^T2

Try it online!

The other Pyth answers use Q=eval(input()), which means the input must be in quotes in order to be valid. This program does not have that stipulation.

Pyth (indented) | Python 3 (translation)
             | G="abcdefghijklmnopqrstuvwxyz"
             | T=10
             | Z=0
             | z=input()
Vz           | for N in z:
    =+ZhxGN) |     Z+=G.find(N)+1
qZ^T2        | print(Z==T**2)
\$\endgroup\$
1
\$\begingroup\$

Pip, 11 bytes

A_-96MSa==h

Takes a string of lowercase letters as a command-line argument. Try it online!

How it works

             a is 1st command-line arg; h is 100 (implicit)
A_           An anonymous function that takes the ASCII value of its argument
  -96        and subtracts 96
     MSa     Map that to the characters of a and sum the result
        ==h  Test if that's equal to 100
             The result (0 or 1) is autoprinted

We use == (exact equality) instead of the usual = (numeric equality) because it has lower precedence than MS.

\$\endgroup\$
1
\$\begingroup\$

Add++, 18 bytes

D,f,@~,€O96€_s100=

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Julia 0.6, 27 bytes

s->sum(c->Int(c)-96,s)==100

Try it online!

\$\endgroup\$
  • 1
    \$\begingroup\$ -3 bytes using broadcast subtraction instead of map: Try it online! \$\endgroup\$ – sundar Jul 23 '18 at 23:17
1
\$\begingroup\$

Befunge-98, 14 13 bytes

+~'@ #.-"d"$#

Try it online!

Takes input as uppercase letters. Outputs 0 for truthy, any other number for falsey.

How It Works:

 ~          Get input and continue right.
+ '@   -    Subtract 64 from the letter and add it to the total
 ~          On EOF go left instead
       -"d" Subtract 100 from the total
   @  .     Print the value and end the program
\$\endgroup\$
1
\$\begingroup\$

Kotlin, 23 bytes

{it.sumBy{it-'`'}==100}

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Ahead, 21 bytes

>jvi96-+v
^~>'d=O~<~@

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Tcl, 70 bytes

puts [expr 100==[join [lmap c [split $argv ""] {scan $c %c}] -96+]-96]

Try it online!


Tcl, 71 bytes

proc D s {expr 100==[join [lmap c [split $s ""] {scan $c %c}] -96+]-96}

Try it online!


Tcl, 74 bytes

puts [expr 100==[join [lmap c [split $argv ""] {expr [scan $c %c]-96}] +]]

Try it online!

Saved a byte using a command line argument instead of a function.


Tcl, 75 bytes

proc D s {expr 100==[join [lmap c [split $s ""] {expr [scan $c %c]-96}] +]}

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Attache, 20 bytes

{100=Sum[_-96]}@Ords

Try it online!

Explanation

{100=Sum[_-96]}@Ords
               @Ords    convert input to ordinates
{             }         anonymous lambda, input: _
         _-96           subtract 96 from each char
     Sum[    ]          take the sum
 100=                   is it equal to 100?

Alternatives

20 bytes: {100=Sum[Ords@_-96]}

21 bytes: 100&`=@Sum@`-&96@Ords

22 bytes: {100=_}@Sum@`-&96@Ords

22 bytes: {100=Sum@_}@`-&96@Ords

24 bytes: {100=Sum!-~_}##STN=>List

25 bytes: {100-#_=Sum@_}##STN=>List

25 bytes: {100=Sum[_+1]}##STN=>List

26 bytes: {100=Sum[_+1]}##STN=>Chars

26 bytes: 100&`=@Sum##Succ@STN=>List

27 bytes: {100=_}@Sum##Succ@STN=>List

\$\endgroup\$
1
\$\begingroup\$

F# (Mono), 38 bytes

fun s->Seq.sumBy(fun c->int c-96)s=100

Try it online!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.