-6
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
bcan dividea? 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 – 6 years ago@KevinCruijssen no arrays – Mouvre – 6 years ago
3Welcome 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 – 6 years ago
@MilkyWay90 Cause it is strings, it may be any other strings, so just for example. – Mouvre – 6 years ago
@Mouvre You should probably explicitly state that in your question – MilkyWay90 – 6 years ago
2
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
– Draco18s no longer trusts SE – 6 years ago=(check equality: push 0 or 1), the?(skipninstructions), 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. theJcommand)?3Aren't all unary or higher operators conditional, since their behaviour changes based on the value on which they are acting. – Expired Data – 6 years ago
@ExpiredData I don't know about "all" but certainly a lot. (e.g. does
x++operate "differently" depending on the value ofx? CertainlyMath.sign(x)does, no argument there). – Draco18s no longer trusts SE – 6 years agoWell x++ is effectively the binary + between x and 1, and it's result is conditional on x, I.e imagine a program which took x and returned x+1, it can conceivably be programmed as a set of n bit if statements where n is the number of bits in your representation of x, or a countable infinity of if statements if the size of x is unbounded @draco18s – Expired Data – 6 years ago
@ExpiredData Ah, I suppose you have a point there. – Draco18s no longer trusts SE – 6 years ago
2
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 – 6 years ago