54
\$\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\$
1
  • 25
    \$\begingroup\$ Title has dollar words in it, sorry if it threw you off. \$\endgroup\$
    – Stephen
    Commented Apr 18, 2017 at 20:56

86 Answers 86

14
\$\begingroup\$

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

Python, 39 38 bytes

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

Try it online!


-1 byte thanks to @JonathanAllan

\$\endgroup\$
0
12
\$\begingroup\$

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
\$\endgroup\$
12
\$\begingroup\$

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
}
\$\endgroup\$
7
\$\begingroup\$

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.
\$\endgroup\$
7
\$\begingroup\$

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'))

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

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.

\$\endgroup\$
7
\$\begingroup\$

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=sum[fromEnum c-96|c<-s]==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.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ You're right that the length is a shame—(100==).length.(enumFromTo 'a' =<<) is such a clean use of point-free-ness \$\endgroup\$ Commented Apr 19, 2017 at 23:58
7
\$\begingroup\$

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!

\$\endgroup\$
5
  • \$\begingroup\$ 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. \$\endgroup\$ Commented Apr 18, 2017 at 21:23
  • 3
    \$\begingroup\$ Could counting down from 100 save bytes? Also, &31 might work to make your code case insensitive. \$\endgroup\$
    – Neil
    Commented Apr 19, 2017 at 0:09
  • \$\begingroup\$ 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? \$\endgroup\$ Commented Apr 19, 2017 at 12:11
  • \$\begingroup\$ @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. \$\endgroup\$
    – Steadybox
    Commented Apr 19, 2017 at 12:15
  • \$\begingroup\$ @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. \$\endgroup\$ Commented Apr 19, 2017 at 12:39
6
\$\begingroup\$

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.

\$\endgroup\$
6
\$\begingroup\$

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.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Alternatively, O%32S=ȷ2. Works for uppercase and lowercase input. \$\endgroup\$
    – Dennis
    Commented Apr 18, 2017 at 21:18
  • \$\begingroup\$ @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? \$\endgroup\$ Commented Apr 18, 2017 at 21:43
  • \$\begingroup\$ Hm, I guess that could be done. Not that different from using a global variable in C, for example. \$\endgroup\$
    – Dennis
    Commented Apr 18, 2017 at 21:59
6
\$\begingroup\$

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.
\$\endgroup\$
1
  • \$\begingroup\$ Nice! I got 41 with my first try \$\endgroup\$
    – user41805
    Commented Apr 19, 2017 at 10:09
6
\$\begingroup\$

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

\$\endgroup\$
1
  • 1
    \$\begingroup\$ function(x)sum(match(el(strsplit(x,"")),letters))==100 saves a byte. \$\endgroup\$
    – BLT
    Commented Apr 19, 2017 at 0:35
6
\$\begingroup\$

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["ADIABATICALLY"]
puts f["ZZZ"]
\$\endgroup\$
4
  • \$\begingroup\$ This only works on Ruby 2.4 and currently does not work on TIO \$\endgroup\$
    – G B
    Commented Apr 24, 2017 at 5:51
  • 1
    \$\begingroup\$ @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. \$\endgroup\$ Commented Apr 24, 2017 at 19:32
  • \$\begingroup\$ You are right, I thought it was the same as Array#sum, which is new in 2.4 \$\endgroup\$
    – G B
    Commented Apr 25, 2017 at 5:29
  • \$\begingroup\$ 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. \$\endgroup\$
    – G B
    Commented Apr 26, 2017 at 9:34
6
\$\begingroup\$

Java 8, 36 bytes

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

Try it online!

Note: case independent.

\$\endgroup\$
5
\$\begingroup\$

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
\$\endgroup\$
5
\$\begingroup\$

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!

