Determine if a number is divisible by 13 (without using 13 itself)

31

6

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.

Mr. Llama

Posted 2012-02-23T18:14:30.460

Reputation: 2 387

Question was closed 2016-08-10T06:48:19.397

is 'true' or 'false' a valid output? – Blazer – 2012-02-23T19:09:21.800

8JavaScript (27 chars) function f(n){return "yes"}. This will return 'yes' for all the numbers that can be divided by 13 – ajax333221 – 2012-02-23T21:59:36.687

5

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

– JiminP – 2012-02-23T22:29:48.617

@JiminP, there's already a challenge for that. Exploit "free whitespace"

– boothby – 2012-02-24T05:58:00.347

How does the bonus work if you have no mod, no div? then just 0.8? – Teun Pronk – 2014-04-15T13:00:31.817

Do "the 6th Fibonacci number", or "the 6th prime number" count as cop-outs here? – Tal – 2014-04-16T07:32:36.120

4Using some roundabout method of generating the number 13 for use is acceptable. How do you determine what is "roundabout enough"? – Cruncher – 2014-04-17T15:57:52.373

@Cruncher This post is two years old. Rather than ask a ghost for clarification, why don't you just submit an edit to make it clearer? – Rainbolt – 2014-04-17T18:57:16.480

3@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.. – Cruncher – 2014-04-17T18:59:30.167

@Cruncher - I'd totally forgotten about it too but I kept getting notifications about it. I had no idea it would suddenly become popular again. – Mr. Llama – 2014-04-17T20:51:03.600

@ajax333221 and JavaScript (26 chars) function f(n){return "no"}. This will return 'no' for all the numbers that can't be divided by 13 – user3459110 – 2014-04-18T09:54:27.460

var o=" "; if((input%(o.length))==0){return "yes"} else {return "no"} – user3459110 – 2014-04-18T09:57:36.577

Answers

24

Java (score 60.8 59.2)

void t(int n){System.out.print(Math.cos(.483321946706122*n)>.9?"yes":"no");}

Score: (76 - 2 whitespace) chars * 0.8 = 59.2

Peter Taylor

Posted 2012-02-23T18:14:30.460

Reputation: 41 901

Ingenious. I like it! – mellamokb – 2012-02-24T15:40:50.723

println -> print? – Geobits – 2014-04-18T01:52:58.950

@Geobits, true. – Peter Taylor – 2014-04-18T09:03:33.957

19

ASM - 16 bit x86 on WinXP command shell

executable - 55 bytes * 0.8 = 44

source - 288 characters * 0.8 = 230.4

The number 13 doesn't even appear in the assembled .com file.

Assemble using A86.

    mov si,82h
    xor ax,ax
    xor cx,cx
a:  imul cx,10
    add cx,ax
    lodsb
    sub al,48
    jnc a
    inc cx
h:  mov dl,a and 255
c:  loop g
    sub dl,a and 255
    jz e
    mov dl,4
e:  add dl,k and 255
    mov dh,1
    mov ah,9
    int 21h
    ret
g:  inc dl
    cmp dl,c and 255
    jne c
    jmp h
k:  db 'yes$no$'

Skizz

Posted 2012-02-23T18:14:30.460

Reputation: 2 225

I understand that this solution is clever, but seeing as this is code-golf, shouldn't we be upvoting shortest solutions rather than cleverest solutions? – mellamokb – 2012-02-28T21:04:09.320

21@mellamokb: From what I've read on meta, some people think voting is a mark of appreciation for a clever / unusual solution. If we only voted on the shortest answer, there wouldn't be any point in having voting. I guess the 'tick' goes to the shortest code as a mark of ultimate kudos. Then again, a simple solution in golfscript will always be smaller than a really clever solution in C - so who deserves the votes? In the end, the votes aren't that important, it's about having fun. – Skizz – 2012-02-29T00:15:52.143

1rule: The input will always be an integer greater than 0 and less than 2^32. You can't use 16bit – Fabricio – 2014-05-09T12:23:31.250

@Fabricio: All 16bit numbers are less than 2^32. :-) – Skizz – 2014-05-09T14:44:25.003

lol.. you're right somehow. But you can't handle 2^32-1 =p – Fabricio – 2014-05-09T22:47:27.203

17

Python 3.x: 54 * 0.8 = 43.2

It may be a cop-out to have a string of length 13, but here it goes:

print('no' if any((' ' * int(input())).split('             ')) else 'yes')

It works by building a string of n spaces (the choice of delimiter is arbitrary, but I chose space for obvious reasons), and splitting away 13-space substrings until you're left with a string containing n%13 spaces.

dan04

Posted 2012-02-23T18:14:30.460

Reputation: 6 319

4+1. I like the split by 13 character whitespace. Moving it to Python 2 and using a technique from my answer takes it down to score of 35.2: print 'yneos'[any((' ' * input()).split(' '))::2] – Steven Rumbalski – 2012-02-24T01:33:03.990

I was about to say: you could replace ' ' with ' '*6+' ' to save 5 chars - but then I found that spaces did not count at all... – kratenko – 2014-05-09T15:50:36.390

15

GolfScript, 32 chars

