g | x | w | all
Bytes Lang Time Link
111sed 4.2.2240703T085949Zguest430
025Befunge93240703T024227ZAdelie
028Perl 5 pF240701T155716ZXcali
009Uiua240701T141726Znyxbird
021Octave240624T210854Zint 21h
028Trilangle230226T223718ZBbrk24
073Go230623T194917Zbigyihsu
004Thunno 2 B230623T172042ZThe Thon
012minigolf230416T041308Zuser1176
014J220114T224852ZJonah
059Lua230412T114432Zbluswimm
040PARI/GP230412T112125Z138 Aspe
005Stax230328T192342Zemirps
017><> Fish230223T142425Zemirps
041Arturo230223T144637Zchunes
009GolfScript230217T193950Zemirps
067D230119T224410ZThe Zip
067PHP230119T214401Zdneustad
nan230119T162300ZThe Thon
010K ngn/k221008T001650Zoeuf
006Japt220114T210622ZShaggy
nanFig221008T002843ZSeggan
054Excel220114T203323ZEngineer
052Nim221005T193747ZMichael
007Vyxal220302T184302ZLarry Ba
032APOL220308T133615ZGinger
042Swift220303T034745ZBbrk24
008BQN220115T223129ZDominic
083C#220128T112528ZB-Slam
085Kotlin220128T122258Zrandom p
024Wolfram Mathematica220115T082739Ztheorist
055Python 3220114T223103ZLarry Ba
162brainfuck220117T101717ZRachit A
00405AB1E220114T225431ZMakonede
049C clang220117T145812Za stone
003Vyxal 2.4.1 K220115T064508Zlyxal
113Whitespace220117T124716ZKevin Cr
016Factor220114T195433Zchunes
017Ruby nl220117T101621ZKirill L
005MathGolf220117T084918ZKevin Cr
007Pyth220117T081512Zhakr14
031Java220117T030111ZUnmitiga
125Python220116T205957ZBinary19
011K ngn/k220115T173706Zcoltim
031Zsh220116T001542ZGammaFun
050Python 3220115T040510ZDialFros
017Scala220115T202412Zcubic le
010Vyxal Ṁ220114T194319Zmath sca
033R220114T194520ZGiuseppe
004Husk220115T000158ZDominic
046Retina 0.8.2220115T100207ZNeil
033Python 3220115T091352Zsolid.py
008Ly220115T082456Zcnamejj
016APL+WIN220114T202959ZGraham
024Python220115T065252Zpxeger
037JavaScript Node.js220115T002439ZArnauld
025Julia 1.0220114T223148ZMarcMush
036Haskell220114T204519ZDelfad0r
098SNOBOL4 CSNOBOL4220114T195026ZGiuseppe
058JavaScript ES6220114T193705ZRydwolf
009Charcoal220114T195500ZNeil
005Jelly220114T193643Zhyper-ne
005Vyxal220114T195008Zhyper-ne

sed 4.2.2, 111 bytes

s'.*'echo &@ s/{a..z}/a'e       #append a bunch of 's/$/a's where $ is each letter
s/ /\n/g                        #put each on its own line
:                               #loop:
s'a$'a/g'm                      #  add a '/g' to the end of a line
s''aa'g                         #  add a 'a' to each line ending with 'a'
t                               #end
s!(.*)@(.*)!sed 'p\2'<<<'\1'!e  #run the script we just generated (see below)
s/./a/gm                        #turn everything into 'a's
s/(.*)\n\1*//                   #unary: line2 mod line1

Try it online!

the script run on line 7:

