| Bytes | Lang | Time | Link |
|---|---|---|---|
| 060 | AWK | 250317T171134Z | xrs |
| 012 | Pyth | 250313T210400Z | Glory2Uk |
| 034 | jq Rr | 221022T000005Z | pmf |
| 010 | Uiua | 241008T004317Z | noodle p |
| 011 | Uiua | 231019T181114Z | chunes |
| 006 | Thunno 2 | 230720T090334Z | The Thon |
| 028 | Dyalog APL v18 | 230116T024442Z | Andriy M |
| 042 | R | 221101T094033Z | Dominic |
| 091 | brainfuck | 230115T054926Z | l4m2 |
| 029 | Arturo | 230115T025052Z | chunes |
| 073 | C++ gcc | 221117T173916Z | huanglx |
| 026 | Julia 1.0 | 221102T125115Z | amelies |
| 2624 | ><> Fish | 221104T144643Z | mousetai |
| 014 | K ngn/k | 221104T141831Z | oeuf |
| 048 | Mathematica | 221021T230643Z | hakr14 |
| 036 | Knight v2 | 221103T071925Z | Sampersa |
| 015 | Gaia | 221101T134940Z | Cliff |
| 059 | R v4.2.0 | 221024T174803Z | acvill |
| 043 | Haskell | 221101T132303Z | Laikoni |
| nan | Bits | 221026T132215Z | The Thon |
| 019 | J | 221025T155204Z | south |
| 030 | x86‑64 assembly machine code | 221022T162853Z | Kai Burg |
| 016 | Pip | 221024T185548Z | Baby_Boy |
| 054 | PowerShell | 221024T162615Z | TwoScoop |
| 064 | C# .Net 6 | 221024T123436Z | MMM |
| 072 | JavaScript V8 | 221023T200014Z | Knight I |
| 077 | Gema | 221023T203246Z | manatwor |
| 132 | Java OpenJDK 8 | 221023T192205Z | Knight I |
| 126 | brainfuck | 221022T031513Z | GotCubes |
| 058 | Excel ms365 | 221022T091742Z | JvdV |
| 007 | Pushy | 221022T141926Z | FlipTack |
| 009 | Vyxal | 221021T181810Z | math sca |
| 015 | BQN | 221022T093501Z | Dominic |
| 014 | Brachylog | 221022T082436Z | Fatalize |
| 714 | Nibbles | 221022T064443Z | Dominic |
| 020 | Pip | 221022T013528Z | Aiden Ch |
| 027 | Raku | 221022T001926Z | Sean |
| 025 | Retina 0.8.2 | 221022T001214Z | Neil |
| 008 | Charcoal | 221022T000147Z | Neil |
| 047 | Wren | 221021T220603Z | chunes |
| 010 | MATL | 221021T183725Z | Luis Men |
| 065 | Clojure | 221021T212018Z | Bob Jarv |
| 018 | ARM Thumb machine code | 221021T204113Z | EasyasPi |
| 046 | C gcc | 221021T204811Z | Digital |
| nan | Fig | 221021T200426Z | south |
| 008 | Jelly | 221021T202108Z | Jonathan |
| 041 | Zsh | 221021T201317Z | GammaFun |
| 008 | Japt | 221021T201241Z | Kamil Dr |
| nan | 221021T201145Z | bigyihsu | |
| 043 | Python 3 | 221021T180658Z | 97.100.9 |
| 006 | 05AB1E | 221021T194414Z | Kevin Cr |
| 076 | simply | 221021T192238Z | Ismael M |
| 024 | Factor + math.unicode | 221021T182128Z | chunes |
| 032 | Ruby | 221021T180333Z | Jordan |
| 051 | JavaScript Node.js | 221021T182639Z | Arnauld |
| 074 | Python | 221021T175804Z | The Thon |
| 010 | Thon Symbols s flag | 221021T175342Z | The Thon |
AWK, 60 bytes
@load "ordchr";{for(;i++<NF;)s+=ord($i)-97;$0=chr(s%26+97)}1
@load "ordchr"; # character lib
{for(;i++<NF;) # for each char
s+=ord($i)-97; # convert to num from ASCII
$0=chr(s%26+97)}1 # back to ASCII and print
Pyth, 12 bytes
@G%sm+7CdQ26
This uses the same algorithm as in other answers (add 7 to each charcode, sum, mod by 26 and subset the alphabet with the resulting index).
Uiua, 11 bytes
+@a◿26/+-@a
+@a◿26/+-@a
-@a # convert string to code points
/+ # sum
◿26 # modulo 26
+@a # add the letter a
Thunno 2, 6 bytes
Ä⁻S⁺ÄL
Explanation
Ä⁻S⁺ÄL # Implicit input
Ä # 1-based index in alphabet
⁻ # Decrement to make 0-indexed
S # Sum the resulting list
⁺ # Increment for 1-indexing
Ä # 1-based convert to letter
L # Lowercase it
# Implicit output
Dyalog APL v18, 28 bytes*
{a[1+26|+/1-⍨(a←¯1∘⎕C⎕A)⍳⍵]}
Assuming that indices start from one (⎕IO←1).
________________
*: APL can be written in its own legacy charset (defined by ⎕AV) instead of Unicode; therefore an APL program that only uses ASCII characters and APL symbols can be scored as 1 char = 1 byte.
R, 44 43 42 bytes
letters[sum(utf8ToInt(scan(,""))+7)%%26+1]
brainfuck, 91 bytes
++[++[->+>+<<]>>[--<<+>>]<],[[-[->+<]>]>>>>>>>,]+[<<<<<<<<<<<<<<<<<<<<<<<<<<+<[-----.[>]]>]
++[++[->+>+<<]>>[--<<+>>]<] Init memory with 1,2,3,...,127
,[[-[->+<]>]>>>>>>>,] Reading each byte, move right that many steps
+[<<<<<<<<<<<<<<<<<<<<<<<<<<+< Go left 26 and check if empty
[-----.[>]]>] If not empty, give shift, output and halt
C++ (gcc), 76 73 bytes
-3 thanks to @ceilingcat
I think this is as much golf as you can get without using a completely different method. Other people will probably prove me wrong the moment I hit "Post." have in fact proven me wrong.
#import<ios>
int f(char*s){int t=0;for(;*s;t+=*s++-97);putchar(t%26+97);}
Ungolfed
We used #import<ios> so we can putchar().
int f(char* s) {
int t = 0; // Running total
for(;*s != 0;t += *s++ - 97); // Loop through string until we get to null byte, add to running total
putchar(t % 26 + 97); // Add 97 to final result and print
}
><> (Fish), 26 24 bytes
- -2 bytes thanks to @Eminga. I didn't want to change the input mode to stack though so I didn't use all the golfing potential. Also I wanted to exit properly and not just error.
0i:0(?v+7+2d*%!
o+"a"~<;
Explanation:
0
Push 0, the starting value
i:0(?v
Check if the input is negative, if so go down.
+7+2d*%
Add 7+the input to the accumulator, then mod 26
!
Skip the 0 the second time, since the accumulator is already set
~"a"+o;
(Reversed in the program) Print "a" + the accumulator.
K (ngn/k), 16 14 bytes
`c$97+26!+/97!
-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
Mathematica, 60 48 bytes
FromLetterNumber[Tr[LetterNumber@#-1]~Mod~26+1]&
-12 bytes thanks to JSorngard!
Knight (v2), 36 bytes
;=sP;=i@O;Ws;=i+~-97iAs=s]sA+97%i 26
I feel like you can golf better but i tried for awhile and gave up
Gaia, 16 15 bytes
⟨c97%⟩¦Σ26%97+c
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
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.
Haskell, 43 bytes
f s=['a'..]!!mod(sum[fromEnum c-97|c<-s])26
Same-length alternative:
f s=['a'..]!!mod(sum$do c<-s;1<$['b'..c])26
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
J, 19 bytes
(26|+/)&.(_97+3&u:)
(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
x86‑64 assembly machine code, 30 B
input
- unsigned length of string in 64‑bit register
rdi - address of string buffer in 64‑bit register
rsi
code listing
1 alphabet_checksum:
2 0000 6A61 push 'a' ; push(97)
3 0002 58 pop rax ; pop(rax)
4 0003 F7E7 mul edi ; edx○eax ≔ eax × edi
5
6 0005 F7D8 neg eax ; eax ≔ −eax; CF ≔ eax ≠ 0
7 0007 7310 jnc .adjust ; if ¬CF then goto adjust
8 .sum:
9 0009 0FB64C3EFF movzx ecx, byte [rsi+rdi-1] ; ecx ≔ (rsi + rdi − 1)↑
10 000E 01C8 add eax, ecx ; eax ≔ eax + ecx
11 0010 FFCF dec edi ; edi ≔ edi − 1; ZF ≔ edi = 0
12 0012 75F5 jnz .sum ; if ¬ZF then goto sum
13
14 0014 6A1A push 26 ; push(26)
15 0016 5F pop rdi ; pop(rdi)
16 0017 F7F7 div edi ; edx ≔ edx○eax mod edi
17 .adjust:
18 0019 92 xchg eax, edx ; eax ≔ edx
19 001A 83C061 add eax, 'a' ; eax ≔ eax + 97
20 001D C3 ret
output
- alphabet checksum as ASCII character in 64‑bit register
rax
limitations
- length of string must be ≤ 44,278,013, else the
mulspills intoedx, yet the algorithm relies onedxbeing0in the case of a zero-length string
JavaScript (V8), 72 bytes
([...s])=>String.fromCharCode(s.map(c=>t+=c.charCodeAt()+7,t=0)|t%26+97)
Gema, 77 characters
?=@set{s;@add{${s;};@add{@char-int{?};7}}}
\Z=@int-char{@add{@mod{$s;26};97}}
(Yepp. Arithmetic operations are a pain in Gema.)
Sample run:
bash-5.1$ echo -n helloworld | gema '?=@set{s;@add{${s;};@add{@char-int{?};7}}};\Z=@int-char{@add{@mod{$s;26};97}}'
k
Java (OpenJDK 8), 132 bytes
interface T{static void main(String[]a){int i=a[0].length(),s=0;for(;i-->0;s+=a[0].charAt(i)+7);System.out.print((char)(97+s%26));}}
brainfuck, 142 126 bytes
,[>++++++++[-<------------>]<-[->>>>+<<<<],]>>>>>+++++[->+++++<]>+<<[>+>->+<[>]>[<+>-]<<[<]>-]>>>>++++++++[-<++++++++++++>]<+.
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
Excel (ms365), 59, 58 bytes
-1 Thanks to @TheThonnu
=CHAR(MOD(SUM(CODE(MID(A1,SEQUENCE(LEN(A1)),1))+7),26)+97)
Pushy, 7 bytes
L7*SvOq
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.
Vyxal, 9 bytes
øA‹∑₄%›øA
ø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
BQN, 15 bytes
'a'+26|·+´-⟜'a'
'a'+26|·+´-⟜'a'
-⟜'a' # subtract 'a' from each letter of input
+´ # sum
· # (no-op to preserve train syntax)
26| # modulo 26
'a'+ # add 'a'
Brachylog, 14 bytes
ạ+₇ᵐ+%₂₆+₉₇g~ạ
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
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'
Pip, 20 bytes
C(($+(7+A*a))%26+97)
Probably could be shorter, I feel like there are just way too many parentheses.
Retina 0.8.2, 25 bytes
0T1>`l`L
+T`l__L`zlL_`^..
Try it online! Link includes test cases. Explanation:
0T1>`l`L
Uppercase all letters after the first.
+T`l__L`zlL_`^..
While there are at least two letters, repeatedly rotate the first letter backwards and the second letter forwards in the alphabet, however the first letter rotates back from a to z while the second letter drops off when it passes Z, allowing subsequent letters to be processed.
The l and L in the patters expand to the lowercase and uppercase alphabet respectively. The _ in the source pattern is just a placeholder to allow the use of l and L in the destination pattern, while in the destination pattern it indicates that the character is to be deleted.
Charcoal, 8 bytes
§βΣES⌕βι
Try it online! Link is to verbose version of code. Explanation:
S Input string
E Map over characters
ι Current character
⌕ Find index in
β Predefined variable lowercase alphabet
Σ Take the sum
§ Cyclically indexed into
β Predefined variable lowercase alphabet
Implicitly print
MATL, 10 bytes
2Y2j97-sQ)
Try it online! Or verify all test cases.
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'
Clojure, 65 bytes
(defn a[s](char(+(mod(apply + (map #(- % 97)(map int s)))26)97)))
Ungolfed:
(defn alpha-checksum [s]
(char (+ (mod (apply + (map #(- % 97) (map int s))) 26) 97)))
ARM Thumb machine code, 18 bytes
61 20 04 c9 61 3a 10 44 fb d5 1a 38 fd d2 7b 30
70 47
Assembler source:
.syntax unified
.arch armv7-a
.thumb
.globl alpha_checksum
.thumb_func
// Input: r1: null terminated UTF-32LE string
// Output: r0
// Clobbers: r0-r2
alpha_checksum:
// Initial accumulator. Start at 'a' to cancel the checksum
// loop adding '\0' - 'a' when the null terminator is reached.
movs r0, #'a'
.Lloop:
// Load character, increment pointer
ldmia r1!, {r2}
// Subtract 'a' to convert to a number, set flags
// In the case of the null terminator, this will result in
// -'a', which ends the loop condition below.
subs r2, #'a'
// Add to the checksum, without setting the flags
add r0, r2
// Loop if the subs didn't return negative,
// which happens only with the null terminator.
bpl .Lloop
.Lend:
// Calculate (checksum % 26) - 26 using a naive subtraction loop
.Lmodulo:
// Subtract 26
subs r0, #26
// Loop while it was >= 26
bhs .Lmodulo
// Add 26 to correct the modulo, and 'a' to convert to ASCII.
adds r0, #'a' + 26
// Return
bx lr
This can be called from C using a dummy parameter to place ptr in r1.
ptr is expected to be a pointer to a null terminated UTF-32LE string.
char32_t alpha_checksum(int dummy, const char32_t *ptr);
Fig, \$10\log_{256}(96)\approx\$ 8.231 bytes
ica%26S+7C
Using Arnauld's logic. Accepts a list of characters
ica%26S+7C
C # str -> char code, vectorises
+7 # add 7 to each item
S # sum
%26 # sum % 26
ca # lowercase alphabet
i # index intro ca using result
Alternate \$13\log_{256}(96)\approx\$ 10.701 bytes
ica%26SM'lxca
ica%26SM'lxca
ca # lowercase alphabet
x # input
M'l # map find over x where we look for each char in ca, returns index
S # sum
%26 # sum % 26
ica # index into ca using the result
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)
+7 - add seven (vectorises)
S - sum
‘ - increment
Øa - "abc...xyz"
ị - index into (1-based and modular)
Zsh, 41 bytes
a=(+##${(s..)^1}+7)
<<<${(#)$((a%26+97))}
(s..)plit, ^ RC-style expand as +##${1[1]}+7 +##${1[2]}+7 .... Then (#) evaluate the expression as character codes.
Japt, 8 bytes
;x!aC gC
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.
Go, 68 bytes
func(s string)(t int){for _,r:=range s{t+=int(r)-97}
return t%26+97}
05AB1E, 6 bytes
ADIkOè
Input as a list of characters.
Try it online or verify all test cases.
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)
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.
Factor + math.unicode, 25 24 bytes
[ 7 v+n Σ 26 mod 97 + ]
-1 byte thanks to some black magic from Arnauld!
! "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, 74 bytes
from string import*
f=lambda s,l=ascii_lowercase:l[sum(map(l.index,s))%26]
Python + golfing-shortcuts, 47 bytes
lambda S:Sl[s(m(Sl.index,S))%26]
from s import*
(Is this one a competitive answer?)
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)


