# Alphabet Checksum

Given a string of lowercase letters, output the "alphabet checksum" of that string, as a letter.

### Example

Let's say we have the string "helloworld". With a = 0, b = 1, c = 2 ... z = 25, we can replace all of the letters with numbers:

h  e  l  l  o  w  o  r  l  d
7  4  11 11 14 22 14 17 11 3


Now, we can sum these:

7+4+11+11+14+22+14+17+11+3 = 114


If we mod this by 26, we get:

114 % 26 = 10


Now, using the same numbering system as before, get the 10th letter, k. This is our answer.

### Test cases

Input          Output

helloworld     k
abcdef         p
codegolf       h
stackexchange  e
aaaaa          a


This is , so shortest code in bytes wins.

• Sandbox Oct 21, 2022 at 17:54

# Excel (ms365), 59, 58 bytes

-1 Thanks to @TheThonnu

=CHAR(MOD(SUM(CODE(MID(A1,SEQUENCE(LEN(A1)),1))+7),26)+97) • I think you can change the -97 to +7 (as some other people have done in their answers) Oct 23, 2022 at 7:55
• @TheThonnu, you are right, but only the 1st one.
– JvdV
Oct 23, 2022 at 8:03
• Yes, I meant the first one. Oct 23, 2022 at 11:01

# JavaScript (Node.js), 51 bytes

s=>(B=Buffer)([B(s).map(c=>t+=c+7,t=0)|97+t%26])+''


Try it online!

# MATL, 10 bytes

2Y2j97-sQ)


### Explanation

2Y2j97-sQ)
2Y2         % Push predefined literal: string 'abc···xyz'
% STACK: 'abc···xyz'
j        % Take input as a string
% STACK: 'abc···xyz', 'helloworld'
97-     % Push 97 (ASCII code of 'a'), and subtract element-wise
% STACK: 'abc···xyz', [7 4 11 11 14 22 14 17 11 3]
s    % Sum
% STACK: 'abc···xyz', 114
Q)  % Add 1, and use as index (1-based, modular). Implicit display
% STACK: 'k'

• Please can you add an explanation? Oct 21, 2022 at 19:39
• @TheThonnu Done! Oct 21, 2022 at 20:13

# Go, 68 bytes

func(s string)(t int){for _,r:=range s{t+=int(r)-97}
return t%26+97}


Attempt This Online!

# brainfuck, 142 126 bytes

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


Try it online!

Edit: -16 bytes due to common sense. Remembered I didn't have to load 97 into its own cell before adding/subtracting.

My first time golfing in brainfuck! Here's the ungolfed code for your viewing displeasure:

,					GET EACH CHARACTER IN THE INPUT
[
>++++++++[-<------------>]<-	SUBTRACT 97 (8 TIMES 12 PLUS 1) FROM CELL 0
[->>>>+<<<<]			ADD CELL 0 TO CELL 4
, 				INPUT TO CELL 0
]
>>>>					GO TO CELL 4
>+++++[->+++++<]>+<<			LOAD 26 (5 TIMES 5 PLUS 1) INTO CELL 6
[>+>->+<[>]>[<+>-]<<[<]>-]		TAKE CELL 4 MOD CELL 6
>>>					GO TO RESULT IN CELL 7
>++++++++[-<++++++++++++>]<+		ADD 97 (8 TIMES 12 PLUS 1) TO CELL 7
.					DISPLAY

• As stated in some other answers, you can probably save some bytes by replacing the "-97" by "+7" (because 97+7 = 104 and 104%26=0). Oct 24, 2022 at 8:30
• @F.Carette I tried to do that by just changing the third line of the ungolfed code to +++++++, but that started giving me the wrong answer somehow. Oct 25, 2022 at 7:43
• Looks like you suffer overflow, current code fail zzzzzzzzzzzzzzz (assuming another answer is correct)
– l4m2
Jan 15 at 5:27

# R v4.2.0, 63 59

-4 thanks to Dominic van Essen