\$\endgroup\$
7
  • \$\begingroup\$ Can you use 31&ord instead? \$\endgroup\$
    – Neil
    Commented Apr 19, 2017 at 0:07
  • \$\begingroup\$ @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 ) \$\endgroup\$
    – Dada
    Commented Apr 19, 2017 at 5:19
  • \$\begingroup\$ The question specifies arrays are allowed as input. This can thus be briefer as a subroutine: {$@+=31&ord for@_;$@==100} (untested) \$\endgroup\$
    – msh210
    Commented Apr 19, 2017 at 6:17
  • \$\begingroup\$ I guess it depends on context - here you're using it in a +=, but in other cases you might waste the saving on parentheses. \$\endgroup\$
    – Neil
    Commented Apr 19, 2017 at 7:44
  • \$\begingroup\$ @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) \$\endgroup\$
    – Dada
    Commented Apr 19, 2017 at 7:50
5
\$\begingroup\$

Retina, 47 23 bytes

\w
!$&
}T`l`_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.

\$\endgroup\$
1
  • \$\begingroup\$ It's a lot shorter to compute the letter values by gradually lowering them while inserting characters: tio.run/nexus/… \$\endgroup\$ Commented Apr 19, 2017 at 9:27
5
\$\begingroup\$

PowerShell, 36 30 bytes