~){.14base{+}*.@<}do('no''yes'if

I wanted to try something different from everyone else, so my solution calculates the base 14 digital root of the number, by repeatedly converting the number to base 14 and summing the digits until the result no longer gets any smaller. This is essentially the same as calculating the remainder modulo 13, except that the result will be in the range 1 to 13 instead of 0 to 12.

Since checking whether the digital root equals 13 would be difficult without using the number 13 itself (or some lame workaround like 12+1), what I actually do is I increment the input number by one before the loop and decrement the result afterwards. That way, the result for numbers divisible by 13 will in fact be zero, which is much easier to check for.

Here's a commented version of the program:

~              # evaluate the input, turning it from a string to a number
)              # increment by one
{              # start of do-loop 
    .          # make a copy of the previous number, so we can tell when we're done
    14 base    # convert the number to base 14
    { + } *    # sum the digits
    . @ <      # check if the new number is less than the previous number...
} do           # ...and repeat the loop if so
(              # decrement the result by one
'no' 'yes' if  # output 'no' if the result is non-zero, 'yes' if it's zero

This program will actually handle any non-negative integer inputs, since GolfScript uses bignum arithmetic. Of course, extremely large inputs may consume excessive time and/or memory.

The code does not use either modulos or division directly, although it does use GolfScipt's base conversion operator, which almost certainly does some division and remainder-taking internally. I'll leave it for GigaWatt to decide whether this qualifies me for the bonus or not.

Ilmari Karonen

Posted 2012-02-23T18:14:30.460

Reputation: 19 513

If only everyone would comment their golfscript code so well. Kudos – skibrianski – 2014-04-16T00:49:40.617

13

C, 68 * 0.8 = 54.4

After 24 answers, no one came up with this obvious algorithm yet:

f(x){puts("no\0yes"+3*((x*330382100LL>>32)-(~-x*330382100LL>>32)));}

ugoren

Posted 2012-02-23T18:14:30.460

Reputation: 16 527

I was waiting for someone to do an integer reciprocal multiply. Not only is it an elegant solution to the challenge, but it's a useful technique in it's own right as a performance optimization. – Sir_Lagsalot – 2012-02-27T17:46:11.967

Could you explain why this works? – Vedaad Shakib – 2015-07-16T11:45:52.997

@user2767189, it's a technique called "reciprocal multiply" - basically a way to implement division by X using multiplication by (2^K / X). In this case X is 13, and 330382100*13 is almost exactly 2^32. – ugoren – 2015-07-16T14:40:13.760

Is this still valid even though it's very non-standard? – oldrinb – 2012-09-13T04:28:02.007

1@oldrinb, I see no requirement for standard compliance in the question. In general, strict standard compliance is awfully annoying in code golf. – ugoren – 2012-09-13T14:20:32.053

11

JavaScript (27.9)

Current version (31 characters * 0.90 bonus = 27.9).

alert(prompt()*2%26?'no':'yes')

Demo: http://jsfiddle.net/9GQ9m/2/

Edit 1: Forgo second bonus by using modulus to lower score considerably and avoid for loop. Also eliminate ~~ and save two chars (thanks @copy).


Older version (48 characters * 0.80 bonus = 38.4)

for(n=~~prompt()*2;n-=26>0;);alert(n?'no':'yes')​

mellamokb

Posted 2012-02-23T18:14:30.460

Reputation: 5 544

Multiply everything by two and use 26 instead... didn't see that coming. – Mr. Llama – 2012-02-23T22:25:47.900

You can omit the ~~ assuming valid input; otherwise prompt()<<1 will work too. – copy – 2012-02-23T22:27:02.803

Although I will admit it technically doesn't reach the limit of 2^32 anymore using this method.. – mellamokb – 2012-02-24T05:45:15.773

1In fact it does work beyond 2^32 since you dropped any bitwise operators now. – copy – 2012-02-24T17:56:34.070

Might not be the highest score, but the most readable and clear – Eran Medan – 2012-02-27T17:26:17.383

3This is still using an arithmetic quickie to determine divisibility by 13, and there was a rule saying no arithmetic cop outs... – WallyWest – 2014-04-17T12:22:18.687

@WallyWest: We all had fun at the time. Is it really necessary to downvote an answer that is over two years old? – mellamokb – 2014-04-18T03:36:16.773

@Mellamokb Sorry, got a little overzealous... Reverted – WallyWest – 2014-04-18T05:13:47.193

7

BrainFuck

Score: 200 * 0.8 = 160

>++++++[>++++++++<-]>>,[<[-<+>>-<]<[->+<]>>>[->++++++++++<]>[-<+>]<<[->+<],]++++
+++++++++>[>+<-<-[>>>]>>[[-<<+>>]>>>]<<<<]>[<<<[-<++>]<++++++++++++++.+.>]<<[[-<
++++++<++++++++>>]<-----.<---.>------.>]

Reads froms stdin. Probably not the most clever solution, but getting anything that works in BF is nice. It's quite compact though.

copy

Posted 2012-02-23T18:14:30.460

Reputation: 6 466

Any explanation on how it works? It seems like by default BrainFuck would get the full 0.8 bonus because it simply doesn't have division or modulus. – Mr. Llama – 2012-02-23T21:19:05.847

@GigaWatt it calculates the modulus. – copy – 2012-02-23T21:27:56.650

1Aye, but what I meant was that it doesn't use the modulus operator (because it doesn't have one). Therefore it'll always get the bonus for not using it. Also, nice bio pic. – Mr. Llama – 2012-02-23T21:37:35.917

@GigaWatt I didn't disagree with you, just answered your question. – copy – 2012-02-23T21:59:27.237

7

Scala (38 * 0.9 = 34.2)

Similar to 0xD(hex) or 015(oct).

ASCII value of CR is 13.

def t(n:Int)=if(n%'\r'==0)"yes"else"no"

Prince John Wesley

Posted 2012-02-23T18:14:30.460

Reputation: 669

1I wondered how long it'd be before I saw someone exploit ascii values. – Mr. Llama – 2012-02-24T19:25:32.910

1Can you add the score to your post please? Should be 38 * 0.9 = 34.2. – mellamokb – 2012-02-28T21:06:37.167

5

Haskell, 28 * 0.8 = 22.4

f x|gcd 26x>2="yes"|1<3="no"

hammar

Posted 2012-02-23T18:14:30.460

Reputation: 4 011

5

Python:

f=lambda n:1==pow(8,n,79)

E.g.

[i for i in range(100) if f(i)]

gives

[0, 13, 26, 39, 52, 65, 78, 91]

blah

Posted 2012-02-23T18:14:30.460

Reputation: 51

1now this one I like. however there needs to be a yes/no according to the challenge criteria, and you should post your score (25*.08 = 20) – Blazer – 2012-02-24T23:10:01.987

f=lambda n:pow(8,n,79)-1 and "no" or "yes" fixes it, 43*0.8=34.4 – ugoren – 2012-02-27T15:54:08.793

4

ECMAScript 6, 25 × 0.9 = 22.5

Yeah, it's a boring way of getting 13.

n => n % '             '.length ? 'no' : 'yes'

Ry-

Posted 2012-02-23T18:14:30.460

Reputation: 5 283

i was trying to figure out how your score was so low, then i realized the genius in using whitespace for your number... lol – mellamokb – 2012-02-24T15:32:49.300

1+1 for abusing the rules. If I stated them, it would be "not counting REMOVABLE whitespace". So is anyone going to give us a 0 byte solution? – ugoren – 2012-02-27T15:59:42.220

@ugoren Wish granted