sed 'p        #prints the input before editing for use later
s/a/a/g       #does nothing
s/b/aa/g      #swap 'b' for 'aa'
s/c/aaa/g     #swap 'c' for 'aaa'
s/d/aaaa/g    #and so on
s/e/aaaaa/g
s/f/aaaaaa/g
s/g/aaaaaaa/g
s/h/aaaaaaaa/g
s/i/aaaaaaaaa/g
s/j/aaaaaaaaaa/g
s/k/aaaaaaaaaaa/g
s/l/aaaaaaaaaaaa/g
s/m/aaaaaaaaaaaaa/g
s/n/aaaaaaaaaaaaaa/g
s/o/aaaaaaaaaaaaaaa/g
s/p/aaaaaaaaaaaaaaaa/g
s/q/aaaaaaaaaaaaaaaaa/g
s/r/aaaaaaaaaaaaaaaaaa/g
s/s/aaaaaaaaaaaaaaaaaaa/g
s/t/aaaaaaaaaaaaaaaaaaaa/g
s/u/aaaaaaaaaaaaaaaaaaaaa/g
s/v/aaaaaaaaaaaaaaaaaaaaaa/g
s/w/aaaaaaaaaaaaaaaaaaaaaaa/g
s/x/aaaaaaaaaaaaaaaaaaaaaaaa/g
s/y/aaaaaaaaaaaaaaaaaaaaaaaaa/g
s/z/aaaaaaaaaaaaaaaaaaaaaaaaaa/g'<<<'$input'

Befunge-93, 25 bytes

~:1+!#v_"`"-+\1+\
@.!%\$<

Prints 1 if the input word is pure, 0 otherwise.

Try it online!

Perl 5 -pF, 28 bytes

map$i+=31&ord,@F;$_=!($i%@F)

Try it online!

Uiua, 9 bytes

=0◿⧻⟜/+-@`

Try it!

        -@` subtract '`' from each character (converting to numbers)
    ⟜/+    get the sum the array, while keeping the original on top
   ⧻       get the length of the array
  ◿        modulo these two values 
=0         does it equal zero?

Octave, 21 bytes

@(s)~mod(mean(s*1),1)

Try it online!

Checks whether the mean is an integer value: multiplication by 1 is needed to convert the string to the array of char codes.

Outputs 1 (true) if the word is "pure", 0 - otherwise.

Trilangle, 28 bytes

'0|2_~<.+!>S/>i,..<.@2\)/(%S

Prints "0" if the word is pure.

Try it on the online interpreter!

Roughly equivalent to this C code:

#include <stdio.h>

int main() {
    int total = 0, len = 0;
    int c;
    while ((c = getchar()) != EOF) {
        total += c;
        ++len;
    }
    if (total % len == 0) puts("0");
}

The code unfolds to this triangle:

      '
     0 |
    2 _ ~
   < . + !
  > S / > i
 , . . < . @