$args|%{$s+=$_[0]-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!

\$\endgroup\$
3
  • \$\begingroup\$ 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 "$_"[0] instead of [char]$_, getting you down to 32. Try it online! \$\endgroup\$ Commented Apr 19, 2017 at 13:01
  • \$\begingroup\$ Are the " around $_ necessary? It appears to work without the cast. Could it be due to the input being a string array already? \$\endgroup\$
    – Sinusoid
    Commented Apr 19, 2017 at 13:32
  • \$\begingroup\$ Ah, indeed you are correct. The " aren't needed in this particular instance. \$\endgroup\$ Commented Apr 19, 2017 at 13:34
5
\$\begingroup\$

Alice, 28 18 bytes

Thanks to @MartinEnder for golfing 10 bytes

=I.!'`-+?hn
>3-nO@

Try it online!

This submission uses a different method than @MartinEnder's answer.

This submission outputs 0x00 for falsy and 0x01 for truthy.

So here is a version that outputs 0 or 1 instead: Try it!

Explanation

The explanation below is for the "visible" version. Both are very similar, except in the first program, the last o doesn't convert the 0 or 1 into a string (because we are in cardinal mode), but instead takes the number and output the character at that code point.

=                 Does nothing, but will be useful later on
I                 Read a character and push its code point onto the stack
                  If there is no more input, -1 is pushed instead
.                 Duplicate it
!                 Store it on the tape
#                 Skip the next command
o                 Gets skipped
'`                Push 96
-                 Subtract it from the character
+                 And add it to the total
?                 Load the number on the tape
h                 Increment it
n                 And negate it
                  For all characters that are read, ?hn results in 0,
                  but if -1 is pushed, then the result becomes 1

After this the IP wraps around to the left edge at the =. If the top value of the stack is 0, the IP continues on with its path, increasing the total sum of all the characters, once it is done with the input (the top of the stack will be 1), then the IP turns right (90 degrees clockwise).

One thing is important to note, the loop on the first line will iterate once after the input has ended. This will subtract 97 (96 from the '` and -1 from the lack of input) from the total.

>                Set the direction of the IP to East
3-               Subtract 3 from it (yields 0 if sum is 100, something else otherwise)
n                Negate it; Zero becomes 1, non-zero numbers become 0
/                Mirror; the IP gets redirected South-East
                 The IP reflects off the bottom and goes North-East
                 Now the program is in Ordinal mode, where numbers are automatically converted into strings when being used
o                Output the top of the stack as a string
                 IP reflects off the top and heads South-East
@                End the program
\$\endgroup\$
0
5
\$\begingroup\$

Taxi, 1259 bytes

Go to Post Office:w 1 l 1 r 1 l.Pickup a passenger going to Auctioneer School.Go to Auctioneer School:s 1 r 1 l 1 l.Pickup a passenger going to Chop Suey.0 is waiting at Starchild Numerology.Go to Starchild Numerology:s 1 l.Pickup a passenger going to Addition Alley.Go to Chop Suey:e 1 l 2 r 3 r 3 r.[a]Switch to plan "b" if no one is waiting.Pickup a passenger going to Charboil Grill.Go to Charboil Grill:n 1 l 3 l 3 l.Pickup a passenger going to What's The Difference.Go to Go More:e.64 is waiting at Starchild Numerology.Go to Starchild Numerology:e 2 r.Pickup a passenger going to What's The Difference.Go to What's The Difference:e 1 l 2 r 1 l.Pickup a passenger going to Addition Alley.Go to Addition Alley:e 2 r.Pickup a passenger going to Addition Alley.Go to Chop Suey:n 1 r 2 r.Switch to plan "a".[b]Go to Addition Alley:n 1 l 2 l.Pickup a passenger going to Equal's Corner.100 is waiting at Starchild Numerology.Go to Starchild Numerology:n 1 l 1 l 3 l 2 r.Pickup a passenger going to Equal's Corner.Go to Equal's Corner:w 1 l.Switch to plan "c" if no one is waiting."TRUE" is waiting at Writer's Depot.[c]"FALSE" is waiting at Writer's Depot.Go to Writer's Depot:n 1 l 1 r.Pickup a passenger going to Post Office.Go to Post Office:n 1 r 2 r 1 l.

With line breaks, it looks like this:

Go to Post Office:w 1 l 1 r 1 l.
Pickup a passenger going to Auctioneer School.
Go to Auctioneer School:s 1 r 1 l 1 l.
Pickup a passenger going to Chop Suey.
0 is waiting at Starchild Numerology.
Go to Starchild Numerology:s 1 l.
Pickup a passenger going to Addition Alley.
Go to Chop Suey:e 1 l 2 r 3 r 3 r.
[a]
Switch to plan "b" if no one is waiting.
Pickup a passenger going to Charboil Grill.
Go to Charboil Grill:n 1 l 3 l 3 l.
Pickup a passenger going to What's The Difference.
Go to Go More:e.
64 is waiting at Starchild Numerology.
Go to Starchild Numerology:e 2 r.
Pickup a passenger going to What's The Difference.
Go to What's The Difference:e 1 l 2 r 1 l.
Pickup a passenger going to Addition Alley.
Go to Addition Alley:e 2 r.
Pickup a passenger going to Addition Alley.
Go to Chop Suey:n 1 r 2 r.
Switch to plan "a".
[b]
Go to Addition Alley:n 1 l 2 l.
Pickup a passenger going to Equal's Corner.
100 is waiting at Starchild Numerology.
Go to Starchild Numerology:n 1 l 1 l 3 l 2 r.
Pickup a passenger going to Equal's Corner.
Go to Equal's Corner:w 1 l.
Switch to plan "c" if no one is waiting.
TRUE is waiting at Writer's Depot.
[c]
FALSE is waiting at Writer's Depot.
Go to Writer's Depot:n 1 l 1 r.
Pickup a passenger going to Post Office.
Go to Post Office:n 1 r 2 r 1 l.

It accepts upper or lowercase because the Auctioneer School converts it all to uppercase.
Chop Suey breaks it into individual characters.
Charboil Grill converts characters to their ASCII code.
We pickup one character a time, convert it to ASCII, subtract 65, and add it to the running total.
Once there aren't any more characters, compare the total to 100.

Returns TRUE for dollar words and FALSE for everything else.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ In a world of "boring" unreadable code-golf langages <20bytes answers, I welcome thy entry, kind stranger. \$\endgroup\$ Commented Apr 21, 2017 at 11:00
5
\$\begingroup\$

IA-32 machine code, 21 bytes

Hexdump:

33 c0 6a 64 5a 8a 01 41 24 1f 75 05 83 ea 01 d6
c3 2b d0 eb f0

Assembly code:

    xor eax, eax;   initialize eax to 0
    push 100;       initialize edx
    pop edx;            to 100
myloop:
    mov al, [ecx];  load a byte
    inc ecx;        go to next byte
    and al, 31;     convert from letter to number
    jnz cont;       not done? continue

    ;               done:
    sub edx, 1;     check whether edx got to 0; result is in CF
    __emit(0xd6);   aka SALC - set al to CF
    ret
cont:
    sub edx, eax
    jmp myloop

Counts from 100 to 0. If arrived to 0, returns true (0xff); otherwise false (0x00).

\$\endgroup\$
5
\$\begingroup\$

Dyalog APL, 17 15 bytes

100=+/17-⍨⎕AV⍳⍞

Uses the Dyalog Classic character set.

              ⍞  ⍝ string input
          ⎕AV⍳   ⍝ index in the character map
      17-⍨       ⍝ subtract 17 from each ('a' = 18)
    +/           ⍝ sum
100=             ⍝ equal to 100?
\$\endgroup\$
1
  • \$\begingroup\$ By default all submission must be full programs or functions. REPL programs are allowed as long as they're identified as such. However, you still have to request user input. \$\endgroup\$
    – Dennis
    Commented Apr 19, 2017 at 7:04
4
\$\begingroup\$

Python, 38 bytes

lambda s:sum(map(ord,s))==4-96*~len(s)

Try it online!

Same length as ovs's solution. Rather than subtracting 96 from each ord value, this checks if the ord total equals 100+96*len(s). This is expressed one byte shorter as 4-96*~len(s), which equals 4-96*(-len(s)-1).

\$\endgroup\$
1
  • \$\begingroup\$ In Python 3, lambda s:sum(s.encode(),96*~len(s))==4 would also work. \$\endgroup\$
    – Dennis
    Commented Apr 18, 2017 at 23:05
4
\$\begingroup\$

Ruby, 35 30 bytes

->w{196==eval(w.bytes*'-96+')}

Try it online!

\$\endgroup\$
4
\$\begingroup\$

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

\$\endgroup\$
0
4
\$\begingroup\$

///, 564 210 189 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.

\$\endgroup\$
4
\$\begingroup\$

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!

\$\endgroup\$
3
  • \$\begingroup\$ 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 Ä \$\endgroup\$ Commented Apr 19, 2017 at 13:18
  • \$\begingroup\$ @ETHproductions Thanks! m%H was a nice find. x@ was a great idea too! \$\endgroup\$
    – Oliver
    Commented Apr 19, 2017 at 15:39
  • \$\begingroup\$ @ETHproductions Got it down to 10 bytes ;) \$\endgroup\$
    – Oliver
    Commented Apr 19, 2017 at 18:10
4
\$\begingroup\$

tinylisp, 56 bytes

(load library
(q((W)(e 100(s(sum(chars W))(*(strlen W)96

Anonymous function that takes a lowercase word (must be quoted, like (q bernardino)) and returns 1 for dollar words and 0 otherwise. Try it online!

Or, 53 bytes if I can swap truthy and falsey (returns 0 for dollar words and some nonzero integer otherwise):

(load library
(q((W)(-(sum(chars W))100(*(strlen W)96

Try it online!

Ungolfed/explanation

(load library)                 ; Needed for sum, *, strlen, and ungolfed aliases

(lambda (word)                 ; Anonymous function with one argument
  (equal? 100                  ; Is the following equal to 100?
    (sub2                      ; The difference of
      (sum (chars word))       ; the sum of the codepoints of the word
      (* (strlen word) 96))))  ; and 96 times the length of the word
\$\endgroup\$
4
\$\begingroup\$

Factor + math.unicode, 19 bytes

[ 96 v-n Σ 100 = ]

Try it online!

Explanation

       ! "boycott"
96     ! "boycott" 96
v-n    ! { 2 15 25 3 15 20 20 }
Σ      ! 100
100    ! 100 100
=      ! t
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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