\(x,l=letters)l[(sum(match(el(strsplit(x,"")),l)-1)%%26)+1]


The input string x is parsed as characters, and match is used to retrieve the index of each character in the letters builtin, minus one to convert from 1-based to 0-based.

• Nice approach. However, generally 'code golf' assumes that you need to include the code to 'receive' the string that you're being given, rather than assuming it's already been stored inside a variable whose name you know (as x here). For R, this typically involves using scan(,'') , or defining a function that accepts the string as a parameter (here this would add 4 bytes like this) Nov 1, 2022 at 9:47
• (and, by the way, match is vectorized, so you can shave-off a few bytes by skipping the lapply altogether like this...) Nov 1, 2022 at 9:55
• @DominicvanEssen again, thanks for the tips! I wasn't aware of the "\" function shorthand -- it seems that's new with R 4.1. Very handy indeed. Nov 1, 2022 at 16:29

# Gaia, 16 15 bytes

⟨c97%⟩¦Σ26%97+c


Try it online!

Pretty standard implementation of what the challenge asks.

I was able to save a byte thanks to the golfing advice given by
Dominic van Essen!

## Explained

⟨c97%⟩¦Σ26%97+c
⟨    ⟩¦           # To each letter in the input {
c97%            #  modulo the character code by 96
#  }
Σ26%      # Get the sum of that list and modulo 26
97+c   # and add 97 to turn it back into an ascii letter

• Why use mod 96 + decrement instead of just mod 97? Nov 1, 2022 at 14:29
• @DominicvanEssen I'm not the best at figuring out modulos just yet. Thanks for the golfing advice! Nov 2, 2022 at 12:23
• -1 byte: ⟨c7+⟩¦Σ26%97+c. Jun 7 at 7:29

# Mathematica, 60 48 bytes

