# Report divisibility with arithmetic integer operations only [closed]

Given two numbers, the first is greater than the second, check whether the first number is divisible by the second without a remainder. If divisible, answer "yes"(or any other string), otherwise "no"(or any other string you like).

Conditions: You cannot use conditional operators, loops, arrays, bitwise operations, functions and methods. You can use variables, all arithmetic integer operations (that is, integer division), even the operation of taking the remainder of a division.

Numbers can range from 1 to 1,000,000. Maximum running time is 1 second.

You can of course write in any language, but here is my non-golfed solution in C++:

int main() {
int a,b; cin >> a >> b;
int c = a%b;
int n = (c+1-(c-1)((2(c-1)+1)%2))/2;
int y = 121, e = 101, s = 115;

cout << (char)(y-11*n) << (char)(e+10*n) << (char)(s-83*n) << endl;
}

• "you can not use conditional operators, cycles, bitwise operations, functions and methods" I assume this includes builtins to check if b can divide a? And how about array/list indexing? Could I use (in pseudo-code): list = ["no","yes"]; int isDivisible = b can_divide_evenly a; print(list[isDivisible]);? – Kevin Cruijssen Jul 2 '19 at 15:40
• Welcome to Code Golf! Especially for a new user, do not post "Do X without Y" questions. Also, why are you restricting the output to "yes" and "no"? Thanks! – MilkyWay90 Jul 2 '19 at 16:12
• So for a language where each byte is an instruction, which part is the "conditional"? The part that coerces the boolean, or the part that consumes the boolean? E.g. for this program which part violates the restriction: the = (check equality: push 0 or 1), the ? (skip n instructions), both (i.e. both commands are individually invalid), or the combination of both in sequence (i.e. invalid only if both are used)? What about commands that act differently based on the value of the top-of-stack (e.g. the J command)? – Draco18s no longer trusts SE Jul 2 '19 at 16:19
• Aren't all unary or higher operators conditional, since their behaviour changes based on the value on which they are acting. – Expired Data Jul 2 '19 at 16:29
• Welcome to the site. We really do recommend the sandbox for new challenges especially for new members. It saves you from getting too many downvotes for a question that could have been improved without downvotes harming your rep :-) – ElPedro Jul 2 '19 at 20:25

# 05AB1E, 1 byte

Ö


Try it online!

Outputs 1 if divsible 0 if not

# 05AB1E, 1312 10 bytes

Ö'…Ü„nor.D


Ö              // Test to see if they are divisible
'…Ü           // The string yes
„no      // the string no
r     // reverse the stack
.D   // push whether they are divisible copies of "yes"
// Implicitly output the result


Try it online!

• “…Ü“ can be '…Ü for -1 and "no" can be „no for -1. – Kevin Cruijssen Jul 2 '19 at 16:17
• Pretty pointless to ban all those things but not builtins.. >.> Anyway, my first comment is also a tip for future challenges. :) '„… are all three builtins for 1, 2, or 3-char string builtins, or 1, 2, or 3 word dictionary strings. More info can be found in this first section here. – Kevin Cruijssen Jul 2 '19 at 16:24
• @KevinCruijssen thanks, I was trying to use that for reference but sometimes it's hard to pick things out! and yeah well this is a terrible challenge anyway, I think it should probably be closed. – Expired Data Jul 2 '19 at 16:26
• Yeah, my tip answer is a bit large these days, because more was added in the process.. And you learn as you go along with it. Even now I sometimes come across builtins which are barely used and I didn't even knew were there.. PS: If you ever have any questions, feel free to ask any of us in the 05AB1E chat. – Kevin Cruijssen Jul 2 '19 at 16:28

# JavaScript (ES6), 17 bytes

Takes input as (a)(b). Returns "Y" for yes or "undefined" (as a string) for no.

a=>b=>"Y"[a%b]+''


Try it online!

# JavaScript (ES6), 50 bytes

Takes input as (a)(b). Returns "yes" or "no", as per the original rules.

a=>b=>(22724-21872*((2*(a%b-1)+1)%2)).toString(36)


Try it online!

# APL (Dyalog Unicode), 17 3 bytesSBCS

Anonymous tacit infix function. Takes lesser and greater numbers as left and right arguments. Prints the string "0" if divisible and "1" if not.

1⌊|


Try it online!

| division remainder when dividing right argument by left argument (gives 0 for divisible or strictly positive integer for non-divisible)

1⌊ the minimum of that and 1 (gives 0 for divisible or 1 for non-divisible)

• Of course, this depends on if = is considered the "conditional" in the challenge specification, or whether the if(...) part is. – Draco18s no longer trusts SE Jul 2 '19 at 16:50
• @Draco18s Good point. Fixed. – Adám Jul 2 '19 at 17:22

# Runic Enchantments, 6 bytes

0ii%p@


Try it online!

Outputs 1 if divisible 0 if not.

Determines 0/1-ness by raising 0 to the power of the remainder, which returns 0 for all x except 0 (due to the indeterminate nature of 00 having been decided to be 1).

# Runic Enchantments, 20 bytes

10ii%p-4´36*6X+d-E@


Try it online!

Utilizes the word dictionary to convert from a 0/1 value to the strings "yes" and "no" by multiplying the result by 436 and adding 47 (ok, it adds 60 and subtracts 13; the byte cost is ironically the same either way: 4X7++ vs. 6X+d- vs. 4´7+).

May be invalid due to using an array? There is certainly no array in the submission code but rather in the the interpreter due to how E is executed when the top of the stack is not a string.

# Befunge-98 (FBBI), 6 bytes

%1\k0.


Arguments should be pushed onto the stack, and requires the current IP delta to be (1,0). Prints 1  if divisible and 0  if not.

Try it online! Link includes I/O boilerplate.