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;

  • \$\begingroup\$ "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]);? \$\endgroup\$ – Kevin Cruijssen Jul 2 '19 at 15:40
  • 3
    \$\begingroup\$ 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! \$\endgroup\$ – MilkyWay90 Jul 2 '19 at 16:12
  • 2
    \$\begingroup\$ 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)? \$\endgroup\$ – Draco18s no longer trusts SE Jul 2 '19 at 16:19
  • 3
    \$\begingroup\$ Aren't all unary or higher operators conditional, since their behaviour changes based on the value on which they are acting. \$\endgroup\$ – Expired Data Jul 2 '19 at 16:29
  • 2
    \$\begingroup\$ 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 :-) \$\endgroup\$ – ElPedro Jul 2 '19 at 20:25

05AB1E, 1 byte


Try it online!

Outputs 1 if divsible 0 if not

Old version with string must be Yes or No

05AB1E, 13 12 10 bytes


Ö              // 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!

  • \$\begingroup\$ “…Ü“ can be '…Ü for -1 and "no" can be „no for -1. \$\endgroup\$ – Kevin Cruijssen Jul 2 '19 at 16:17
  • \$\begingroup\$ 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. \$\endgroup\$ – Kevin Cruijssen Jul 2 '19 at 16:24
  • \$\begingroup\$ @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. \$\endgroup\$ – Expired Data Jul 2 '19 at 16:26
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – 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.


Try it online!

JavaScript (ES6), 50 bytes

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


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.


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)

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

Runic Enchantments, 6 bytes


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).

Version with string output

Runic Enchantments, 20 bytes


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


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.


Not the answer you're looking for? Browse other questions tagged or ask your own question.