FromLetterNumber[Tr[LetterNumber@#-1]~Mod~26+1]&


View it on Wolfram Cloud!

-12 bytes thanks to JSorngard!

• -12 bytes if we avoid StringLength with some arithmetic tricks Nov 2, 2022 at 13:22

# 05AB1E, 6 bytes

ADIkOè


Input as a list of characters.

Explanation:

A       # Push the lowercase alphabet
D      # Duplicate it
I     # Push the input-list
k    # Get the index of each character in the (top) alphabet
O   # Sum these together
è  # (Modular 0-based) index it into the alphabet
# (after which this character is output as result)


# Factor + math.unicode,  25  24 bytes

[ 7 v+n Σ 26 mod 97 + ]


-1 byte thanks to some black magic from Arnauld!

Try it online!

     ! "helloworld"
7    ! "helloworld" 7
v+n  ! { 111 108 115 115 118 126 118 121 115 107 }
Σ    ! 1154
26   ! 1154 26
mod  ! 10
97   ! 10 97
+    ! 107


# Python 3, 43 bytes

-1 byte from @Arnauld

lambda s:chr(sum(ord(c)+7for c in s)%26+97)


Try it online!

• No need for f=, just put it in the header code (saving you 2 bytes). Oct 21, 2022 at 18:09
• The +7 is really clever! I had the exact same solution, except I used -97 instead. Oct 22, 2022 at 2:22
• @TheThonnu can you explain how 'header code' is valid for not being able to call this function now? How does this work and how is this valid for a code golf? Oct 27, 2022 at 9:16
• @Jeroentetje3 - there's a rule somewhere on codegolf.meta.stackexchange.com where it says that for lambda functions in Python, you can name it in the header. If you look at some other Python answers as well, you'll see this convention. Oct 27, 2022 at 9:26
• @Jeroentetje3 - I found it: codegolf.meta.stackexchange.com/a/1503/114446: functions do not need to be named. Oct 27, 2022 at 9:45

# Jelly, 8 bytes

O+7S‘ịØa


A monadic Link that accepts a list of characters and yields a character.

Try it online! Or see the test-suite.

### How?

O+7S‘ịØa - Link: list of characters, Message
O        - ordinals (Message)
S     - sum
‘    - increment
Øa - "abc...xyz"
ị   - index into (1-based and modular)


# jq, 37 bytes

explode|map(.-97)|[add%26+97]|implode


Try it online!

# Raku, 27 bytes

{chr sum(.ords X-97)%26+97}


Try it online!

# Nibbles, 7 bytes (14 nibbles)

+%+.$-$;'a'26

   .            # map over
$# the input: - # subtract 'a' # the letter 'a' ; # (and save it)$         #   from each letter
#   (which gives its 0-based index)
+             # now sum this list
%         26   # apply modulo-26
+               # and add back the saved letter 'a' # K (ngn/k), 16 14 bytes

c$97+26!+/97!  Try it online! -2 bytes thanks to coltim! Explanation: c$97+26!+/97!  Main function. Takes implicit input
97!  Modulo by 97 to each character in the string
to convert them into the 0..25 system
(In K, every character in a string is also an ASCII charcode)
+/     Sum
26!       Modulo by 26
97+          + 97 to each of them to convert them back to ASCII charcode
c$And convert them back to characters  • You don't need the ' on the -97+ (it will "vectorize" automatically); additionally, -97+ can be swapped out for 97! Nov 4, 2022 at 14:52 # Julia 1.0, 36 26 bytes !s=sum([s...].-'a')%26+'a'  Try it online! -10 MarcMush • -10 bytes by adding and subtracting chars directly !s=sum([s...].-'a')%26+'a' Nov 12, 2022 at 10:25 # Ruby, 33 32 bytes -1 byte thanks to Arnauld ->a{(a.sum{_1.ord+7}%26+97).chr}  Attempt This Online! • @Arnauld Nice! Thanks. Oct 21, 2022 at 18:29 # simply, 76 bytes It is a pretty long one... Creates an anonymous function that outputs the expected result. fn($S){$X=0each$S as$C;$X=&add($X&sub(&ord($C)97))out!ABCL[$_=&mod($X,26)];}


Yes, that's right, I'm assigning the result of &mod into a variable.
Without it, it gives a syntax error, because ... I made mistakes in the compiler...

# Using the code

Simply call the function.

$fn = fn($S){$X=0each$S as$C;$X=&add($X&sub(&ord($C)97))out!ABCL[$_=&mod($X,26)];}

// should output "h"
call $fn("codegolf");  # Ungolfed Somewhat code-y looking: $fn = fn($string) => {$sum = 0;
each $string as$char {
$sum = &add($sum, &sub(&ord($char), 97)); }$index = call &mod($sum, 26); echo !ABCL[$index];
}


Plain English-ish/Pseudo-code looking:

Set $fn to an anonymous function($string).
Begin.
Set $sum to 0. Loop through$string as $char. Begin. Set$sum to the result of calling the function &add(
$sum, Call the function &sub( Call the function &ord($char),
97
)
).
End.

Set $index to the result of calling the function &mod($sum, 26).

Show the value !ABCL[$index]. End.  Both versions do exactly the same. # Japt, 8 bytes ;x!aC gC  Try it Input as an array of characters. Explanation: ;x!aC gC ; # C = "abcdefghijklmnopqrstuvwxyz" x # Compute the following for each character, then sum the results: !aC # Find its index in C gC # Get the character at that index in C (wrapping)  You can also rearrange things like this for a different 8 byte solution which works almost exactly the same way. # Brachylog, 14 bytes ạ+₇ᵐ+%₂₆+₉₇g~ạ  Try it online! ### Explanation ạ String to char codes +₇ᵐ Add 7 to each code (a <-> 97 becomes 104 = 0 (mod 26)) + Sum %₂₆ Mod 26 +₉₇ Add 97 g Wrap into a list ~ạ Char code to string  # Vyxal, 9 bytes øA‹∑₄%›øA  Try it Online! øA‹∑₄%›øA øA Letter to number (1-indexed) ‹ Decrement each value in list ∑ Sum it up ₄%› Modulo by 26 and increment øA Number to letter  • øA‹∑₄%›øA is shorter Oct 21, 2022 at 22:42 • @lyxal oh wow I didn't know decrement vectorises by default Oct 22, 2022 at 10:01 • 6 bytes by porting the 05AB1E answer. – user117404 Mar 25 at 15:57 # Pushy, 7 bytes L7*SvOq  Try it online!  The input is implicitly converted into bytecodes on the stack. L7* Push the length of the input, times 7. S Push the sum of the stack. vO Send this to the 'output stack'. q Index into the ASCII lowercase alphabet (mod 26) and print the result.  Pushing 7 times the length comes from the fact that a has bytecode 97, and $$\ -97 \equiv 7 \ (\text{mod} \, 3) \$$. So it's equivalent to subtracting 97 from each bytecode. # Java (OpenJDK 8), 132 bytes interface T{static void main(String[]a){int i=a.length(),s=0;for(;i-->0;s+=a.charAt(i)+7);System.out.print((char)(97+s%26));}}  Try it online! • Welcome to Code Golf, and nice answer! Oct 23, 2022 at 19:23 ## C# (.Net 6), 64 bytes int i=0,j=0;for(;i<a.Length;)j+=a[i++]-97;return(char)(97+j%26);  Try it here # J, 19 bytes (26|+/)&.(_97+3&u:)  Attempt This Online! (26|+/)&.(_97+3&u:) &. NB. F&.G y applies G⁻¹(F(G x)) to y, rank is decided by G (_97+3&u:) NB. fork converting str to char codes and subtracting 97 from each (26|+/) NB. fork that sums the arg and mods the result by 26 NB. +/ can be used because u: operates on y as a whole NB. The inverse of G in this case would be to add 97 to NB. the result of F and then convert char code to str  # Bits, 130 bits = 16.25 bytes 1110000111000001110001011111110111010100000001100111110101011100011000000110001011001101101110000000110100111001111101010111111100  This was very painful. ### Explanation 11100001 // Get a string input 1100000 // Push 0 to the stack [this will be our running sum] 11100010 // For each character in the input string: 111111101 // Get ord(c) 1101010 // Add [to the running sum] 000000 // Separator so the numbers don't get joined together 1100111 // Push 7 1101010 // Add [to the running sum] 11100011 // ENDFOR 000000 // Separator so the numbers don't get joined together 1100010 // Push 2 1100110 // Push 6 [this gets joined into 26] 1101110 // Mod our running sum by 26 000000 // Separator so the numbers don't get joined together 1101001 // Push 9 1100111 // Push 7 [this gets joined into 97] 1101010 // Add [to the result of the mod] 111111100 // Get chr(x) // [implicit output of the item on the top of the stack]  ### Output # R, 4443 42 bytes letters[sum(utf8ToInt(scan(,""))+7)%%26+1]  Try it online! (or 38 bytes as a function in R ≥ 4.1). # Thon (Symbols)s flag, 10 bytes $åị$Σ26%å  ### Explanation $åị$Σ26%å // (implicit input as a string)$  \$         // For each character in the input string:
åị          //   Get the index in the alphabet
// (implicitly create a list of all of these indexes)
Σ        // Sum the list
26%     // Mod by 26
å   // Get that letter of the alphabet
// (implicit output)

• -1? Please explain? It works fine for all test cases. Oct 21, 2022 at 18:56
• My guess is that the downvote is for the challenge poster immediately posting their own solution.
Oct 23, 2022 at 6:42
• @Adám thanks. I thought that was fine. I won't do that in future, then. Oct 23, 2022 at 6:44
• Well, it is fine, especially when doing so in a lesser known language. It is just my guess that the downvoter expressed their personal opinion.
Oct 23, 2022 at 6:45

# Python, 74 bytes

from string import*
f=lambda s,l=ascii_lowercase:l[sum(map(l.index,s))%26]


Try it online!

# Python + golfing-shortcuts, 47 bytes

lambda S:Sl[s(m(Sl.index,S))%26]
from s import*


(Is this one a competitive answer?)