2 \ ) / ( % S

Control flow starts at the north corner heading southwest, on the red path:

If EOF was read, control flow continues on the blue path; otherwise, control flow continues on the green path.

The green path performs the necessary additions before looping:

On the blue path (after EOF is read), the following instructions are seen:

If the word is pure, the stack contains two -1's, and the interpreter takes the magenta path. If the word is not pure, the stack contains two copies of some non-negative number, and the interpreter takes the yellow path.

On the magenta path, it prints a 0 before exiting:

The yellow path has a rather convoluted no-op before it exits:

Go, 73 bytes

func(R[]rune)bool{s:=0
for _,r:=range R{s+=int(r-'`')}
return s%len(R)<1}

Attempt This Online!

Thunno 2 B, 4 bytes

SslḊ

Attempt This Online!

Explanation

SslḊ  # Implicit input, converted
      # to ordinals by B flag
S     # Sum the ordinals
 sl   # Get the length of the input
   Ḋ  # Is divisible?
      # Implicit output

minigolf, 12 bytes

i+,ni#*i+=;+

Attempt This Online!

Explanation

i+         sum of codepoints of input
,          map in [1..sum(i)]:
  n          push curr. item
  i#*        Multiply by input's length
  i+=        Is that equal to input's sum?
;          end map
+          Sum the list
           (we definitely have a 1 output for an integer quotient,
            and 0 with no integer output

Implicit output

J, 14 bytes

0=#|1#.96|3&u:

Try it online!

-1 thanks to south

Lua, 67 59 bytes

s=...a=0s:gsub('.',load'a=a+(...):byte()-96')print(a%#s==0)

Try it online!

Ungolfed version:

s=...
a=0
s:gsub('.',load'a=a+(...):byte()-96')  -- Add up value of chars, store in a
print(a%#s==0)

PARI/GP, 40 bytes

Try it online!

f(w)=!(sum(i=1,#w,Vecsmall(w)[i]-96)%#w)

Stax, 5 bytes

:VR1=

Run and debug it

This program's length is the same packed and unpacked, so I chose to use the unpacked version.

Explanation

:V    # mean of array (returns a fraction)
  R   # denominator
    = # is equal to
   1  # 1

><> (Fish), 26 24 23 20 19 17 bytes

l&v
v+>l1-?!
>&%n

Try it

Exits with error, which is allowed by default.

This is my first answer in this language, so it can probably be golfed.

Input is assumed to be on the stack. Output is any non-zero number for falsy, 0 for truthy.

Arturo, 41 bytes

$=>[=floor<=average map&=>[to :integer&]]

Try it

GolfScript, 9 bytes

.{+}*\,%!

Try it online!

Explanation

.{+}*\,%! | whole program
 {+}*     | sum the codepoints of the string
.    \,   | push the length
       %  | modulo
        ! | logical negate

D, 67 bytes

import std;int p(string w){return !(w.fold!"a+=b-96"(0)%w.length);}

ungolfed

import std;
int p(string w) {
    return !(w.fold!"a+=b-96"(0)%w.length);
}
// not much more readable, lol

takes a string w, and then performs a fold on it. The fold adds each char, minus 96, to the accumulator. 96 being the ascii value of the backtick character, one behind a (since this challenge specifies that the characters are 1-indexed). this effectively adds up all characters in the string. Then we perform a modulo for a divisibility check, and since we want 0 to be the true case, we invert it. Note how we return int from this function so that it takes up one less byte. ints can be implicitly cast to bool so it's fine.

Try it online!

PHP, 67 bytes

fn($w)=>!(array_sum(array_map('ord',str_split($w)))%96%strlen($w));

Try it online!

Ungolfed

fn($w) => !(array_sum(
    array_map('ord', str_split($w))
  ) % 96 % strlen($w));

Thunno, \$ 7\log_{256}(96)\approx \$ 5.76 bytes

OSz0L%!

Attempt This Online!

Explanation

OSz0L%!  # Implicit input
 S       # the sum of
O        # the ords of the input
     %!  # is divisible by
    L    # the length of
  z0     # the input?
         # Implicit output

K (ngn/k), 11 10 bytes

{(#x)!+/x}

Try it online!

Saves a byte by not using the Not operator (~)

Quick and simple. Return 0 for true and any other value for false.

Explanation:

{(#x)!+/x}    Main function. Takes x as input
      +/x     Sum of all charcodes in x
     !        Modulo
 (#x)         Length of x

Japt, 6 bytes

Takes input as an array of characters. The c can be removed by instead taking input as an array of codepoints.

xc vUl

Try it

xc vUl     :Implicit input of array U
x          :Sum of
 c         :  Codepoints
   v       :Is divisible by
    Ul     :  Length of U

Fig, \$4\log_{256}(96)\approx\$ 3.292 bytes

%LxS

Try it online!

Port of K answer. Prints 0 for truthy and a positive number for falsey.

%LxS
   S # Sum of charcodes
%    # Modulo
 Lx  # Length of input

Excel, 59 54 bytes

Saved 5 bytes thanks to pajonk.

=MOD(SUM(CODE(MID(A1,SEQUENCE(LEN(A1)),1))),LEN(A1))=0

Input is in cell A1. Output is wherever the formula is.

Result


I found an alternative with the same byte count. It works in reverse and exploits the fact that CODE() only pulls the left-most character if it's given a string of greater length. I almost like it more, though, because it has 5 closing parentheses in a row.

=MOD(SUM(CODE(RIGHT(A1,SEQUENCE(LEN(A1))))),LEN(A1))=0

Nim, 52 bytes

import sequtils,sugar
t=>t.foldl(a+b.int,0)%%t.len<1

Try it online!

Vyxal, 7 bytes

C₆%₌∑LḊ

Try it Online!

APOL, 32 bytes

v(0 i);!(%(⊕(ƒ(⁰ ⌕(ⓛ ∋))) l(⁰)))

Explanation:

v(            Set memory cell
  0
  i           to input
);
!(            Not
  %(          Modulo
    ⊕(       Sum
      ƒ(      List-builder for
        ⁰     Memory cell 0
        ⌕(    Find
          ⓛ  All ASCII lowercase characters
          ∋   Loop item
        )
      )
    )
    l(        Length of
      ⁰       Memory cell 0
    )
  )
)

Swift, 42 bytes

{$0.utf8.reduce(0){$0+Int($1)}%$0.count<1}

Try it online!

This uses the same algorithm as the current top answers for Python, Excel, Java, and Scala, and probably others. As for why I use .utf8, see my explanation here. As with that answer, the input type here can be String or Substring, and the output type is Bool.

It still surprises me that Swift has .reduce(0, +) rather than .sum() for collections of numbers.

BQN, 16 12 9 8 bytes

Edit: -3 bytes thanks to ovs, and -1 byte thanks to DLosc

≠|·+´@-⊢

Try it at BQN online REPL

Outputs nonzero (truthy) for non-perfect words, zero (falsy) for perfect words.

C#, 101 83 bytes

bool P(string w){int i=0;foreach(var c in w){i+=(int)c%32;};return i%w.Length==0;};

Try it online

Kotlin, 85 bytes

fun i(s:String):Int{var a=0;for(i in s)a+=i.code-96;return if(a%s.length==0)1 else 0}

Try it online!

Ungolfed version:

fun isPure(s: String) : Int
{
    var acc = 0
    for(i in s) acc+= i.code-96
    return if(acc%s.length==0) 1 else 0
}

1 stands for Truthy and 0 stands for falsy, derived from this post Interpretation of Truthy/Falsey

Wolfram Mathematica, 34 24 bytes

1∣Mean@LetterNumber@#&

-10 bytes from @att

Try it online!

Python 3, 55 bytes

lambda s:(sum(ord(c)-95for c in s)/len(s)).is_integer()

Try it online!

brainfuck, 162 bytes

>+[+[>+<+<]>]+[,[>[>+<<->-]<[>>>+<<<-]>>>>+<<[<+>-]<<+>>]<<]>>>[-]>>[<+>-]<[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]>[-]+++++++>[-]<[>+++++++<-]>>[<.[-]>[-]>[-]]<[-.[-]]

Try It Online!

outputs 0 for truthy and 1 for falsey

This one was a lot of fun. Not necessary golf-optimal but hey, brainfuck solution :)

Explanation

; 96 algorithm from esolangs constants
; initialise tape to (1)/96/0/0/0
>+[+[>+<+<]>]+[
    ; while(getchar())
    ,[>
        [>+<<->-]
        <[>>>+<<<-]>>>>+<<[<+>-]<<+>>
        ; 0/96/(0)/cumulative/length
    ]
    <<
]

; divmod algorithm from esolangs
>>>[-]>>[<+>-]
<[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]

; prepare 0 for output
>[-]+++++++>[-]<[>+++++++<-]

; if(sum%length){print 1}else{print 0}
>>[<.[-]>[-]>[-]]<[-.[-]]

05AB1E, 4 bytes

OIgÖ

Try it online! Takes input as a list of codepoints.

C (clang), 49 bytes

i,l;f(*a){for(i=l=0;*a;i+=*a++)l++;return!(i%l);}

Try it online!

Takes input as a wide string; returns 1 for pure words and 0 for others.

Vyxal 2.4.1 K, 4 3 bytes

ṁ1Ḋ

Try it Online!

Ah yes classic pre-2.6 jank ftw. -1 thanks to Dominic

Explained

ṁ1Ḋ
      # First, the input is converted to a list of corresponding ordinal values by the `K`(eg mode) flag:
ṁ     #   push the arithmetic mean of that list
 1Ḋ   #   is that divisible by 1? (i.e is it a whole number)

Whitespace, 113 bytes

[S S S N
_Push_0][S N
S _Duplicate_0][S N
S _Duplicate_0][N
S S N
_Create_Label_LOOP][S N
S _Duplicate][S N
S _Duplicate][T N
T   S _Read_STDIN_as_char][T    T   T   _Retrieve_input][S N
S _Duplicate][S S S T   S T S N
_Push_10][T S S T   _Subtract][N
T   S S N
_If_0_jump_to_Label_PRINT_RESULT][T S S S _Add][S N
T   _Swap_top_two][S S S T  N
_Push_1][T  S S S _Add][S N
T   _Swap_top_two][N
S N
N
_Jump_to_Label_LOOP][N
S S S N
_Create_Label_PRINT_RESULT][S N
N
_Discard_top][S N
T   _Swap_top_two][T    S T T   _Modulo][N
T   S T N
_If_0_Jump_to_Label_TRUTHY][S S T   T   N
_Push_-1][N
S S T   N
_Create_Label_TRUTHY][S S S T   N
_Push_1][T  S S S _Add][T   N
S T _Print_as_integer]

Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.

Since Whitespace can only read input one character at a time, the input must contain a trailing newline so we'll know when we're done reading characters.
Whitespace also lacks truthy/falsey values, so this program will output 1 for truthy and 0 for falsey (could be 28 bytes less with 0 as truthy and a positive integer as falsey).

Try it online (with raw spaces, tabs and new-lines only).

Explanation in pseudo-code:

Integer length = 0
Integer sum = 0
Start LOOP:
  Integer input = STDIN as character
  If(input == '\n'):
    Jump to PRINT_RESULT
  sum = sum + input
  length = length + 1
  Go to next iteration of LOOP

PRINT_RESULT:
  Integer result = 0
  Integer mod = sum modulo length
  If(mod == 0):
    Skip to TRUTHY
  Else:
    result = -1
  TRUTHY:
  result = result + 1
  Print result as integer to STDOUT

Factor, 37 16 bytes

[ mean fixnum? ]

Try it online!

Is the mean of the input an integer?

Why does this work?

Four reasons.

Ruby -nl, 17 bytes

p$_.sum%$_.size<1

Try it online!

MathGolf, 5 bytes

$Σ\£÷

Input as a list of characters. Could be 1 byte less by taking the input as a list of codepoints.

Try it online.

Explanation:

$     # Map each character in the (implicit) input-list to a codepoint integer
 Σ    # Sum this list
  \   # Swap so the (implicit) input-list is at the top again
   £  # Pop and push its length
    ÷ # Check if the earlier sum is divisible by this length
      # (after which the entire stack is output implicitly as result)

Pyth, 7 bytes

!%sCMQl

Test suite

Explanation:
!%sCMQl  | Full code
!%sCMQlQ | with implicit variables filled
---------+-------------------------------------------------------
   CMQ   | Replace each character in the input with its codepoint
  s      | Sum the resulting list
 %    lQ | Mod the sum with the length of the input
!        | Boolean negate (i.e. 0 -> True, other -> False)

Java, 31 bytes

s->s.chars().sum()%s.length()<1

Try it online!

Python, 125 bytes

Wow I feel like an idiot after reading all these other amazing answers.

j=[ord(k)-96 for k in str(input(""))]
l=len(j)
while len(j)>1:j[0]+=j[1];del j[1]
print("%sy"%("truth"if j[0]%l<1else"fals"))

I think how this works is pretty trivial.

K (ngn/k), 14 11 bytes

-3 bytes from @Dominic van Essen's improvement

{~(#x)!+/x}

Try it online!

Zsh, 31 bytes

a=(+\#\#${(s::)^1})
(((a)%$#1))

Try it online!

In Zsh, ##x in arithmetic mode returns the codepoint of 'x'.

        ${(s::) 1}    # split $1 into characters
   +\#\#${(s::)^1}    # append `+##` to each element
a=(+\#\#${(s::)^1})   # save as $a
(((a)%$#1))           # join $a on spaces, evaluate (+##a +##b ...) % $#1
                      # arithmetically

Python 3, 50 bytes

s=input();print(sum(ord(c)-95for c in s)%len(s)<1)

Try it online!

Scala, 17 bytes

s=>s.sum%s.size<1

Try it online!

Vyxal , 11 10 bytes

-1 thanks to Neil

ƛkanḟ;∑?LḊ

Try it Online!

Explanation

ƛkanḟ;∑?LḊ
ƛ            Start a mapping lambda for input
 ka          Lowercase alphabet
   n         Current letter
    ḟ        Find letter in the alphabet, return index
     ;       Close mapping lambda
      ∑      Sum the list of indices.
       ?L    Get Length of input
         Ḋ   Check if Sum is divisible by the length.

R, 42 39 33 bytes

function(w)!mean(utf8ToInt(w))%%1

Try it online!

-6 bytes thanks to m90.

Husk, 5 4 bytes

Edit: -1 byte thanks to Razetime

¦L¹Σ

Try it online!

Outputs truthy (non-zero) for perfect words, falsy (zero) for non-perfect words.

Retina 0.8.2, 46 bytes

.
$&26$*
+T`1l`_3l`\D.
^
2
O^`.
3
1
^(1+)2\1*$

Try it online! Link includes test cases. Explanation:

.
$&26$*

Append 26 1s to each letter.

+T`1l`_3l`\D.

Cycle the letters through the alphabet, removing a 1 each time. Once the letter reaches a, replace it with a 3. (Note that this numbers the alphabet in reverse but this doesn't affect the divisibility check.)

^
2
O^`.

Insert a 2 and then sort the digits in reverse order, so you have the 3s for each letter, the 2, and then the 1s representing the sum of the positions.

3
1

Change the 3s into 1s.

^(1+)2\1*$

Check that the leading 1s divide the trailing 1s.

Python 3, 33 bytes

lambda s:sum(map(ord,s))%len(s)<1

Try it online!

Ly, 8 bytes

iys&+l%!

Try it online!

i         - read STDIN onto stack as codepoints
 ys       - push length of the stack, save to backup cell
   &+     - sum the codepoints on the stack (1)
     l    - load the number of chars from the backup cell
      %   - module math to push "0" if evenly divisble, ">0" otherwise
       !  - negate modulo result so that 0->1 and other->0

(1) The code includes the length of the original stack in the sum of the codepoints to save the p byte that would be needed to delete it. But it doesn't change the result of the modulo math to get the final result.

When the code exits, the only thing on the stack is the 0|1 result, which is printed as a number automatically.

APL+WIN, 22 16 bytes

Prompts for string

0=(⍴s)|+/⎕av⍳s←⎕

Try it online!Thanks to Dyalog Classic

Python, 24 bytes

lambda s:sum(s)%len(s)<1

Attempt This Online!

Takes input as a byte string. We don't need to subtract 95 from each element, because the sum will end up having 95 * length added on, which has no effect on the result modulo length.

JavaScript (Node.js), 37 bytes

s=>eval(Buffer(s).join`+`)%s.length<1

Try it online!

Julia 1.0, 25 bytes

!x=sum(Int,x)%length(x)<1

Try it online!

Haskell, 36 bytes

f w=sum(fromEnum<$>w)`mod`length w<1

Try it online!

SNOBOL4 (CSNOBOL4), 103 98 bytes

	L =SIZE(W =INPUT)
N	W LEN(1) . X REM . W :F(O)
	S =S + ORD(X)	:(N)
O	OUTPUT =1	EQ(REMDR(S,L))
END

Try it online!

Prints 1 for truthy and nothing for falsey.

JavaScript (ES6), 58 bytes

w=>!([...w].reduce((s,c)=>s+parseInt(c,36)-10,0)%w.length)

Charcoal, 9 bytes

¬﹪ΣEθ℅ιLθ

Try it online! Link is to verbose version of code. Outputs a Charcoal boolean, i.e. - for a perfect word, nothing if not. Explanation:

    θ        Input string
   E         Map over characters
      ι      Current character
     ℅       Ordinal
  Σ          Sum
¬﹪           Is divisible by
        θ    Input string
       L     Length
             Implicitly print

Jelly, 5 bytes

OSḍ@L

Try It Online!

OSḍ@L    Main Link
O        ord (vectorizes)
 S       sum
  ḍ@     is this divisible by
    L    the length of the input?

If outputting inconsistent truthy/falsy values is allowed:

Jelly, 4 bytes

OSọL

Try It Online!

OSọL    Main Link
O       ord (vectorizes)
 S      sum
  ọ     how many times is this divisible by
   L    the length?

This works using an observation made by caird coinheringaahing in chat that you do not need to account for the offset between A = 1 and A = 65 when you take the codepoint, since the codepoint offset will be added len(X) times and not affect the modulo.

Yes, caird also just straight up gave the algorithm, but to be fair, the observation was the only non-trivial part about this solution anyway.

Vyxal, 5 bytes

C∑$LḊ

Try It Online!

Same thing as my Jelly solution.

C∑$LḊ    Full Program
C        ord (vectorizes)
 ∑       sum
  $      swap; bring the string back to the top
   L     length
    Ḋ    is the ord sum divisible by the length?