Your challenge, should you choose to accept it, is to create a function or a program that outputs "yes" if a given number is divisible by 13 and outputs "no" if it isn't.

- You're not allowed to use the number 13 anywhere.
- No cop-out synonyms for 13 either (like using 15 - 2).
- Bonus points will be awarded for not using modulus, additional bonus for not using division.

- Your score will be the number of bytes in your code (whitespace not included) multiplied by your bonus.
- If you didn't use modulus, that bonus is 0.90; if you didn't use division, that bonus is 0.90.
- If you didn't use either, that bonus is 0.80.
- The lower your score, the better.

The input will always be an integer greater than 0 and less than 2^32.
Your output should be a simple "yes" or "no".

- Using some roundabout method of generating the number 13 for use is acceptable. Simple arithmetic synonyms like (10 + 3) are not allowed.
- The function or program must literally output "yes" or "no" for if the given number is divisible by 13.
- As always, clever solutions are recommended, but not required.

  • \$\begingroup\$ is 'true' or 'false' a valid output? \$\endgroup\$ – Blazer Feb 23 '12 at 19:09
  • 8
    \$\begingroup\$ JavaScript (27 chars) function f(n){return "yes"}. This will return 'yes' for all the numbers that can be divided by 13 \$\endgroup\$ – ajax333221 Feb 23 '12 at 21:59
  • 5
    \$\begingroup\$ "(whitespace not included)" always have been resulted in one of these two situation : a program encodes its content in whitespace, or a program written in Whitespace (programming language). \$\endgroup\$ – JiminP Feb 23 '12 at 22:29
  • 4
    \$\begingroup\$ Using some roundabout method of generating the number 13 for use is acceptable. How do you determine what is "roundabout enough"? \$\endgroup\$ – Cruncher Apr 17 '14 at 15:57
  • 3
    \$\begingroup\$ @Rusher To be honest, I didn't notice that it was 2 years old, it just recently became active. As for your suggestion, I'd rather not ninja-change as non-OP a question with 2 pages of answers.. \$\endgroup\$ – Cruncher Apr 17 '14 at 18:59

66 Answers 66


k2, 22 char * 0.8 = 17.6

Just as you can sum the digits of a base 10 number to tell if it is divisible by 9, so too can you tell if a number is divisible by 13 if repeatedly summing its digits gives 13. As a function returning a string:


14_vs expands the input into base 14, and then +/ sums up the "digits". Wrapping that up into (...)/ repeats the process until it produces no change, that is, the result is less than 14. then we simply check whether our result is greater than 12 with 12<, and select the string "yes" or "no" ($`no`yes@) based on that result.

  $`no`yes@12<(+/14_vs)/ 39
  f 38
  f' 167 168 169 170 171
  f 0

0 gives a "no" under this algorithm, but that's okay because the input is always greater than 0, according to the question. If we had to fix that, we would want to increment the number before and check for equality to 1, getting the 23 character $`no`yes@1=(+/14_vs)/1+.


Powershell, 43.2



if((1.2307692307 * $a) -band 15) {"no";exit}

Magic number is of course 16/13. Multiplies by this, checks if the last four bits are all zero.


GAP, 45 bytes * 0.8 = 36

Instead of giving one more solution that computes Gcd(26,n), I multiply with the one of the field with 169 elements (which has characteristic 13) and get zero iff n is divisible by 13. If I wanted a truthy result, I could just use IsZero, but to get a yes/no-String I turn that result into an ordinary integer, compute 0 to that power, add one and use that as index to a string list. Normally I could say list[index], but that doesn't work with list literals. However there is another short way:


Befunge, 121 bytes * 0.8 = 96.8

&:!#v_1-:!#v_1-:!#v_1-:!#v_1-:!#v_1-:!#v_1-:!#v_1-:!#v_1-:!#v_1-:!#v_1-:!#v_1-:!#v_1-:!#v_1-       #
yes"<      >      >      >      >      >      >      >      >      >      >      >      >"on",,@,,,"

Uses the wraparound nature of Befunge's code--the top row repeatedly decrements the input number until reaching 0. When it reaches 0, it takes the next v down to the bottom row, where it either hits the one < or one of the twelve >s. The bottom row outputs "yes" if executed from right to left, and "no" from left to right.


R, 79 Bytes


Relies on the interquartile range of a standard normal being a bit higher than 13.


f=function(n) {
    if (any(seq==n)) {
    } else {return("no")}

JavaScript, 113 Bytes

var input = document.querySelector("input").value;if(input/parseInt(atob("MTM=")) != 0) {alert(0);}else{alert(1)}

var input = document.querySelector("input").value;
if(input/parseInt(atob("MTM=")) != 0) {alert(0);}else{alert(1)}


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