32
\$\begingroup\$

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.

Rules:
- 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.

Scoring:
- 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".

Clarifications:
- 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.

\$\endgroup\$
12
  • \$\begingroup\$ is 'true' or 'false' a valid output? \$\endgroup\$
    – Blazer
    Commented Feb 23, 2012 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
    Commented Feb 23, 2012 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
    Commented Feb 23, 2012 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
    Commented Apr 17, 2014 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
    Commented Apr 17, 2014 at 18:59

65 Answers 65

1 2
3
0
\$\begingroup\$

Powershell, 43.2

param($a)if((1.2307692307*$a)-band15){"no";exit}"yes"

Ungolfed

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

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

\$\endgroup\$
0
\$\begingroup\$

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:

n->\[\](["no","yes"],1+0^Int(n*One(GF(169))))
\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

R, 79 Bytes

f=function(n)ifelse(any(1:n*as.integer(IQR(rnorm(100000,,10)))==n),"yes","no")

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

ungolfed

f=function(n) {
    number=as.integer(IQR(rnorm(10000,,10)))
    seq=1:n*number
    if (any(seq==n)) {
        return("yes") 
    } else {return("no")}
}
\$\endgroup\$
0
\$\begingroup\$

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)}
<input>

\$\endgroup\$
1 2
3

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