| Bytes | Lang | Time | Link |
|---|---|---|---|
| 038 | jq | 230718T123219Z | manatwor |
| 003 | Vyxal 2.4.1 K | 230718T105851Z | lyxal |
| 003 | Thunno 2 B | 230718T102314Z | The Thon |
| 023 | APOL | 220114T191202Z | Ginger |
| 006 | Husk | 220114T121040Z | Natte |
| 033 | Factor + math.unicode | 220114T071456Z | chunes |
| 041 | Java | 210225T041404Z | Unmitiga |
| 033 | PowerShell Core | 210222T213253Z | Julian |
| 007 | Pyth | 200909T103517Z | Mukundan |
| 030 | PowerShell Core | 210223T061725Z | mazzy |
| 049 | Python 3.8 prerelease | 210222T203428Z | Gotoro |
| 005 | Vyxal | 210222T075024Z | Dion |
| 012 | NARS2000 | 210222T150842Z | jimfan |
| 053 | C gcc | 200909T093636Z | Noodle9 |
| 020 | GolfScript | 200916T202640Z | 2014MELO |
| 031 | Zsh | 200916T151204Z | GammaFun |
| 052 | PHP | 200910T143059Z | Kaddath |
| 052 | Python 3 | 200913T010640Z | Steve28 |
| 040 | Wolfram Language Mathematica | 200909T081108Z | ZaMoC |
| 008 | Brachylog | 200912T084855Z | xash |
| 148 | C clang | 200909T194718Z | aidan062 |
| 010 | x8616 machine code | 200911T165952Z | 640KB |
| 162 | Rockstar | 200910T091721Z | Shaggy |
| 076 | Go | 200911T133438Z | wilkben |
| 023 | MAWP | 200910T130743Z | Dion |
| 041 | Clojure | 200911T091055Z | Stuart |
| 065 | TSQL | 200910T115842Z | t-clause |
| 066 | Excel | 200910T115620Z | Engineer |
| 038 | R | 200909T092053Z | Dominic |
| 021 | Aceto | 200910T064237Z | L3viatha |
| 032 | JavaScript | 200909T085744Z | Shaggy |
| 020 | Perl 5 pF | 200909T140504Z | Nahuel F |
| 081 | C# Visual C# Interactive Compiler | 200909T110830Z | bit |
| 032 | Ruby | 200909T103938Z | Razetime |
| 004 | Jelly | 200909T081814Z | ovs |
| 039 | Haskell | 200909T102041Z | rak1507 |
| 062 | Factor | 200909T090624Z | Galen Iv |
| 012 | Pip | 200909T101301Z | Razetime |
| 031 | Befunge98 FBBI | 200909T085717Z | ovs |
| 036 | Rust | 200909T094825Z | madlaina |
| 004 | MathGolf | 200909T094216Z | Kevin Cr |
| 006 | Japt e | 200909T093643Z | Shaggy |
| 008 | Charcoal | 200909T090601Z | Neil |
| 025 | C# .NET Core | 200909T085658Z | LiefdeWe |
| 011 | K oK | 200909T083416Z | Galen Iv |
| 007 | APL Dyalog Extended | 200909T082401Z | Adá |
| 004 | MATL | 200909T081855Z | Luis Men |
| 039 | Python 2 | 200909T080624Z | Dion |
| 005 | 05AB1E | 200909T080646Z | ovs |
jq, 38 characters
length as$a|explode|map(.%$a)|all(.<1)
Sample run:
bash-5.2$ jq -R 'length as$a|explode|map(.%$a)|all(.<1)' <<< 'Hello'
false
bash-5.2$ jq -R 'length as$a|explode|map(.%$a)|all(.<1)' <<< 'lol'
true
Thunno 2 B, 3 bytes
lḊp
Explanation
lḊp # Implicit input
# Convert to charcodes
l # Length of input
Ḋ # Are they divisible
p # Product of the list
# Implicit output
APOL, 23 bytes
!(x(ƒ(i %(↶(∋) l(⋒)))))
Explanation:
!( Not
x( Any list item is true
ƒ( List-builder for
i Input
%( Modulo
↶( ASCII codepoint
∋ Loop item
)
l( Length of
⋒ Loop iterator (what the loop is looping through)
)
)
)
)
)
Husk, 6 bytes
Λo¦L¹c
Explanation
Λo¦L¹c translates = Λo¦L⁰c⁰
Λ ⁰ all of input:
o c charcode
¦ divides
L⁰ length of input
Pyth, 8 7 bytes
-1 byte thanks to @isaag
!%#lQCM
!%#lQCM
! - logical negation of
# - filtering
CM - ascii values of input with
% lQ - func(x): return x % len(input)
Python 3.8 (pre-release), 63 49 bytes
lambda h:print({0}=={*[ord(i)%len(h)for i in h]})
* in the {} constructs a set which I think is more byte-efficient than using set(), which I didn't know.
----
Python 3.8 (pre-release), 42? bytes
lambda h:{0}=={*[ord(i)%len(h)for i in h]}
I can't get TIO to output the True or False. This works with IDLE or Jupyter. Try it online.
NARS2000 (12 characters)
(∧/0=⍴|⎕ucs)
Fork ⍴|⎕ucs finds residue of each ASCII int value when divided by length of string. ∧/0= checks if all residue are zero.
C (gcc), 54 53 bytes
l;r;f(char*s){l=strlen(s);for(r=0;*s;)r|=*s++%l;l=r;}
Returns falsey if the ASCII value of each character is divisible by the length of the input string or truthy otherwise.
Explanation:
l;r;f(char*s){l=strlen(s);for(r=0;*s;)r|=*s++%l;l=r;}
l;r; // Declare 2 int variables
f( // Function f taking
char*s){ // string parameter s
l=strlen(s); // Store length of s in l
for( // Loop
r=0; // initialising r to 0
*s;) // until end of s
r|= // Bitwise or r with
*s // the ASCII value of the next
// character...
++ // Aside: push s pointer forward
%l; // ... mod the string length
l=r; // Return r (r will be 0
// iff every character was
// divisible by the length of the
// input string)
GolfScript, 20 bytes
.,0@{(3$%@+\}3$*;!\;
This outputs 1 if the string is divisible and 0 if it isn't. Let S be the string and L its length.
.,0@ # The stack from bottom up will be: L 0 S
{ }3$* # Execute this block L times
( # Separate first char from the string as a number
3$% # Previous number mod L
@+\ # Add result to the acumulator
; # Discard the ""
! # 1 iff the acumulator is 0
\; # Discard L
Zsh, 31 bytes
for c (${(s::)1})((r||=#c%$#1))
If we accept a "list of characters" as arguments, then we don't have to split the string for 19 bytes:
for c;((r||=#c%$#))
PHP, 56 52 bytes
for(;$c=ord($argn[$i++]);$c%strlen($argn)?die(f):1);
Output is reversed
Execution stops with f if any char is not divisible, or empty string (falsy in PHP) if all are divisible
EDIT: saved 4 bytes thanks to @640KB
Wolfram Language (Mathematica), 40 bytes
{0}==##&@@ToCharacterCode@#~Mod~Tr[1^#]&
thanks to @att for saving some bytes
Brachylog, 8 bytes
ạfᵐ∋ᵛ~l?
ạfᵐ∋ᵛ~l?
ạ characters to integer
fᵐ find all factors
∋ᵛ every list of factors contain …
~l? the length of the input
Alternative version,
⟨ạzl⟩%ᵛ0
⟨fhg⟩ forks! fA & gB ∧ [A, B]h
ạzl zip the code blocks with the length;
[[108, 3], [111, 3], [108, 3]]
%ᵛ0 every list must be 0 after modulo
C (clang), 149 148 bytes
#include<stdio.h>
int main(){char s[100];scanf("%s",s);int j;int k=strlen(s);for(int i=0;i<k;i++){if(s[i]%k>0){printf("0");return 0;}};printf("1");}
x86-16 machine code, 10 bytes
00000000: 880e 0601 acd4 0ae1 fbc3 ..........
Listing:
88 0E 0106 MOV BYTE PTR[CHR_LOOP+2], CL ; move len to second byte of AAM opcode
CHR_LOOP:
AC LODSB ; AL = next char
D4 0A AAM CL ; ZF = (AL % CL == 0)
E1 FB LOOPZ CHR_LOOP ; loop if CX > 0 AND ZF = 1
C3 RET ; return to caller
As a callable function. Input: string in SI, length in CX. Output: ZF = 1 if Truthy, ZF = 0 if Falsey.
Output of DOS test program:
Rockstar, 205 192 175 162 bytes
Well, this was fun. Rockstar has no way of reading the length of a string directly, can't convert characters to codepoints and has no modulo operator. Surprised it worked out this short!
listen to S
cut S
X's0
D's0
while S at X
N's32
while N-127
cast N into C
if C is S at X
let M be N/S
turn down M
let D be+N-S*M
let N be+1
let X be+1
say not D
Try it here (Code will need to be pasted in)
Go, 76 bytes
func f(a string)int{for _,v:=range a{if int(v)%len(a)>0{return 0}}
return 1}
MAWP, 34 33 24 23 bytes
`|_=M0=A0/[M%{0:.}?`]1:
Thanks to @Razetime for saving 9 bytes!
Explanation:
` Remove starting 1 on stack
| Push input on stack as ASCII codes
_=M Set variable M to length of stack (length of input)
0=A Set variable A to 0
0/ Push 0 and cycle stack
[ Start of loop
M% Modulo by M
{0:.} If not 0 then print 0 and terminate
?` If 0 then pop value
] End of loop
1: Print 1
Clojure, 41 chars
(every? #(= 0 (mod (int %) (count x))) x)
Removing spaces after comment 37 chars
(every? #(= 0(mod(int %)(count x)))x)
T-SQL, 65 bytes
Returns 1 for true, 0 for false
SELECT-1/~max(ascii(substring(@,number,1))%len(@))FROM spt_values
Excel, 66 bytes
=SUM(MOD(CODE(MID(A1,ROW(OFFSET(A1,0,0,LEN(A1))),1))/LEN(A1),1))=0
Input is in the cell A1.
ROW(OFFSET(A1,0,0,LEN(A1))) gives us an array of values from 1 to the length of the input.
MID(A1,ROW(~),1) pulls out each character of the input, one at a time.
CODE(MID(~) converts those characters to their decimal ASCII equivalent.
MOD(CODE(~)/LEN(A1),1) returns just the decimal portion of those codes divided by the input length.
SUM(MOD(~))=0 adds up all those decimal portions and returns TRUE if there weren't any (SUM=0 means everything divided nicely) and FALSE if there were.
I thought this would have to be an array formula but it seems to work without that. Color me surprised.
R, 39 38 bytes
Edit: -1byte thanks to the new rule that we can output TRUE for FALSE and FALSE for TRUE
function(s)any(utf8ToInt(s)%%nchar(s))
Or try the original 39-byte version that outputs TRUE for TRUE...
Aceto, 21 bytes
&L
|%o 1
€l|!
rM@dp
Explanation
We read a string and €xplode it, push the stack length and Memorize that.
Then, after setting the exception catch point (@), we always duplicate the top stack element, negate (!) it, and m|rror horizontally if we get a truthy value (string has ended; we popped a 0). Otherwise, we get the ordinal of the character, Load the memorized value and do modulo (%). If this is truthy, we m|rror again.
Finally, we raise an exception (&) to land back in front of the d, for our next character.
If we mirrored, then we eventually land on p, printing the top-most element of the stack. In one of the two cases of mirroring, we will have pushed a 1 before.
I don't see much potential to golf this down further; there's only one space character used, and 3 newlines. Perhaps one or two bytes could be saved by making it a 16x16 in two lines.
C# (Visual C# Interactive Compiler), 81 bytes
(s)=>{var bs = ASCIIEncoding.ASCII.GetBytes(s);return bs.All(b=>b%s.Length==0);};
C# (Visual C# Interactive Compiler), 27 26 bytes
s=>s.All(c=>c%s.Length<1);
Ruby, 43 37 36 32 bytes
->a{a.bytes.all?{|n|n%a.size<1}}
if only map could be used on strings..
-10 bytes from ovs.
-1 byte from Dingus.
Jelly, 4 bytes
LḍOP
Try it online! or Verify all cases!
Commmented: (At least I think it works like this)
P # product of ...
L # does the length
ḍ # ... divide ...
O # the char codes
Haskell, 42 39 bytes
(<1).sum.(map=<<flip(mod.fromEnum).length)
f s=sum[fromEnum c`mod`length s|c<-s]<1
3 fewer bytes thanks to ovs and xnor!
Pip, 12 bytes
!$+(A_Ma)%#a
Explanation
!$+(A_Ma)%#a a → input
(A_Ma) Map a to Unicode/ASCII codepoints
%#a Modulo the list by it's length
$+ Sum up the remainders
! Not(returns 0 for any positive number, 1 for 0)
Befunge-98 (FBBI), 31 bytes
Output is via exit code, 1 for truthy, 0 for falsey cases.
#v~\1+
v>53p
>:#v_1q
^ >' %#@_
Code running with inputs lol and ab:
small numbers represent literal byte values
MathGolf, 4 bytes
$h÷╓
Input as a list of characters.
Explanation:
$ # Get the codepoint of each character in the (implicit) input-list
h # Push the length of this list (without popping the list itself)
÷ # Check for each codepoint if it's divisible by this length
╓ # Pop and push the minimum of the list
# (after which the entire stack joined together is output implicitly as result)
Charcoal, 8 bytes
¬⊙θ﹪℅ιLθ
Try it online! Link is to verbose version of code. Output is a Charcoal boolean, i.e. - for true, nothing for false. Explanation:
θ Input string
⊙ Is there a character where
ι Current character
℅ Ordinal
﹪ Modulo (i.e. is not divisible by)
θ Input string
L Length
¬ Boolean NOT
Implicitly print
⬤θ¬﹪℅ιLθ also works of course.
APL (Dyalog Extended), 7 bytes (SBCS)
Anonymous tacit prefix function
⍱≢|⎕UCS
⍱ are not any of the following true (non-zero)?
≢ the length
| divides (lit. division remainder when dividing)
⎕UCS the code points
MATL, 4 bytes
tn\~
- For divisible strings the output is a vector containing only
1s, which is truthy. - Otherwise the output is a vector containing several
1s and at least one0, which is falsy.
Try it online! Or verify all test cases including truthiness/falsihood test.
How it works
t % Implicit input. Duplicate
n % Number of elements
\ % Modulo
~ % Negate. Implicit display
05AB1E, 5 bytes
ÇsgÖP
Commented
# implicit input "lol"
Ç # push ASCII value [108, 111, 108]
s # swap (with input) [108, 111, 108], "lol"
g # length [108, 111, 108], 3
Ö # is divisible? [1, 1, 1]
P # product 1