– TuxCrafting – 2016-08-06T18:16:50.303

4

C, 54.4 == 68 * .8   80 * .8

char*f(c){char*s=" yes\0\rno";while(c&&*s++);return c>0?f(c-*s):++s;}

ceased to turn counterclockwis

Posted 2012-02-23T18:14:30.460

Reputation: 5 200

Nice use of \r - I thought it's only good for Windows support. But why c>0 when c would do? – ugoren – 2012-02-26T22:20:04.200

@ugoren: it wouldn't do, think about it. – ceased to turn counterclockwis – 2012-02-26T23:24:34.510

You're right, I got confused somehow. I was thinking about numbers above 2^31, where >0 is no good. But instead of noticing that your function doesn't support them, I thought == is good. – ugoren – 2012-02-27T07:37:53.863

3

Perl - 44 × 0.8 = 35.2

#!perl -p
map$_+=4*chop,($_)x10;$_=chop^$_*3?'no':yes

Counting the shebang as one byte.

I'm a bit late to the game, but I thought I'd share the algorithm, as no other posts to this point have used it.

This works under the observation that if n is divisible by 13, then ⌊n/10⌋+n%10*4 is also divisible by 13. The values 13, 26 and 39 cycle onto themselves. All other multiples of 13 will eventually reach one of these values in no more than log10 n iterations.


In Other Bases

Admittedly, chop is a bit of a cop-out. With a base 10 representation, it's equivalent to divmod. But the algorithm works prefectly well in other bases, for example base 4, or 8.

Python style pseudo-code of the above algorithm (base 10):

def div13(n):
    while n > 40:
        q, r = n // 10, n % 10
        n = q + 4*r
    return n in [13, 26, 39]

In base 2:

def div13(n):
    while n > 40:
        q, r = n >> 1, n & 1
        n = q + 7*r
    return n in [13, 26, 39]

In base 4:

def div13(n):
    while n > 40:
        q, r = n >> 2, n & 3
        n = q + 10*r
    return n in [13, 26, 39]

In base 8:

def div13(n):
    while n > 40:
        q, r = n >> 3, n & 7
        n = q + 5*r
    return n in [13, 26, 39]

etc. Any base smaller than 13 works equally well.

primo

Posted 2012-02-23T18:14:30.460

Reputation: 30 891

3

APL ((21 - 1) × 0.8 = 16)

'yes' 'no'[1=⎕∨⌊⍟9*6]

⎕IO should be set to 0 for this to work properly in Dyalog APL. To generate 13, we take the floor () of the natural logarithm () of 9 to the power of 6 (9*6). After that, we find the GCD () of our input () and 13, and we then test if that equals 1. This is used to index ([...]) the vector of answers.

If anyone wants to be pedantic about the mention of bytes in the scoring specification, the score for the UTF-8 encoded version of this is (29 - 1) × 0.8 = 22.4. :)

Dillon Cower

Posted 2012-02-23T18:14:30.460

Reputation: 2 192

1I so want to be pedantic about bytes. – Steven Rumbalski – 2012-02-26T03:38:01.220

1Ohhhhhhhh snap you di-int. – Dillon Cower – 2012-02-26T04:19:29.610

3

C, 88

Fibonacci trick.

f(n){return n<2?n:f(n-1)+f(n-2);}main(x){printf("%s",x%f(7)?"No":"Yes",scanf("%d",&x));}

l0n3sh4rk

Posted 2012-02-23T18:14:30.460

Reputation: 1 387

2You're using 13 via f(7)... That's kinda bending the rules a bit... – WallyWest – 2014-04-18T02:21:36.767

2

JavaScript (108 less 0 for whitespace) => 108, x 0.8 (no modulus, no division) = 86.4

b=b=>{a=z,a=a+"";return+a.slice(0,-1)+4*+a.slice(-1)};z=prompt();for(i=99;i--;)z=b();alert(b()-z?"no":"yes")

This method uses the following algorithm: 1. Take the last digit, multiply it by four, add it to the rest of the truncated number. 2. Repeat step 1 for 99 iterations... 3. Test it one more time using step 1, if the resulting number is itself, you've found a multiple of 13.

Previous update, removed var, and reversed logic at the alert to remove more chars by using subtraction-false conditional.

Technically, the end result is that you'll eventually reach a two digit number like 13, 26, or 39 which when run through step 1 again will give 13, 26, or 39 respectively. So testing for iteration 100 being the same will confirm the divisibility.

WallyWest

Posted 2012-02-23T18:14:30.460

Reputation: 6 949

2

Javascript: 59*0.8 = 47.2 (?)

fiddle:

function r(n){
  for(c=0;n>c;n-=12,c++);
  return n==c?'yes':'no';
}

Including mellamokb's improvement (57*0.8 = 45.6):

function r(n){
  for(c=0;n>c;n-=12,c++);
  return n-c?'no':'yes'
}

Supr

Posted 2012-02-23T18:14:30.460

Reputation: 121

1You can save two chars by changing return to return n-c?'no':'yes' and omitting the second semicolon. – mellamokb – 2012-02-24T15:39:46.857

@mellamokb Good catch. Could probably improve further by writing it in Ruby, or something that allows more compact function definitions. – Supr – 2012-02-24T16:27:52.373

There is also an accepted standard on CG to use prompt for input and alert for output, which makes the program interactive and saves a few chars. – mellamokb – 2012-02-24T22:01:41.403

2

Perl: (51-4 spaces)*0.9 = 42.3

say+<>%(scalar reverse int 40*atan2 1,1)?'no':'yes'

40*atan2(1,1) -> 31.41592 (PI*10)

Toto

Posted 2012-02-23T18:14:30.460

Reputation: 909

2

Perl (19.8)

21 bytes * .9

say2*<>%26?"no":"yes"

note: My first Perl program ever. Weakly typed is good for golf i guess.

Steven Rumbalski

Posted 2012-02-23T18:14:30.460

Reputation: 1 353

I've found that a good way to measure your knowledge of a language is to try and golf in it. Usually requires knowing edge cases. Also, your score is actually 23 * 0.90 (whitespace doesn't count). – Mr. Llama – 2012-02-24T19:10:54.440

Thought I had accounted for the whitespace. Fixed now. Thanks for pointing that out. – Steven Rumbalski – 2012-02-24T19:18:11.683

Wow. No love for Perl. Can't say I like it either. – Steven Rumbalski – 2012-02-28T17:55:32.847

2

in C (K&R): 47 * 0.8 = 37.6

f(i){for(;i>0;i-=__LINE__);puts(i?"no":"yes");}

EDIT1: okay removed all dependencies on external functions, the above will work as long as you put this line on the 13th line of the file! :) If __LINE__ is okay to be replaced by say 0xd then can save a further 5 characters (score: 33.6)

Nim

Posted 2012-02-23T18:14:30.460

Reputation: 269

7If this needs to be on 13th line, you need to add 12 newlines to your code, and therefore, to your score: it becomes 59 * 0.8 = 47.2 – Vereos – 2014-04-18T09:45:40.950

2

Ruby (50 48 * 0.9 = 43.2)

Smart way to use eval

eval x="p gets.to_i*3%x.length == 0? 'yes':'no'"

Hauleth

Posted 2012-02-23T18:14:30.460

Reputation: 1 472

2

J - 22.4 = 28 * 0.8

Based on mxmul's clever cyclic method.

f=:<:{('yes',~12 3$'no ')$~]

Examples:

   f 13
yes
   f 23
no
   f 13*513
yes
   f 123456789
no

Eelvex

Posted 2012-02-23T18:14:30.460

Reputation: 5 204

2

Cheddar, 20 bytes (noncompeting)

Score is 20 * 0.9 = 18

n->n*2%26?'no':'yes'

A straightforward answer.

Deimos

Posted 2012-02-23T18:14:30.460

Reputation: 41

2

Common Lisp (71 bytes * 0.8) = 56.8

Simple recursion, really.

(defun w(x)(if(> x 14)(w(- x 13))(if(> 14 x 12)(print'yes)(print'no))))

Ungolfed:

(defun w (x)
  (if (> x 14)
      (w (- x 13))
      (if (> 14 x 12)
          (print 'yes)
          (print 'no))))

MatthewRock

Posted 2012-02-23T18:14:30.460

Reputation: 913

1

Delphi XE3 114*0.8 = 91.2

function d(n:integer):string;var i:int8;begin d:='No';while n>0do for I:=0to 5do n:=n-2;if n=0then exit('Yes')end;

Ungolfed

function d(n:integer):string;
var
  i:int8;
begin
  d:='No';
  while n>0do
    for I:=0to 5do
      n:=n-2;
  if n=0then exit('Yes')
end;

Does not use division, does not use mod, does not contain the number 13

Teun Pronk

Posted 2012-02-23T18:14:30.460

Reputation: 2 599

1

Python 2: 33 * 0.9 = 29.7 points

print['yes','no'][input()*2%26>0]

n*2%26 is equivalent to n%13. input()*2%26 will give a number from 0 to 12, and only numbers with 0 should print yes. To solve that, we add >0. 0>0 == False but all(map(lambda n:n>0,range(1, 13))) == True. False gets implicitly converted to 0, and True to 1, and the string in the appropriate index is printed.

undergroundmonorail

Posted 2012-02-23T18:14:30.460

Reputation: 5 897

1

Python2.7, 57B

x=input()
while x>50:x=x//10+x%10*4
print x==x//10+x%10*4

No *2%26 bullshit trickery here. I think it would be more interesting if all non-zero multiples of 13 were forbidden.

Alternative (per wikipedia) algorithm in slightly more interesting code in 77B:

print not(sum([int(s)*[1,-3,-4,-1,3,4][i%6]for i,s in enumerate(`x`[::-1])]))

alexander-brett

Posted 2012-02-23T18:14:30.460

Reputation: 1 485

1

C# 98 chars (score 98*.80 = 76.8)

Shorter version:

int l="ThisIsLongNo?".Length;while(i>0)i-=l;if(i==0)Console.Write("yes");else Console.Write("no");

Easy to read version:

int length = "ThisIsLongNo?".Length;
while (input > 0)
    input -= length;
if (input == 0)
    Console.Write("yes");
else
    Console.Write("no");

s3l1n

Posted 2012-02-23T18:14:30.460

Reputation: 11

This takes a ridiculously long time for input 4294967287. – primo – 2014-04-19T16:04:37.433

Use inline if ?: to save a few chars. – Peter van der Heijden – 2014-04-20T12:12:01.610

1

BASH, 57.6 (72*0.8) 58.4

The x file:

set - `factor $1` 17
shift
while(($1<12))
do
    shift
done
(($1>16)) && echo no || echo yes

The size:

$ cat x | tr -d ' \t\n' | wc -c
72

The run:

$ for i in 1 12 13 14 142 143 144 4294967295; do echo $i - $(bash x $i) ; done
1 - no
12 - no
13 - yes
14 - no
142 - no
143 - yes
144 - no
4294967295 - no

user19214

Posted 2012-02-23T18:14:30.460

Reputation:

Nice idea, if you use backticks instead of $( ... ) you have one char less. – Peter van der Heijden – 2014-04-20T12:15:21.620

@PetervanderHeijden: Thanks! – None – 2014-04-20T14:28:52.717

1

PHP ~84 characters. $n=26;// e.g. function m($n){$x=ord(4)/4;while($n>=$x){$n-=$x;}return $n|0;}echo m($n)?'no':'yes';

I actually prefer this method for getting 13 though (below in function form): function a(){ return (int)((int)true.floor(pi())); }

latinospirit

Posted 2012-02-23T18:14:30.460

Reputation: 11

1

Javascript, ES6, 74.4

Program 106*.8 = 84.8:

alert((f=n=>(n=n.toString(14).split("").reduce((r,x)=>+("0x"+x)+r,0))<14?n>12?"yes":"no":f(n))(+prompt()))

Function 93*.8 = 74.4:

f=n=>(n=n.toString(14).split("").reduce((r,x)=>+("0x"+x)+r,0))<14?alert(n>12?"yes":"no"):f(n)

The number in base 14 is divisible by 13 if and only if sum of its digits is divisible by 13.
Repeat summing digits until number will be 1 digit in base 14.
The answer is "yes" when this number is 13 or 0.
We can ignore 0 as it can be in result only when initial number is 0 (which is out of range by the rules), so it have to be greater than 12.

No explicit divisions and modulus, no any whitespaces, also no 13 in any form.

Qwertiy

Posted 2012-02-23T18:14:30.460

Reputation: 2 697

1

D 56 chars .80 bonus = 44.8

bool d(double i){
    return modf(i*0,0769230769,i)<1e-3;
}

this might have been a cop-out with using 1/13 and a double can store any 32 bit number exactly

edit: this works by multiplying with 1/13 and checking the fractional part if it's different from 0 (allowing for rounding errors) or in other words it check the fractional part of i/13

ratchet freak

Posted 2012-02-23T18:14:30.460

Reputation: 1 334

doesn't modf count as using modulus? – Blazer – 2012-02-23T19:05:40.883

@Blazer not really it takes the fractional part of the first argument and returns it while storing the integral part in the second arg – ratchet freak – 2012-02-23T19:16:23.783

Just a note: the result (yes/no) has to actually be output. Also, I'm somewhat curious as how this solution works. An explanation would be much appreciated! – Mr. Llama – 2012-02-23T19:28:47.483

1

Python 2.7

(20 - 1 whitespace) * 0.9 (no division) = 17.1

print input()%015==0

yes/no instead of true/false: 31 * 0.9 (no division) = 27.9

print'yneos'[input()%015!=0::2]

takes advantage of python's int to convert other bases from strings into base 10 integers. you can see in both versions they use a different (yet same character length) base

edit: 1 char save in yes/no version

edit2: another 2 chars shaved!

edit3: thanks again to comments! even more characters shaved off by using python's builtin octal representations (015 == 13...) instead of int's base translation

Blazer

Posted 2012-02-23T18:14:30.460

Reputation: 1 902

3I see a cop-out with the different bases – ratchet freak – 2012-02-23T19:25:41.557

14 in base 9? I should have seen that coming. – Mr. Llama – 2012-02-23T19:29:25.907

1print['no','yes'][input()%int('d',14)==0 – Steven Rumbalski – 2012-02-23T19:32:14.940

as far as I saw, a cop-out was defined as being something like 14-1 or 26/2. I just took creative liberty to represent 13 – Blazer – 2012-02-23T19:32:28.167

@StevenRumbalski thanks for the 1 char save :P – Blazer – 2012-02-23T19:33:53.737

print'yneos'[input()%int('d',14)==0 – Steven Rumbalski – 2012-02-23T19:38:11.000

I do think this fails the rule "No cop-out synonyms for 13 either (like using 15 - 2)". – Steven Rumbalski – 2012-02-23T19:43:24.520

Forgot a closing bracket 2 comments ago: print'yneos'[input()%int('d',14)==0] – Steven Rumbalski – 2012-02-23T19:44:25.923

@StevenRumbalski you also forgot that it can't be ==0 otherwise it will say 'yes' for numbers not divisible by 13 and 'no' for numbers that are, and ::2 for the step. but I fixed it nonetheless :P – Blazer – 2012-02-23T19:46:34.563

@Blazer. Sheesh, I'm full of errors. At least I got it right in my answer. – Steven Rumbalski – 2012-02-23T19:51:26.880

we'll let @GigaWatt decide whether the base cop-out counts as a violation of the rules or not – Blazer – 2012-02-23T19:54:38.170

@Blazer: If int('14',9) is acceptable, you may as well shorten it to 015. – Steven Rumbalski – 2012-02-23T20:15:39.377

@StevenRumbalski how does that work exactly? edit: nvm I see now that it's octal conversion – Blazer – 2012-02-23T20:26:51.640

I would consider base conversions as bending the rules considerably, but because I wasn't specific enough to begin with, I'll have to let it slide. I'd prefer to see something a bit more clever than a round-about creation of 13, but as it stands, your entry is still valid. – Mr. Llama – 2012-02-23T20:44:50.320

1

Python - score 27.9

(31 characters * 0.90) -- forgoes some bonus for shorter code.

print'yneos'[2*input()%26>0::2]

older version: (47 characters * 0.80) -- complete rip-off of mellamokb's Javascript answer, but in Python.

n=2*input()
while n>0:n-=26
print'yneos'[n<0::2]

older version: (60 characters * 0.80)

n=input()
while n>12:
 for _ in'x'*12+'!':n-=1
print'yneos'[n>0::2]

older version: (105 characters * 0.80)

n=abs(input())
while n>12:n=abs(sum(int(x)*y for x,y in zip(`n`[::-1],n*(1,-3,-4,-1,3,4))))
print'yneos'[n>0::2]

Steven Rumbalski

Posted 2012-02-23T18:14:30.460

Reputation: 1 353

Hmm, this is a nifty method. That 1,-3,-4 pattern is similar to what I saw on wikipedia. Still cool to see it in code. – Mr. Llama – 2012-02-23T19:35:17.520

@GigaWatt: That's where I got it. The other pattern (1,10,9,12,3,4) would save 1 character but would not resolve to a value less than 13. – Steven Rumbalski – 2012-02-23T19:47:05.233

1

Perl, 95 * 0.8 = 76

$_=<>;
while($_>0){
$q=7*chop;
$d=3*($m=chop$q);
chop$d;
$_-=$d+$m}
if($_){print"no"}
else{print"yes"}

The line breaks were added for clarity. I could have probably made this answer a lot shorter, but I feel that this answer represents a unique way of approaching the problem.

PhiNotPi

Posted 2012-02-23T18:14:30.460

Reputation: 26 739

1

In Q:

d:{$[0=x mod "I"$((string 6h$"q")[1 2]);`yes;`no]}
50*.9=45

sinedcm

Posted 2012-02-23T18:14:30.460

Reputation: 410

Welcome to CodeGolf.SE. You should put your code in a codeblock, and which point you can use backticks where you mean backticks as they no longer have formatting meaning. I've done the first part for you, please check it and fix any errata I've introduced. – dmckee --- ex-moderator kitten – 2012-03-02T19:02:29.867

1

Right Linear Grammar - ∞ points

S->ε
S->1A
S->0S
S->9I
S->3C
S->5E
S->4D
S->2B
S->7G
S->6F
S->8H
F->3K
K->0F
A->2L
K->1G
A->5B
A->0J
B->7A
J->5A
G->6K
G->8S
H->9K
F->5S
K->2H
I->6E
I->5D
J->4S
D->8I
B->6S
K->9B
F->6A
G->9A
K->6L
K->4J
C->1E
L->8K
E->5C
B->4K
C->0D
J->2K
D->2C
A->9F
J->7C
C->6J
C->8L
E->0K
L->0C
B->9C
E->2S
L->6I
I->0L
J->0I
B->2I
I->3B
H->1C
I->7F
C->4H
F->1I
G->4I
I->0G
C->3G
F->8C
D->0A
E->3A
I->9H
A->7D
C->2F
H->7I
A->8E
F->9D
E->8F
A->6C
D->6G
G->0E
D->5F
E->9G
H->2D
D->7H
H->3E
I->2A
K->3I
C->9S
C->7K
E->4B
D->1B
L->1D
J->9E
I->1S
E->1L
J->8D
D->9J
L->2E
J->3L
B->5L
B->8B
L->7J
L->9L
G->1F
A->4A
K->5K
B->3J
H->6H
E->7E
J->1J
D->4E
G->2G
J->6B
D->3D
E->6D
H->4F
I->4C
C->5I
F->0H
H->5G
K->7S
G->3H
L->5H
H->8J
A->3S
H->0B
B->1H
G->7L
K->8A
F->2J
F->7B
L->4G
F->4L
A->1K
B->0G
G->5J
L->3F

Then depending on how you choose to 'run' it, it will output 'yes' or 'no'.

Not a serious entry, just some fun ;)

EDIT: Perhaps I should explain a bit.

A grammar is a set of rules (productions) which define a language. A language can be thought of as all of the possible strings formed by an alphabet, that conform to the rules of it's grammar.

Here the alphabet is the set of all decimal digits. The grammar's rules are that all strings must form decimal integers that are divisible by 13.

We can use the grammar above to test whether a string belongs to our language.

The rules of the grammar contain terminal symbols (which are elements in the language) as well as non-terminal symbols which are replaced recursively.

It's easier to explain what's going on with an example:

Lets say for example that the string we are testing is 71955.

There is always a start symbol (which is non-terminal), in the case of the grammar above this is 'S'. At this point we have not read any characters from our string:

current pattern                    symbol read
S                                  ε

Now, we read the first symbol in our string which is '7', then we look for a rule in the grammar which has any of the non-terminals in our current pattern in the left hand side of the '->' and that has our symbol in the right hand side of the '->'. Luckily there is one (S->7G), so we replace the non-terminal symbols in our current pattern with the right hand side of the new rule:

current pattern                    symbol read
7G                                 7

Now we have the non-terminal 'G' in our pattern, and the next symbol to be read is '1', So we look for a rule in our grammar that begins with 'G->1". We find there is one (G->1F), so we replace the non terminal with the RHS of our new rule:

current pattern                    symbol read
71F                                1

Keep repeating this process:

Next rule: F->9D

current pattern                    symbol read
719D                               9

Next rule: D->5F

current pattern                    symbol read
7195F                              5

Next rule: F->5S

current pattern                    symbol read
71955S                             5

At this point we have no more symbols in our string, but we have another non-terminal symbol in there. We see from the first rule in the grammar that we can replace 'S' with the empty string (ε): S->ε

Doing so gives us the current patter: 71955ε which is the equivalent to 71955.

We have read all of the symbols in our string, and the pattern contains no non-terminal symbols. Which means that the string belongs to the language and therefore 71955 is in fact divisible by 13.

I.e. the goal is to have pattern = string. If you are left with any non-terminal symbols, after reading all of the symbols in your string, the string doesnt belong to the language. Likewise, if you still have more symbols in your string to read, but there are no rules in the grammar allowing you to go forward, then the string does not belong to the language.

Griffin

Posted 2012-02-23T18:14:30.460

Reputation: 4 349

I'm... not even sure what I'm looking at here. – Mr. Llama – 2012-03-07T16:11:54.610

@GigaWatt http://en.wikipedia.org/wiki/Linear_grammar :)

– Griffin – 2012-03-07T16:49:05.773

1

49 characters in Burlesque: 0\/r@{1\/.-<-12\/.-<-}{L[1.>}w!L[{"no" "yes"}\/!! (assuming the number to check is already on the stack. see here in action.)

Does not use division, does not use modulo. It actually does not use any arithmetic at all... just list manipulation.

mroman

Posted 2012-02-23T18:14:30.460

Reputation: 1 382

start="48">

  • The whitespace between "no" and "yes" is optional. If input comes from stdin and output is expected on stdout prepend ps and append sh leading to 52 characters.
  • < – mroman – 2012-09-12T12:27:23.623

    1

    Mathematica 26*.9 ==23.4

    If[2 n~Mod~26 == 0, "yes", "no"]
    

    DavidC

    Posted 2012-02-23T18:14:30.460

    Reputation: 24 524

    1

    Befunge, 27 non-whitespace bytes * 0.9 = 24.3

    "_v#%\*4"#&<@,,<"no
      >"sey",      ^
    

    Multiplies the input by 4, then checks whether the result is divisible by 52. The 4 and the 52 both come from the 4 literal in the code, which is used for its ASCII value of 52 when read from left to right, then as the number 4 when read from right to left after the < reverses direction.

    histocrat

    Posted 2012-02-23T18:14:30.460

    Reputation: 20 600

    0

    perl, 228.8 (286 chars)

    This solution is long, but it's fun. It contains no cheapo, oddball representation of 13 whatsoever. It doesn't use division or modulus. It works on any integer of any length and runs in - O(log²n) time.

    In all its glory:

    @x=(1,10,9,12,3,4);sub a{$a=shift;$b=0;$c=0;for(0..length($a)-1){$c=0 if$c==6;$b+=$x[$c++]*substr$a,length($a)-$_-1,1}$b}sub b{my$c;$d=shift;do{$c=$d;$d=a$c}while($d!=$c);$x[1]=-3;$e=a$c;$x[1]=10;abs$e}sub c{@d=split//,sprintf"%02d",b$_[0];$d[0]*3==$d[1]}$\=$/;print c(abs<>)?"yes":"no"
    

    Oh wait, was this not an obfuscation contest? Oops =)

    Anyway, here's how it works: First, we note that the ones digit is the same modulo 13 as the millions digit, and the tens digit is the same modulo 13 as the ten millions, etc. This yields the sequence (1,10,9,12,3,4). So, we sum (sequence[digit_number % 6])*digit_value. That gives us a smaller number that is the same modulo 13 as our input. We keep doing this until we fail to get a smaller number. Any number that fails to get smaller must be in the range 0-99. So now we take that number and feed it in to the same algorithm after changing the value for the tens digit from 10 to -3 (which is the same modulo 13). This yields a number in the range -27 to 9. If a number is a multiple of -13, it is a multiple of 13 as well, so we return the absolute value, yielding a number in the range 0-27. The multiples of 13 in the 0..27 range are 0, 13, and 26. 13 and 26 have the property that the tens digit * 3 == the ones digit. If 0 is represented as 00, it has this property as well. No other number in the range 0..27 has this property. Thus, we've determined if the input number is a multiple of 13 or not.

    skibrianski

    Posted 2012-02-23T18:14:30.460

    Reputation: 1 197

    0

    JavaScript: 74*0.8 = 59.2

    function a(b){alert(eval(String.fromCharCode(98,37,49,51))==0?'Yes':'No')}
    

    Try it out here

    Hari

    Posted 2012-02-23T18:14:30.460

    Reputation: 101

    0

    PHP, Score: 64 - 20% = 51.2

    $a=$argv[0];while($b-$i<$a){$b+=14;$i++;}echo($b-$i==$a?yes:no);
    

    14 is added to $b in every cycle, and then it check if $b-$i (where $i is the n° of cycles) is greater of equal the input number. If it is equal, it is a multiple of 13, otherwise it's not.

    Vereos

    Posted 2012-02-23T18:14:30.460

    Reputation: 4 079

    0

    Python- 38 chars

    I hope this doesn't count as a cop-out, but here it goes:

    print["no","yes"][input()%ord("\x0D")==0]
    

    Explanation:

                              ord("\x0D")       ---i.e. 13
                      input()%ord("\x0D")==0    ---the divisibility check
         ["no","yes"][input()%ord("\x0D")==0]   ---the bool we get is used as an index
    print["no","yes"][input()%ord("\x0D")==0]   ---and we print the result
    

    Dan the Man

    Posted 2012-02-23T18:14:30.460

    Reputation: 141

    0

    Julia, 30*0.9=27

    f(x) = x%endof("            ")==0?"yes":"no"
    

    gggg

    Posted 2012-02-23T18:14:30.460

    Reputation: 1 715

    SE's markdown interpreter strips consecutive spaces. You can get around it by putting your code inside a code block, which also makes it a nice monospace font. – undergroundmonorail – 2014-04-17T18:06:47.450

    0

    PowerShell: 65.6

    Characters: 82
    Multiplier: 0.8 (No modulus or division.)
    Total: 65.6

    Golfed Code

    for($y=read-host;$x-lt$y;$x+='StackExchange'.length){}if($x-eq$y){"yes"}else{"no"}
    

    Un-Golfed & Commented

    # Set up a for loop to add 13 (derived from the length of a string) to an initially null variable ($x) until it meets or exceeds a user-input value ($y).
    for($y=read-host;$x-lt$y;$x+='StackExchange'.length){}
    
    # After for loop exits, check final value of $x against $y.
    # If values match, $y is divisible by 13.
    if($x-eq$y){"yes"}else{"no"}
    

    If you're going to use a string length to get to 13, you may as well make the string interesting.

    (May take a long time for very large values of $y.)

    Iszi

    Posted 2012-02-23T18:14:30.460

    Reputation: 2 369

    0

    Pure Bash 40=50*0.8

    File x:

    j=$1*2
    while ((j>0))
    do
    ((j-=26))
    done && echo no || echo yes
    

    Use as, e.g., bash x 13 or bash x 14. Character count:

    $ tr -d '[:space:]' < x | wc -c
    50
    

    Older was:

    File x:

    for ((j=$1*2;j>0;j-=26))
    do
    :
    done
    ((j)) && echo no || echo yes
    

    Use as, e.g., bash x 13 or bash x 14. Character count:

    $ tr -d '[:space:]' < x | wc -c
    52
    

    gniourf_gniourf

    Posted 2012-02-23T18:14:30.460

    Reputation: 141

    0

    C#, 74 * 0.8 = 59.2

    void f(int n)
    {
        while (n >= 14)
            n = (n >> 1) + 7 * (n & 1);
    
        Console.Write(n <= 12 ? "no" : "yes");
    }
    

    Explanation

    Write n as n = 2 a + b, i.e. a = n / 2 = (n >> 1) and b = n % 2 = (n & 1)

    n          = 0    (mod 13)
    2 a + b    = 0    (mod 13)
    14 a + 7 b = 0    (mod 13)
    a + 7 b    = 0    (mod 13)
    

    So n is divisible by 13 if (and only if) a + 7 b is. Replace n by a + 7 b. Keep doing this until n is smaller than 14. n is now 13 if the starting value was divisble by 13 else n is some positive number smaller than 13.

    Peter van der Heijden

    Posted 2012-02-23T18:14:30.460

    Reputation: 101

    0

    ~-~! - 38 * 0.9 (no modulus) = 34.2

    '=~~~~,~~~+~:''=|*/','==*[|yes|]|no||:
    

    ~-~! only supports integer division - thus, */',' (x/13*13)is equivalent to *-*;' (x-x%13). This checks whether x/13*13 == x and returns the appropriate string (yeah, it's a function, decimal console input is a huge pain)

    cjfaure

    Posted 2012-02-23T18:14:30.460

    Reputation: 4 213

    0

    Javascript 30*.9=27

    n % '\r'.charCodeAt() ? 'no' : 'yes'
    

    Second approach 32*.9=28.8 (in case of the first one be invalid)

    This code will only work in the 13th day of each month

    n % new Date().getDay() ? 'no' : 'yes'
    

    Fabricio

    Posted 2012-02-23T18:14:30.460

    Reputation: 1 605

    1No cop-out synonyms for 13 either (like using 15 - 2). I believe '\r'.charCodeAt() is a synonym for 13. – user12205 – 2014-05-09T12:31:29.037

    @ace: Let's wait for what others will say. It is as synonym as ' '.length. – Fabricio – 2014-05-09T12:34:27.193

    0

    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:

    $`no`yes@12<(+/14_vs)/
    

    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
    "yes"
      f:$`no`yes@12<(+/14_vs)/
      f 38
    "no"
      f' 167 168 169 170 171
    ("no"
     "no"
     "yes"
     "no"
     "no")
      f 0
    "no"
    

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

    algorithmshark

    Posted 2012-02-23T18:14:30.460

    Reputation: 8 144

    0

    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.

    tomkandy

    Posted 2012-02-23T18:14:30.460

    Reputation: 167

    0

    Ruby 34x0.8 = 27.2

    p gets.to_i.gcd(0xD)==0?"yes":"no"
    

    Hauleth

    Posted 2012-02-23T18:14:30.460

    Reputation: 1 472

    0

    Ocaml

    let p n =
       if ((n>0) &&(n mod (40 mod 27)) = 0) then "yes" else "no"
    

    13 = x+13 mod x.

    Joseph Elcid

    Posted 2012-02-23T18:14:30.460

    Reputation: 111

    Why *0.8? You're blatantly using mod. – Peter Taylor – 2012-02-25T08:23:08.503

    I didn't get it right, my bad – Joseph Elcid – 2012-02-25T08:29:12.100

    Still not quite right: you get a multiplier of 0.9 for using mod but not div. – Peter Taylor – 2012-02-27T09:01:14.697

    0

    JavaScript, Score 73 68*0.8=58.4 54.4

    for(i=prompt();(i=(i&15)+3*(i>>4))>16;);alert(((i+3)&15)?"no":"yes")
    

    celtschk

    Posted 2012-02-23T18:14:30.460

    Reputation: 4 650

    0

    99 * 0.9 = 89,1 (Used division but no mod)

    var = float.Parse(Console.ReadLine())* 2 / 26;
    if (s == (int)s) Console.Write("Yes");
    else Console.Write("No");
    

    This is in C#. Probably not a very good language to golf in. Feel free to improve it in different languages (or in c#) aslong as the method is the same.

    Heysunk

    Posted 2012-02-23T18:14:30.460

    Reputation: 1

    I think you meant var s at the beginning. Also, try to get rid of useless whitespace (ex: *2/26 instead of * 2 / 26) – Cristian Lupascu – 2012-04-28T09:58:15.863

    the last two lines can be rewritten as Console.Write(s==(int)s?"Yes":"No") – Cristian Lupascu – 2012-04-28T09:59:15.190

    0

    PYTHON 2.6

    Now, this is not the shortest code, but the idea should be very easy to comprehend. Does not work with n = 0 but that can be fixed with if not n or s[-2:] == '.5' or '.' not in s.

    def foo(n):
        s = str(n/26.0)
        return 'yes' if s[-2:] == '.5' or '.' not in s else 'no'
    

    Leonid

    Posted 2012-02-23T18:14:30.460

    Reputation: 101

    0

    C Language

    include <stdio.h>
    
    void main()
    {
    int number = 45;
    int i=0;
    
    while(number >=12)
    {
    for(i=0;i<=12;i++)
        number -=1;
    }
    
    if (number==0)
      printf("Divisible");
    else
      printf("Not Divisible");
    }
    

    Sim

    Posted 2012-02-23T18:14:30.460

    Reputation: 101

    6Hi Sim. Welcome to code golf! The idea behind Code-Golf challenges is to write as short of code as possible that solves the problem. This is done by using shorter variable names like n instead of number, or by cleverly combining loops or code sequences together. Also, the spec is defined to be 100% objective and ambiguous. You'll notice, for example, that the spec defines the output as yes or no. Please conform to the spec with your code and identify your score in the header to your post. Thanks, and welcome to the community! – mellamokb – 2012-02-28T20:56:43.527

    0

    QBasic - 164 CHARS

    i = 9
    s = 0
    WHILE s < i
            s=s+NOT-14
            IF s=i THEN
                    ? "YES"
            ELSEIF s > i THEN
                    ? "NO"
            END IF
    WEND
    

    Set i to the number you want to test. Will Print Y if divisible by 13, otherwise, will print no. Updated to not use simple addition for to generate 13. Actual Non-Whitespace Characters is 66. No Division. No Modulus.

    SCORE 53.49

    Kibbee

    Posted 2012-02-23T18:14:30.460

    Reputation: 919

    Have you tested this for numbers larger than 13? It would appear that it would print out YES/NO many times.. I think you want your output to occur after the WEND. Also, you should be able to golf the output more using something like ? MID$("NO YES", (s=i)*3+1,3) – mellamokb – 2012-02-28T21:00:08.327

    works fine for numbers larger than 13. Will only print yes or no when it reaches the number, or if it finds that it goes past the number. After this, the loop exits. – Kibbee – 2012-02-28T21:11:50.690

    Ah. I missed ELSEIF s > i. Good call. – mellamokb – 2012-02-29T01:33:12.160

    0

    Python, 108 x 0.8 = 86.4

    def F(n):s=oct(n);return F(abs(sum(int(s[-1-i])*[1,-5,-1,5][i&3]for i in range(len(s)))))if n>7 else'yneos'[n>0::2]
    

    Not going to win, but does an interesting trick by iterating over the octal digits of the number and reducing them modulo 13 (e.g. the "hundreds" digit is multiplied by -1 since 8^2==12==-1 mod 13).

    Keith Randall

    Posted 2012-02-23T18:14:30.460

    Reputation: 19 865

    0

    Q, 30 * 0.9 = 27

    {$[0=x mod "i"$"\r";`yes;`no]}
    

    tmartin

    Posted 2012-02-23T18:14:30.460

    Reputation: 3 917

    0

    Perl, score: 25.6 24.8

    OK, my program abuses perl's regex engine. It's a little bit obfuscated to look funnier.

    say+(q x x x <>)=~m ?^(\?:             )+$??"yes":"no"
    

    A shorter and "more readable" version would look like this:

    say+(" "x<>)=~/^(             )+$/?"yes":"no"
    

    I'm not quite sure how to count this. I ignore whitespace, so it goes down to these 32 31 countable characters:

    say+(""x<>)=~/^()+$/?"yes":"no"
    

    which of course doesn't work, but the rules are like that. Because there's no modulus or division, I use factor 0.8. Please correct me if I'm wrong here. :)

    memowe

    Posted 2012-02-23T18:14:30.460

    Reputation: 409

    0

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

    Christian Sievers

    Posted 2012-02-23T18:14:30.460

    Reputation: 6 366

    0

    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.

    histocrat

    Posted 2012-02-23T18:14:30.460

    Reputation: 20 600

    0

    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>

    Ronronner

    Posted 2012-02-23T18:14:30.460

    Reputation: 129

    0

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

    user5957401

    Posted 2012-02-23T18:14:30.460

    Reputation: 699