text:
Convert __DATE__-style string to sortable string
Goal is to write the shortest possible C89 and C99-compliant single-module C program which will compute and print out a single-line string whose sort order will correspond with the date given by the predefined __DATE__ macro (in other words, later dates will yield later-sorting strings).  The programmer is free to arbitrarily select the mapping between dates and strings, but every entry should specify the mapping and it should be obvious that it will sort correctly (e.g. a programmer could decide to compute (day + month*73 + year*4129) and output that as a number, though it's likely that particular encoding would probably require a longer program than some others).
The program should yield identical results on any standards-compliant compiler on which 'int' is 32 bits or larger and both source and target character sets are 7-bit ASCII, and should not rely upon any implementation-defined or undefined behavior nor print any characters outside the 32-126 range except for a single newline at the end.  The program should contain the following aspects indicated below (replacing «CODE» with anything desired):

♯include <stdio.h>
«CODE»int main(void){«CODE»}

All output shall be produced by the printf at the end (i.e. the correct value will be in an int called z).  The required elements will be included in the character total for each entry.
Code should operate correctly for all future dates through Dec 31 9999.  Libraries which are standard in both C89 and C99 may be used, provided that appropriate headers are included.  Note that standard date libraries may not be assumed to operate beyond the Unix limits.
Note: Code is permitted to perform Undefined Behavior if and only if the __DATE__ macro expands to a macro other than a date between Feb 11 2012 and Dec 31 9999 (expressed in that format, using C-standard abbreviated English month names Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec)
Note 2: For compliance with C99 standards, 'main' should return an arbitrary, but defined value, and the newline is required.  The first requirement, btw, adds 7 characters to my best effort; the single new-line adds 5.

This seems kind of pointless because there is already a UNIX timestamp that you can perform operations on to determine the date, and is constantly increasing. also, is this code golf? you should tag it as such

Unix date does not match criteria to reach 2099: LC_ALL=C date -d "2060/02/13"  date: invalid date 2060/02/13'`

@Blazer: I would consider the use of a Unix timestamp to violate the prohibition against date-parting routines.  The primary goal is to figure out an efficient way of converting "Jan/Feb/Mar/etc" into a sortable number.

@userunknown: Depends on the unix. 32 bit unix time runs out in 2038, I think, but 64 bit unix time...Scientific Linux 5.3 gives $ LC_ALL=C date -d "2060/02/13" Fri Feb 13 00:00:00 CST 2060 on x86_64.

That said, this question need to be formed as a CodeGolf.Se compliant puzzle (with the winning condition specified and the like). Supercat, please feel welcome here, but also read the FAQ and examine some of the other questions here. I'll be happy to reopen this when you've tuned it up a little. Just submit a flag for help.

so is this for any language, or is it only limited to C?

@Blazer: I'd be interested in seeing approaches for approaching similar problems in other languages, but for purposes of scoring I think it's probably easiest to restrict "official entries" to C programs which are compliant with C89/C99.

@supercat: I'll submit my Python answer anyways, then! :)

I have a 185 char C program but I can't post it. This makes me sad :-(

Thanks @supercat, that's just the kind of thing we're looking for. Personally I'm not a big fan of language limits, but there seems to be a consensus to allow them (or at least no consensus to not allow them).

@dmckee: I think the issue is that different language have different amounts of unavoidable baggage, and the number of characters required to solve a problem in one language may be less than the number of characters to 'get out the starting gate' in another.  My original concept for this problem was to have a function return an 'int', but there seems to be a preference for standalone programs.  Using a function rather than a program could have eliminate the #include, for example, though for another puzzle I might specify a 'test' program with which the function must work.

@Gareth: The topic is open now, if you'd like to come back.  My program, including the trailing newline and a defined return value, is 115 characters and I wouldn't be at all surprised if it could shrink a tiny bit.

Challenges on the site come in all varieties, there are those that specify functions and those that specify whole programs. As for the differences between language, there is no consensus on who to deal with it: see Language Handicap, should imports/includes count in golf, What programming language should we consider for the code-golf solution ? and may other questions on meta.

@supercat 115! I'm embarrassed by my pitiful attempt now...

@Gareth: I'll admit I have something of an unfair advantage, since I was trying to figure out a way to have an embedded system convert __DATE__ into a version number, stumbled upon a really nice trick, and then decided it would make a cute puzzle.  Admittedly my goal was smallest compiled code size, but I think my trick works out well by any metric.

@dmckee: Wow. The first time in my live I'm thinking about a 64 bit system. :)

C, 137 184 184 140 120 106 103 characters
Replaced the month name lookup with a magic formula.
The formula (m[1]*4388^m[2]*7)%252 is ascending for month names.
Changed it to nicely return 0, at no cost.
It no longer prints a number. Instead it prints a string, which should sort right.
Implemented supercat's %*s idea, which inserts more spaces for earlier months, along with a function that's descending for month names - (m[1]*29^m[2]+405)%49.
#include<stdio.h>
int main(void){
    char*m=__DATE__"%*.6s\n"+1;
    return!printf(m+6,(*m*29^m[1]+405)%49,m);
}

I thought single digit days are represented as Jan_1_2012 (_ being a space), when in fact it's Jan__1_2012 (extra space). This complicated things, so my previous versions were more complicated:
#include<stdio.h>
int main(void){
    char*m=__DATE__+1,*t=m+m[4]/16;
    return!printf("%s%3d%s\n",t+3,(*m*4388^m[1]*7)%252,t);
}

I hate to be nit-picky, but is the use of an unprototyped strstr function C99 compliant?  Also, my original plan for the puzzle was to compute a single integer, but given the present requirements if you can save a few characters by assembling an output string you should do so.

Added #include<string.h>, sacrificing some more characters. I don't know if it's required by c99, but considering 64bit, where assuming strstr returns int can end badly, it's better like this. So now I'm barely ahead of the competition (but being ahead thanks to omitted includes isn't such a big deal).

That sort of formula is the type of thing I was hoping to see in answers.  I spent a lot of time crunching mine, but it still has an 11-character string literal in it.  I think your program relies upon Undefined Behavior on a 32-bit machine when the year exceeds 8191, though.

Indeed, there's an integer overflow, which is harmless on normal compilers. y*252 keeps the numbers small, but is two characters more. Perhaps a U on one of the constants will promote everything to unsigned (but how to test it, given that it works as is in all compilers I know?)

Adding a "u" to the constant 4388, 7, or 252 would I believe eliminate any Undefined Behavior, but compare the strings output by your program on "Jan 01 6000" with those for "Feb 14 2012".

Indeed, you want strings to sort, not numbers. y*252 fixes both issues, but costs 2 characters. U won't help, because y*y overflows, and promoting to unsigned later won't help.

The quantity 99999999 won't overflow a 32-bit 'int' until it's shifted left, so adding "u" to the indicated constants would prevent overflow.  It won't solve the sorting problem, though; nor will using "y252".

You're right, the overflow is only after the shift. I think y*252 does the sorting problem, because the result is always 8 digits.

You're right about eight digits; mea culpa.  In any case, you've got some more golfing before you beat my solution, though with your nice hash function you could do it.

I figured that a sortable string, rather than a number, doesn't have to be a bad thing. So now I'm 5 characters from your solution (but a very hard 5 chars...)

Is there any standard which permits DATE to be anything other than an eleven-character string?  I certainly did not intend to require programs to deal with ten-character strings of the form Feb 1 2012. Your handling of ten-character date strings is magnificent, and would be worth keeping as a note, "if support for strings of the form 'Feb 1 2012' were required...".  Without that requirement, see if you can get down to 105.

@supercat, If only you published this challenge on February 9th, not 10th... Tests with __DATE__  will only reveal this next month, and tests with generated strings depend on how you generate them. I need to set the clock on a machine and see __DATE__

Yeah, sorry about that. I realized after I saw your answer that I was perhaps unclear. In any case, your handling of variable-length date field is amazing, and I'm glad I got to see it. BTW, I'm trying to figure out, as a separate challenge, if there's any way to abuse the preprocessor to convert __DATE__ into a static integer constant. I figured out a way to surround __DATE__ with doubled quotes, so as to expose the month name to the preprocessor. I can't manage to gobble the whitespace characters, though, nor can I figure any context where two integer literals can appear adjacent.

I checked the standard, and it says a space is added before the day number if it's a single digit. About making it a number - I think __DATE__[xxx] is the way. I don't think there's any way to get rid of the quotes (I tried to define a macro to be a single ", but failed).

Subscripted elements of a literal are not considered to be compile-time constants.  The trick would have to be something more like #define p2(x,y) x##y #define p1(x,y) p2(x,y) #define Feb February p1(/,*"*/"__DATE__"/*"*/) which is thoroughly evil, but might be workable.

You're right about constants, but I doubt if you can do better. Your code does warning: pasting "/" and "*" does not give a valid preprocessing token, and pasting results in / *. I don't think it can be done.

Hmm... Microsoft is probably not being standards-compliant then.  In any case, I think there are two separately-applicable improvements left.

When do you think I should post my original answer?

Now would be a good time. I don't see how to improve it further (I guess there's a way if you say so, but I can't find it).

A couple hints: (1) Were it not for the requirement that there be exactly one newline, concatenating the format string to __DATE__ would save %s and a comma (three characters).  Fixing the newline requires adding two characters, but still leaves a net shrinkage of one character.

(2) There's exists at least one hash function which is conceptually similar to yours, but one character shorter, where months will either be in order or will 'tie', and where numerical ties will still result in proper sequencing.  Incidentally, if one had a hash function which was the same length, but returned numbers in the reverse of month order, and always returned numbers larger than six (but preferably less than a few thousand) one could save another character, one could save a character on the formatting.

(1) I did try concatenating the format string and __DATE__, and had the newline problem. But it cost me too much, even without fixing the newline (though I didn't see the cheapest %.4s). Adding "\n" after __DATE__ was an extra pair of quotes, and m+7->m+14 was another wasted character.

(2) I'm tired of looking for hash function. I used code to search for constants, but played manually with operator combinations, so the search wasn't exhaustive. I also didn't allow ties, though indeed they can be be broken with the month first letter (or second, if I use __DATE__+1 and m[1]->*m). With the reverse order, I guess you mean something like %*s, though I'm not sure about the details. Anyway, I'm out, let's see your code (and maybe the merge of both).

OK, I'm not 100% out yet. I did manage to combine the format string with __DATE__, with no newline problems. 2 characters saved. So perhaps it's possible, with an improved hash function, to reach 100?

Also replaced the hash function by a shorter one, that ties for Jan/Feb, but I break it correctly using the second letter.

Doesn't your %s output a newline in addition to the one in the format string?  My best is 105, which was like yours but with a %.5s to avoid outputting the extra newline.  I don't think I would have found the operator combination for your hash function by myself, but I did search for and find the same combination you had.  I'll post my previous as an answer.

(see last comment also) I hope you liked the challenge.  My "reverse order" thought would have involved using the "*" format sub-specifier as an alternative to "%3d".  If the * required took argument of type unsigned rather than int, one might be able to shave a character by having the format range from e.g. INT_MAX-94 to INT_MAX.  That might yield a solution which was technically correct, but which would be incredibly icky on anything larger than a 16-bit machine (on a 64-bit machine, one would have a program whose output would be correct if it could be run to completion...

...but in practice would be completely unworkable.  (Un?)fortunately the C standard doesn't allow for that.

I did manage to get %*s to work, along with the format string concatenated with __DATE__. I found another hash function, which is descending (not strictly, but tie broken correctly). It does go below 6, but only for December, which is still OK. 103 again.

Bottom line, there was certainly a surprising amount of challenge in here. It's a very simple task, with the eventual solution much shorter and a lot different from initial attempts. But I still wonder if 100 is possible...

I'm glad you enjoyed the challenge.  What do you think of my solutions?

Too bad I required the single newline after the output.  Otherwise you could do 99 easily.

Yes, m+6->m and %*.6s->%*s. Better, if you didn't insist on C99 compliance, I think I could go below 80.

C, 194 characters
#include <stdio.h>
#include <string.h>
d,y,n[3];
int main(void)
{
sscanf(__DATE__,"%s %d %d",n,&d,&y);
return printf("%d%02d%02d",y,13-strlen(strstr("JanFebMarAprMayJunJulAugSepOctNovDec",n))/3,d);
}

I think most of the newlines are unnecessary, but I've left them in for readability.
Not sure what your feelings are about compiler warnings - this throws a few but runs fine. Also not sure whether the declarations with no type are valid C89 or not.

I don't believe C99 allows for implicit declarations of variable type.  Even if such declarations were permitted for variables of type int, your substitution of an array of int for an array of char is almost certainly illegitimate.  I'll also suggest that trying to convert the month into a nice number from 1 to 12 isn't necessary.  As a simplification, arrange the months in the other order and you could drop the "13-" and the "/3".  December would yield 36 and January would yield 3.  That would save you five characters right there.  Also, you if you append the declaration of a char*...

..with your declaration of n[], it might be profitable to define a variable for your "JanFeb"etc. string so you can subtract the strstr result from its base address.  I don't think the strstr approach will get as short as my solution, no matter what you do, but it would be interesting to see how close it gets.

Here are the solutions that I had come up with (for brevity, I'm just writing the #include line once--copy and paste as needed to assemble a testable program).

(my entries)
#include <stdio.h>
int main(void){char*d=__DATE__"%s%sDFCwu-vBxE-t%c"+1;return printf(d+6,d+(*d+d[1])%17+9,d,10);}
int main(void){char*d="h-elbj-ikcfdga-"__DATE__+16;return printf("%s%s\n",d+6,d-(*d+d[1])%17);}
int main(void){char*d=__DATE__+1;return printf("%s%x%s\n",d+6,3**d+"![ WT -#[ 8"[d[1]%12],d);}
int main(void){char*d=__DATE__"%x%.5s\n"+1;return printf(d+6,3**d+"![ WT -#[ 8"[d[1]%12],d);}
int main(void){char*d=__DATE__"%x%.5s\n";return printf(d+7,d[1]+"1C0EB042E0:"[d[2]%12],d);}
(ugoren's entry, golfed, for comparison, and adding .5 to the %s format specifier)
int main(void){char*m=__DATE__"%3d%.5s\n"+1;return!printf(m+6,(*m*803^m[1]*95)%94,m);}

My initial approaches made use of a month-to-number approach which can turn each month into an arbitrary character.  If in a production embedded-systems environment one had to turn an alphabetic month into a number 1-12, the approach might actually be an efficient algorithm to do so (perhaps using repeated subtract-17 instead of mod, if no other divisions are required).
Allowing the computation to return values which were sortable but not consecutive made it possible to use a smaller table indexed using the third character of the month, and add to that character the second.  A further savings was achieved by realizing that the multiplication by three I'd used to facilitate "tiebreaking" was in fact not needed, since the months which would otherwise yield matching hash values were correctly sortable by their first character.
I tried quite a few variations, but nothing came close to the operator combination that ugoren found, which don't require any table.  I was also impressed by his entry which would have accommodated single-digit dates without padding, which would have been a challenge in its own right, and one which I doubt that I could have handled as nicely.

Certainly nice solutions. All based on converting the month to a unique number, then using a table to make it sort right. Using just one character with the table, while breaking the ties using the other is also a nice idea.

C, 163 characters
A different approach from my other solution.
I can save 13 characters by making t an int array, and relying on the internal layout of struct tm. But I guess it violates the rules.
#define _XOPEN_SOURCE
#include<time.h>
#include<stdio.h>
int main(void){
    struct tm t;
    strptime(__DATE__,"%b%d%Y",&t);
    return printf("%d\n",t.tm_year*366+t.tm_yday);
}

I should have been clearer in my wording, as I meant to imply that code should operate correctly in any standards-conforming C89 compiler and also work correctly with any standards-conforming C99 compiler.  Still, since I was unclear about that, that wouldn't be a disqualifying factor if the C99 standard in fact states that the libraries will work all the way through Dec 31, 9999.  Does the spec in fact promise that?

I actually have no idea. But since my other answer is much shorter, and makes no such assumptions, I don't think I'll bother checking it.

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
Can you find Waldo?
Where's Waldo is a searching game where you are presented an image of some scene, and your goal is to find a man named Waldo in the picture.
Here are a couple pictures showing what Waldo looks like. He always wears a red and white striped sweater and hat, blue pants, brown shoes and hair. He can be with or without accessories such as a camera, glasses, or a cane.

And here are some of the scenes where Waldo is hidden. (You can right click the images and go to the image source for higher resolution.)

The Challenge
Write a program that processes the images (provided as input however you like) and finds Waldo in as many of the above five images as possible. Your program is scored using the following formula
codeLength / numberOfPicturesInWhichWaldoIsFound

and, of course, the lower the score, the better.

Note How do I find Waldo with Mathematica? and How to find Waldo with R? on Stack Overflow.

The problem that I see is that it might be much shorter (and probably easier) to hard-code the solutions into the program.

@PhiNotPi But that's cheating!

@PeterOlson I know, but this place is notorious for rules-lawyering!

How many correct answers are there for the last two? I haven't looked at the others, but in each of those there's more than one figure who seems to match...

In the fourth one, there are two waldoes, and in the fifth one, everybody's a waldo.

What output do you want? Coordinates or a circle of some kind? What is the required tolerance? It is trivial to draw a box that is guaranteed to contain waldo.

@CMP The coordinates or region should have a center point directly on some part of Waldo.

Voting to close because this question is eliciting only joke answers.  I also think it's poorly specified as to what the required output is supposed to look like.

Also voting to close, image processing is complex and getting something that even tries to find the image is a large, complex program which defeats the idea of code golf. And then you've got scaling and flipping and multiple images to check. It's hard enough for humans to do it and we've got specialised facial recognition hardware built in!

Oh, and not forgetting possible copyright infringement on those images!

Shell script, score 30/5 = 6
Since there's no specification on what comprises finding Waldo (i.e. how exact the location must be specified), I figure this program should give a rather good score, finding Waldo in every one of those pictures.
echo Waldo is in the picture.

-1: http://meta.codegolf.stackexchange.com/a/1070/9498

@Quincunx: 2014-02-23 is much later than 2012-12-21, isn't it? (Also note the "no longer funny" in the title of that meta item). Anyway, I'm not sure that criterion applies to my answer anyway (you should have selected "hard-coding the output" instead; this would at least unconditionally apply, although it still suffers from the after-the-fact issue).

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Reduce the amount of loops when finding if an element is stored only once in the array?
I was amazed to find that there is a way to reduce the times you loop on an array to find if a element is contained once.
One would think that the only way would be to loop through the whole array, and increasing a variable every time you find a match, and then check if it is equal to 1. However, lets look at this JavaScript code:
function isOnce(itm,arr){
    var first_match=-1;
    for(var i=0,len=arr.length;i<len;i++){
        if(arr[i]===itm){
            first_match=i;
            break;
        }
    }
    if(first_match!=-1){
        var last_match=-1;
        for(i=arr.length-1;i>first_match;i--){
            if(arr[i]===itm){
                last_match=i;
                break;
            }
        }
        if(last_match==-1){
            return true;
        }
    }
    return false;
}

It can reduce the times you loop when these two points met:

There are 2 or more matches
The first and last match are at least 1 space apart

so, arr=["a", ...(thousands of items here)... ,"a"]; //we only looped 2 times
I was wondering if there are other ways to reduce the looping in *certain cases.
*There are obviously some cases that one will need to loop through every item on these worst-case scenarios. So it might not work all the time.

This doesn't look like a competition to me. Migrate to SO?

@PeterTaylor, I think my question is just dumb, as 'ratchet freak' pointed out, it will remain at O(n) regardless on any algorithm. I think my question should be deleted or closed to prevent people from lowering their IQ

D
bool containsOnce(E,R)(R haystack,E needle){
     bool foundOnce=false;
     foreach(e;haystack){
          if(e==needle){
              if(foundOnce)return false;
              foundOnce=true;
          }
     }
     return foundOnce;
}

this is pretty much the best case on unsorted data, you loop until you find a match and then set a flag to true and continue looping, when you find the second match return false immediately, when you looped over the entire thing return state of the flag
this has better timebounds when the double match is found near the beginning of the array (and in general when the items are close together) (but is better in a code-golf contest ;) )
in interest of time bound you'll remain at O(n) regardless on any algorithm (sometimes there simply are no improvements possible except with micro-optimizations). as finding a single match (a subproblem of the current problem) in an unsorted array is O(n)

it make a lot of sense, I really don't know what I was thinking with those two loops


text:
Implementing a firewall
Your program reads from standard input and prints to standard output.
The first thing you'll be receiving on stdinput will be the ruleset for your firewall (until you encounter a double newline).
We'll start explaining the ruleset itself with some sample input:

/* header abbreviations added for demonstration purposes only */

 /> Allow (A) or Block (B)
|
|  /> Source (incl. mask)
| |
| |               /> Destination (incl. mask)
| |              |
| |              |          /> Source port(s)
| |              |         |
| |              |         |           /> Destination port(s)
| |              |         |          |

A 192.168.1.0/24 0.0.0.0/0 1024:65536 80
A 0.0.0.0/0 192.168.1.0/24 80 1024:65536
A 192.168.1.1/32 0.0.0.0/0 80 1024:65536
A 0.0.0.0/0 192.168.1.1/32 1024:65536 80
B 0.0.0.0/0 0.0.0.0/0 * *

Rules are processed in cascading order. Once you find a matching rule, determine the outcome and stop processing.
If a packet does not match any given rule, block it (sane defaults).
Elements of a rule are single-space delimited.
Source and destination adresses will provide a netmask. Be sure to filter accordingly.
The specification of the source and destinations ports must support the following syntax:

Single ports: e.g. "80"
Inclusive port ranges: e.g. "1024:65536"
All ports: e.g. "*"

You may assume input to be well-formed.

After the double newline, you'll receive (one or more) newline seperated input packets to test according to the ruleset you've now acquired.
Some sample input for the packets to clarify:

/* header abbreviations added for demonstration purposes only */

 /> Source
|
|             /> Source port
|            |
|            |     /> Destination
|            |    |
|            |    |              /> Destination port
|            |    |             |

192.168.1.18 1036 157.136.122.5 22
157.136.108.8 2400 192.168.1.1 80

You'll examine these input packets and determine the outcome of filtering according to the rules.
The above sample input (ruleset + packets) should thus yield the following output:

BLOCK 192.168.1.18 1036 157.136.122.5 22
ALLOW 157.136.108.8 2400 192.168.1.1 80

The output is basically no more than 'BLOCK' or 'ALLOW' followed by a space and the verbatim input line.
Some varia:

This is code golf, the shortest (source code, by byte count) solution wins. Have fun!
You are not allowed to use specific IP address handling features of your language.
Specialized languages for routing or firewalling will be excluded from contending for first place (if they exist).
If any part of the question is ambiguous or in need of further clarification, feel free to comment.

Haskell, 356 characters
main=interact$f.break null.lines;f(r,_:p)=unlines$map(foldr(g.w)(j"B"++)r)p
g[r,s,d,a,b]n x|and$zipWith3($)(cycle[k.('/'#),q.(':'#)])[s,a,d,b]$w x=j r++x|t=n x
k[y,z]x=y%z==x%z;y%z=foldl((.r).(+).(*256))0('.'#y)`div`2^(32-r z)
q["*"]x=t;q[y]x=x==y;q[a,b]x=r x>=r a&&r x<=r b
d#x=w$map(d?)x;d?x|d==x=' '|t=x;j"A"="ALLOW ";j"B"="BLOCK ";t=1<3;r=read;w=words

Perl 561
First try. Any tips?
[gary@phoenix ~]$ cat test | perl f2.pl
BLOCK 192.168.1.18 1036 157.136.122.5 22
ALLOW 157.136.108.8 2400 192.168.1.1 80

sub r{($i,$j)=split'/',shift;$j eq 0?'*':map$h.=sprintf("%.8b",$_),split/\./,$i;
substr$h,0,$j}sub s{$_[0]=~/(\d+):(\d+)/?$1<$_[1]&& $_[1]<$2:$_[0]==$_[1]}sub
t{chomp;($a,$b,$c,$d,$e)=split/ /}sub o{$_[0]eq'*'or$_[0] eq
substr&r($_[1].'/32'),0,length$_[0]}sub p{$_[0]eq'*'or&s($_[0],$_[1])}
map((/^[AB]/?(t,push@f,join' ',($a,&r($b),&r($c),$d,$e)):push@g,$_),<STDIN>);
push@f,"B * * * *\n";for $q(@g){if($q=~/[0-9]/){($k,$l,$m,$n)=split/ /,$q;
for(@f){&t;$a=$a=~/^A/?'ALLOW':'BLOCK';&o($b,$k)&& &o($c,$m)&& &p($d,$l)&&
&p($e,$n)?print"$a $q":next;last}}}

I'm not familiar with Perl, but at first glance, I see lots of duplicate code, like ($a,$b,$c,$d,$e)=split(/ /); and (($b eq '*') || $b eq substr(&r($k.'/32'),0,length($b))).  Try factoring those into loops or functions.

A lot of the whitespace can be removed. ...?return 1:return 0 seems to cry out for return ...?1:0 or even return ... if that works. (My knowledge of Perl is quite superficial).

You read my mind. I just changed that return statement. I'll work on the rest of the whitespace. I believe the return (VALUE) needs to stay so that perl doesn't try to interpret return(ARGS).

I believe you can remove the whitespace around ==, ||, ? and :; and the whitespace in $q (, and before all "s.

Thanks for all the help. I think I've gone about as far as I can short of writing a more efficient process.

From a quick glance: 1) most ;} sequences could be rewritten as just } 2) don't call functions as &o, go for straight o 3) a lot of function-call-parentheses can be dropped (for user-defined functions, move the definition somewhere before the call) 4) a lot (all?) of returns can be dropped.

@JB When I remove return from sub r{($i,$j)=split('/',shift);$j eq 0?return'*' perl complains about me calling it in void context. Useless use of a constant in void context at f3.pl line 5. I'm calling this subroutine as a scalar, is this just perl getting confused?

r might be a case where you can't do it, since return was being used to short-circuit the rest of the function body.

Ruby (384)
Not sure it's 100% correct, but works at least for the given example inputs. Propably could be made a bit shorter too.
$ wc gc4907-firewall.rb
       9      15     384 gc4907-firewall.rb

$ cat fwinput| ruby gc4907-firewall.rb
BLOCK 192.168.1.18 1036 157.136.122.5 22
ALLOW 157.136.108.8 2400 192.168.1.1 80

q=->x{x.gsub(/(\d+)\.?/){'%02x'%$1}.hex}
w=->x{u=x.scan(/[\d.]+\/\d+/)
p=$'.split.map{|z|z=="*"?->y{1}:(z=eval z.sub(?:,'..');->y{z===y.to_i})}
f=u.map{|z|a,m=z.split ?/;a=q[a]>>(m=32-m.to_i);->y{a==q[y]>>m}}.zip(p).flatten
->y{f.zip(y.split).all?{|z,c|z[c]}&&x[0]}}
s=[]
while gets=~/./;s<<w[$_];end
s<<->x{0}
$<.map{|p|s.map{|f|(f=f[p])&&(puts (f=="A"?"ALLOW ":"BLOCK ")+p;break)}}

$' seems to confuse both brace matching in emacs, and syntax highlight here.


text:
ASCII ruler generation
The challenge is to generate an ASCII character count ruler in the following format:
+-------------------------------------------------------------------------+
||    |    |    |    |    |    |    |    |    |    |    |    |    |    |  |
|0         10        20        30        40        50        60        70 |
|                                                                         |
+-------------------------------------------------------------------------+

The length of the ruler should be scalable to any multiple of 10.
Rules:

Ruler must be horizontal.
Let's say, to keep things simpler, that the ruler must work until the 1000 mark, all numbers left-aligned, one space after the final number.
Asking for a ruler with zero length should print NaR
Negative numbers should print a reversed ruler (-90, -80, -70, ...) with right-aligned numbers, in the exact same format as the one above otherwise

And, just printing to console is fine
Ready, set, golf!

How does the program know how long to make the ruler? Is it provided as a number on STDIN?

Yes, as usual I guess!

Does the ruler have to be horizontal or vertical? if it's horizontal, can we assume a maximum of 80 characters, or do we output this to a file to avoid wrapping instead? or do we have to resize the console/terminal when writing to stdout?

How to handle input of 1000000010 or greater?

It looks like multiples of 10 are left-justified to the mark.  What about when it reaches 100, 110, etc.  Are those left-justified as well, or do they become centered?

Also, it looks like you leave one extra space after the final number, is that the general rule?  For really large multiples of ten, you'll be ending up with almost another 5-10 length afterward just spacing out the last number...

And what does the case of ruler size 0 look like?  Three wide with a 0 in the middle?  A vertical line?  You should probably give something like the following set of examples to help address these conerns: 0, 70, 150 (for example).

I didn't expect things to be so specific! That's good. So: 1) Ruler must be horizontal. 2) Let's say, to keep things simpler, that the ruler must work until the 1000 mark, all numbers left-justified, one space after the final number. 3) Asking for a ruler with zero length should print NaR.

Is it also safe to assume negative numbers will print NaR as well? And my other question remains unanswered: do we write to a file if the result would be too big for a console?

Negative numbers should print a reversed ruler (-90, -80, -70, ...) with right-aligned numbers, in the exact same format as the one above otherwise. And, just printing to console is fine.

One of the main points of code-golf is that the problem must be 100 % unambiguously specified (see the faq).  There is little room for creativity in the actual output, because the creativity is in the code itself.  In the future, please try to think through all of these possible cases before posting the question, but since you're new, we're helping you out :)

Could you please edit the challenge to include rules specified in the comments?

So does that mean with negative numbers there is a single space to the left of the smallest number? Or should there be a space to the right of the 0 in that case?

Blazer: It's usually safe to assume that output won't wrap and if it does it's more a result of the surrounding conditions than the actual problem and solution.

Didn't play codegolf but this one inspired an entire R package: https://github.com/leipzig/asciiruler

Python - 227 232
Supports entire specification
edit: improved generator expression.
Supporting right aligned negative numbers adds a surprising amount of code.
b,p,d,w,='|+- '
g=input
s=''.join(('%'+d[:i>0]+'10s')%i+['',9*w][i==0] for i in range(g(),g()+1,10)).strip()+w
m,n=s[0]==d and s.find(w)-1,len(s)
t=p+n*d+p
print['\n'.join([t,b+(w*m+'|    '*n)[:n]+b,b+s+b,b+n*w+b,t]),'NaR'][n<9]

Sample outputs:
-30
30
+-----------------------------------------------------------------+
|  |    |    |    |    |    |    |    |    |    |    |    |    |  |
|-30       -20       -10         0         10        20        30 |
|                                                                 |
+-----------------------------------------------------------------+

-30
-30
NaR

100
150
+------------------------------------------------------+
||    |    |    |    |    |    |    |    |    |    |   |
|100       110       120       130       140       150 |
|                                                      |
+------------------------------------------------------+

-1000
-950
+--------------------------------------------------------+
|    |    |    |    |    |    |    |    |    |    |    | |
|-1000      -990      -980      -970      -960      -950 |
|                                                        |
+--------------------------------------------------------+

Not going to beat the dynamic languages today, but anyway...
Haskell, 341
import Data.List
main=interact$unlines.m.map read.words
m[l,r]|r>l=ᴛ.("┌│││└":).(++["┬   ─","┐│││┘"]).ʀ.t.ʀ.t.takeWhile((>4).length).ᴛ$[c"┬",c"│    ",[l,l+10..r]>>=h.show,c" ",c"─"]|True=["NaR"]
h s=p s$length s;p s@('-':_)l=r(6-l)ꜱ++s++r 4ꜱ;p s l=r 5ꜱ++s++r(5-l)ꜱ
ᴛ=transpose;ʀ=reverse;r=replicate;c=cycle
ꜱ=' ';t l@(c:o)|c!!2==ꜱ=t o|True=l

I took the liberty of exchanging the actual ASCII characters with better-looking unicode box drawing chars.
$ echo "-50 30" | runhaskell  def0.hs
┌┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┐
│  │    │    │    │    │    │    │    │    │    │    │    │    │    │    │    │    │  │
│-50       -40       -30       -20       -10         0         10        20        30 │
│                                                                                │
└─────────────────────────────────────────────────────────────────────────────────────┘

The ruler looks very, very nice.

Python 2.7, 342 266 260 chars
a,b,c,d,m='+|- \n'
def f(y):x=map(str,(range(0,y+1,10)if y>0 else range(y,1,10)));h,g=len(x[-1])+1,len(x)-1;u=a+(c*10)*g+c*h+a;return'NaR'if y==0 else u+m+b+(b+d*4)*2*g+b+d*(h-1)+b+m+b+''.join(i.ljust(10)for i in x[:-1])+x[-1].ljust(h)+b+m+b+(d*10)*g+d*h+b+m+u

returns a tuple of each line string, which you can then print or save to a file (I prefer the latter for lengths longer than 70 becuase the console will jsut make it look messed up with wrapping)
Assumes y to be a string (raw_input() n python, or sys.argv[1] if you wish to invoke via cmd) an integer (eg with input() in 2.x or int(input()) in 3.x)
I made this a function to be more flexible
edit: reduced to 266 characters. no longer returns a tuple, but a string instead. Now takes an integer instead of a string as the argument
edit2: reduced to 260 chars, single line function
note: does handle negative numbers, but doesn't right justify (I don't really htink the justification is too important anyways

Or just use a non-linebreaking console (e.g. Terminator).

@leftaroundabout I wasn't sure such a thing existed

regardless, having to install a separate platform just to make a ruler seemspretty pointless, where-as creating a return value that anybody could use (write to a file, etc) is more universal

@Blazer, does your shell not have pipes and redirects?

PowerShell, 256 253 233 225 222 bytes
param($a,$b)('NaR',$($d=@{}
$a..$b|%{$d.$_=' ';0..($l=($s="$($_-$_%10)").Length-1)|%{$d[$_+$s-$l*(0-gt$s)]=$s[$_]}}
$d.Keys|sort|%{$e+='-';$p+='|    '[$_%5];$r+=$d.$_;$w+=' '}
@"
+$e-+
|$p |
|$r |
|$w |
+$e-+
"@))[$a-lt$b]

Try it online!
Less golfed:
param($a,$b)
(
    'NaR',
    $(
        # {key, value} := {position, digit|minus|space}
        $d=@{}
        $a..$b|%{
            $d.$_=' '

            # draw a nearest left number
            $n=$_-$_%10
            $s="$n"
            $l=$s.Length-1
            0..$l|%{
                $d[$_+$s-$l*(0-gt$s)]=$s[$_]
            }
        }

        # edge, points, ruler, whitespaces
        $d.Keys|sort|%{
            $e+='-'
            $p+='|    '[$_%5]
            $r+=$d.$_
            $w+=' '
        }

        # output the multiline string
@"
+$e-+
|$p |
|$r |
|$w |
+$e-+
"@
    )
)[$a-lt$b]

Perl 5.14, 198 224 chars
Probably can be shortened a lot further, but here's a first second attempt (with line breaks inserted for readability):
$l=shift||die"NaR\n";
@n=grep!($_%10),$l>0?0..$l:$l..0;
$l=9-length$n[$#n];
@f=('-'x10,'|    'x2,'@'.'<'x9,' 'x10);
@f=map$_ x@n,@f;
map$_=~s/.{$l}$//,@f;
eval"format=\n+$f[0]+\n|$f[1]|\n|$f[2]|\n\@n\n|$f[3]|\n+$f[0]+\n.\n";
write

EDIT: Edited to die with "NaR" when input is 0 and to support negative range.
EDIT2: I haven't had a chance to work more on this, and I only just now noticed the right aligned for negative numbers rule, which my code doesn't support, so I think another solution should be marked as the answer if the deadline has been reached.

@louism: My answer doesn't conform to all the rules. Another answer should be chosen if possible.

Python, 291 241 characters
A pretty simple approach. I'm sure it can be improved quite a lot.
I tried to follow the guidelines in the comments, but I don't support negative numbers (it was a joke, I hope).
This is a program, prints the ruler to standard output. If your screen is wide enough, it should support pretty long rulers.
import sys
def p(b,a="|"):print a+b+a
j="".join
l=int(sys.argv[1])//10*10
if l:
    d=j(["%-10d"%n for n in range(0,l,10)])+"%d "%l
    L=len(d)
    h="-"*L
    p(h,"+")
    p(j(["|    "[n%5] for n in range(L)]))
    p(d)
    p(" "*L)
    p(h,"+")
else: print "NaR"

You can golf a few more characters off of this I shaved off 12 characters here

Thanks @GordonBailey, but there's already a winner anyway, which is shorter than my code and supports the full specification.

C++, 392
This is programmed using the windows console, therefore I just chose a maximum ruler size is 70, it'll just crash for anything bigger.  Negative numbers( up to -70) and 0 are handled correctly.
#include<ios>
#define q s[2][i
#define v ,memset(&s
char g,o,i,n,s[5][80];int main(int a,char**b){a=atoi(b[1])v,32,400);n=0<a;for(a=abs(a)v[0][1],45,a+3)v[4][1],45,a+3);i<a+4;++i)o=i-n,!(o%5)?s[1][n?i:i+3]='|',(o%2-1?(n?q]=i/10+48,i>9?q+1]=48:0:((a-i)>9?q+2]=(a-i)/10+48,q+1]=45:0,q+3]=48)):0):0;for(;g-5;g++)for(s[g][a+4]=s[g][i=0]=g&g-4?'|':43;i-80;i++)printf(a?"%c":g+i?"":"NaR",s[g][i]);}

Python - 208
(does not support right aligned negative numbers)
 l,u=map(int,raw_input().split())
 n=u-l
 q="+%s+\n"
 q=q+"|%s|\n"*3+q
 print q%('-'*n,(''.join("|    "for i in range(n)))[:n],(''.join("{:<10d}".format(i)for i in range(l,u,10)))[:n],' '*n,'-'*n)if n>0 else"NaR"

I think my favourite trick was to generate strings that are way longer than necessary and then truncate them, for example:
 ''.join("|    "for i in range(n)))[:n]

I just wish there was a more concise string formatting option for left-alignment (unless there is one that I just don't know about)

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Determine if a number is divisible by 13 (without using 13 itself)
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.

is 'true' or 'false' a valid output?

JavaScript (27 chars) function f(n){return "yes"}. This will return 'yes' for all the numbers that can be divided by 13

"(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, there's already a challenge for that. Exploit "free whitespace"

How does the bonus work if you have no mod, no div? then just 0.8?

Do "the 6th Fibonacci number", or "the 6th prime number" count as cop-outs here?

Using some roundabout method of generating the number 13 for use is acceptable. How do you determine what is "roundabout enough"?

@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?

@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 - I'd totally forgotten about it too but I kept getting notifications about it.  I had no idea it would suddenly become popular again.

@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

var o="             "; if((input%(o.length))==0){return "yes"} else {return "no"}

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

Ingenious.  I like it!

println -> print?

@Geobits, true.

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$'

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

rule: The input will always be an integer greater than 0 and less than 2^32. You can't use 16bit

@Fabricio: All 16bit numbers are less than 2^32. :-)

lol.. you're right somehow. But you can't handle 2^32-1 =p

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.

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

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

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.

If only everyone would comment their golfscript code so well. Kudos

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

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.

Is this still valid even though it's very non-standard?

@oldrinb, I see no requirement for standard compliance in the question. In general, strict standard compliance is awfully annoying in code golf.

Could you explain why this works?

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

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

Multiply everything by two and use 26 instead... didn't see that coming.

You can omit the ~~ assuming valid input; otherwise prompt()<<1 will work too.

Although I will admit it technically doesn't reach the limit of 2^32 anymore using this method..

In fact it does work beyond 2^32 since you dropped any bitwise operators now.

Might not be the highest score, but the most readable and clear

This is still using an arithmetic quickie to determine divisibility by 13, and there was a rule saying no arithmetic cop outs...

@WallyWest: We all had fun at the time.  Is it really necessary to downvote an answer that is over two years old?

@Mellamokb Sorry, got a little overzealous... Reverted

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.

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.

@GigaWatt it calculates the modulus.

Aye, 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.

@GigaWatt I didn't disagree with you, just answered your question.

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"

I wondered how long it'd be before I saw someone exploit ascii values.

Can you add the score to your post please?  Should be 38 * 0.9 = 34.2.

Haskell, 28 * 0.8 = 22.4
f x|gcd 26x>2="yes"|1<3="no"

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]

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

f=lambda n:pow(8,n,79)-1 and "no" or "yes" fixes it, 43*0.8=34.4

ECMAScript 6, 25 × 0.9 = 22.5
Yeah, it's a boring way of getting 13.
n => n % '             '.length ? 'no' : 'yes'

i was trying to figure out how your score was so low, then i realized the genius in using whitespace for your number... lol

+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 Wish granted

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;}

Nice use of \r - I thought it's only good for Windows support. But why c>0 when c would do?

@ugoren: it wouldn't do, think about it.

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.

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

I so want to be pedantic about bytes.

Ohhhhhhhh snap you di-int.

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

You're using 13 via f(7)... That's kinda bending the rules a bit...

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.

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'
}

You can save two chars by changing return to return n-c?'no':'yes' and omitting the second semicolon.

@mellamokb Good catch. Could probably improve further by writing it in Ruby, or something that allows more compact function definitions.

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.

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)

Perl (19.8)
21 bytes * .9
say2*<>%26?"no":"yes"

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

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

Thought I had accounted for the whitespace.  Fixed now.  Thanks for pointing that out.

Wow.  No love for Perl.  Can't say I like it either.

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)

If 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

Ruby (50 48 * 0.9 = 43.2)
Smart way to use eval
eval x="p gets.to_i*3%x.length == 0? 'yes':'no'"

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

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.

Cheddar, 20 bytes (noncompeting)
Score is 20 * 0.9 = 18
n->n*2%26?'no':'yes'

A straightforward answer.

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

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

doesn't modf count as using modulus?

@Blazer not really it takes the fractional part of the first argument and returns it while storing the integral part in the second arg

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!

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

I see a cop-out with the different bases

14 in base 9?  I should have seen that coming.

print['no','yes'][input()%int('d',14)==0

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

@StevenRumbalski thanks for the 1 char save :P

print'yneos'[input()%int('d',14)==0

I do think this fails the rule "No cop-out synonyms for 13 either (like using 15 - 2)".

Forgot a closing bracket 2 comments ago:  print'yneos'[input()%int('d',14)==0]

@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.  Sheesh, I'm full of errors.  At least I got it right in my answer.

we'll let @GigaWatt decide whether the base cop-out counts as a violation of the rules or not

@Blazer:  If int('14',9) is acceptable, you may as well shorten it to 015.

@StevenRumbalski how does that work exactly? edit: nvm I see now that it's octal conversion

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.

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]

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.

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

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.

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

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.

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.

I'm... not even sure what I'm looking at here.

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

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.

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.

Mathematica 26*.9 ==23.4
If[2 n~Mod~26 == 0, "yes", "no"]

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.

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

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

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

This takes a ridiculously long time for input 4294967287.

Use inline if ?: to save a few chars.

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

Nice idea, if you use backticks instead of $( ... ) you have one char less.

@PetervanderHeijden: Thanks!

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()));
}

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.

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.

Ruby 34x0.8 = 27.2
p gets.to_i.gcd(0xD)==0?"yes":"no"

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

13 = x+13 mod x.

Why *0.8? You're blatantly using mod.

I didn't get it right, my bad

Still not quite right: you get a multiplier of 0.9 for using mod but not div.

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

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.

I think you meant var s at the beginning. Also, try to get rid of useless whitespace (ex: *2/26 instead of * 2 / 26)

the last two lines can be rewritten as Console.Write(s==(int)s?"Yes":"No")

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'

Q, 30 * 0.9 = 27
{$[0=x mod "i"$"\r";`yes;`no]}

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

Hi 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!

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

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)

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.

Ah. I missed ELSEIF s > i.  Good call.

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

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

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

Julia, 30*0.9=27
f(x) = x%endof("            ")==0?"yes":"no"

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.

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

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.

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

Try it out here

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.

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

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.

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

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

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.

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

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

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.

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>


text:
Pluralize it!
The challenge:
Write a program or function in any language that takes as an argument (command-line or function) a single English word. It returns or outputs the pluralized form of the word.
(To clarify, the program or function will be executed many times on different words, but separately - the list of words won't be passed all at once.)
The scoring:
The score of a program or function is -(characters in program + 1) * number of wrong answers. Highest score wins. Joke answers will likely lose by a huge margin (I'm planning on putting in maybe 1,000 words) and if you're amazing you get the highest score of 0.
Example test data:
woman
turn
fly
court
finger
blitz
pie
injury
vertex
alleyway
alloy
ox
goose
mouse
house
louse
waffle
right
bacterium
virus
cherub
chaetognath
boy
man
shaman
figure
prefix
etc.

Those are just some that I picked off the top of my head. The real test cases will have even stranger plurals, but the distribution between types of suffixes will be more even.
Enjoy!
Additional Rule
No Mathematica. Sorry.

The problem with your proposed scoring is that a program which gets everything right can be arbitrarily big, it will always have score 0. That's hardly code-golf-ish, you'd simply need to include an entire dictionary! I'd suggest (characters_in_program + 1) * (wrong_answers + 1) instead.

@leftaroundabout: I'll throw in a plural that people are unlikely to have ever heard of. If it includes that, well... it deserves the highest score! :)

Also, you should perhaps specify whether answers like this will be accepted.

@leftaroundabout: Ah, yes. I was meaning to add that. And the answer is NO! But for the other possible "loopholes" and rule-bending, they're still allowed.

By the way, something which hadn't occurred to me earlier: how does your test script handle cases where there's more than one correct answer?

@PeterTaylor: I was originally going to allow any correct answer to be counted as correct, but I've now decided that only the plural forms of the world that break the most rules will be correct. Just to make things a little more fun :)

Meh. That makes it even more of a guessing game than it already was.

@PeterTaylor: Fine, fine, anything accepted. No more guessing game.

sed - 155 (not including #! line)
#!/bin/sed -Ef
s/man$/men!/
s/([aeiou](x|z))$/\1es!/
s/ium$/ia!/
s/([^!aeiou])y$/\1ies!/
s/((r|gh|l|s)[^!aeiou])$/\1s!/
s/([^!aeiou]{2}|.s)$/\1es!/
s/([^!])$/\1s/
s/!$//

This will read from stdin, and I think it will do an okay job for most input. The basic idea is that it tries each regex line by line. Whenever it matches it makes a replacement that appends ! to make sure that no other regexes will match, then it drops the ! on the last line.
I tried to deal with most special cases, but it will definitely fail on some (goose and mouse for example)
Sample invocation:
chmod a+x GordonBailey.sed
echo $word | ./GordonBailey.sed

Sorry, how do I run it? echo "test" > sed -f GordonBailey.sed doesn't output anything.

woops, added a sample invocation

Ah, thanks! Also, I'm looking for tests, not testes ;) Good job anyway, though - 1kw testing will now begin.

Hahaha, if it's not too late, I just modified to catch that case

Retesting now.

much appreciated

Shoot, it doesn't want to be automated. Lucky you, manual test :)

Really? If it makes it easier, since it's sed, it will read from a file line by line, so you could put all the words into a file and run it on the whole file: cat words.txt | ./GordonBailey.sed > output.txt

I don't know @minitech...I want to respect you, but I'm beginning to think you're not a unix user. ::gasps and shocked silence from the audience:: Whatever is the world coming to?

@dmckee: Isn't unix that thing that webservers use? (No, this is not serious.)

@minitech ::laughs:: Touche.

Best answer for now!

By the same token, it's also the worst answer :)

sed, 6 chars
Someone should give this a try...
s/$/s/

Invoked with sed -f myscript.sed < words.txt > output.txt
I can afford 22 times more mistakes, compared to Gordon Bailey's solution, and still win.
With the sample input I do win, because he misses "mice" and "lice" (and maybe more, there are some I need to look up), and this sample is too short for me to have 44 mistakes...

Nice. I'll be curious to see the final stats with a longer input list, this may well be the best approach.

require 'open-uri'

def p(w)
  open("http://en.wiktionary.org/wiki/#{w}"){|f| f.read}.match(/plural-form-of.*?title=\"(.*?)\"/)[1]
end

ruby at 135. It got all of the sample input (though it will eventually begin returning 403s if you type quickly enough).

Nicely done. If it does return 403s, though... (automated testing, so typing speed is not an issue.)

perl -mLingua::EN::Inflect=PL -pe's/.*/PL$&/e'

Extended BrainFuck: 9
,[.,]||s|

Compiling:
beef ebf.bf < plural.ebf > plural.bf

Turns into the following BrainFuck code: (39)
,[.,]>++++++++++[-<+++++++++++>]<+++++.

Sample invocation:
$ echo -n test | beef plural.bf

Any BrainFuck interpreter can be used instead of beef. It takes one word in stdin and ends it with EOF. Alternatively you can use echo test | bf -n plural.bf where in this particular interpreter-n assumes EOF on first linefeed.


text:
Square of the number of ones
I'm solving problem: in file "a.in" given the number N - length of the number consists of ones. Need to gets square of it, and put this in file "a.out". This is my shortest solution(150 bytes):
char s[1<<27];j;main(i,n){for(fscanf(fopen("a.in","r"),"%d",&n),i=n*=2;--i;j+=i<n/2?i:n-i,s[i-1]=48+j%10,j/=10);fprintf(fopen("a.out","w"),"%s\n",s);}

This is formated copy:
char s[1<<27];j;
main(i,n){
    for(fscanf(fopen("a.in","r"),"%d",&n),i=n*=2;--i;
        j+=i < n/2 ? i: n-i,
        s[i - 1] = 48 + j % 10,
        j /= 10
    );
    fprintf(fopen("a.out","w"),"%s\n",s);
}

The best solution of this problem has size 131 bytes, how?

Maybe I'm a bit slow, but it took me a long time just to get what the program should do. If the number is 3, you want to print 111*111, which is 12321. Right?

What's the source of this puzzle?

Why the restriction to such a few languages?

without changing your logic, you can save 9 characters by using fputs (instead of fprintf).
fputs(s,fopen("a.out","w"));

you can also save one character by not doubling n at first step, thus removing divide by two:
...,i=n*2;--i;
j+=i<n?i:2*n-i

I need write breakline(\n), but fputs no do this.

fputs works nice, 140 bytes

fputs doesn't add a newline (unlike puts).

You can save another character, by doing j/=10 after for - for(...)j/=10;
My best so far, 145 characters:
char s[1<<27];j;
main(i,n){
    for(fscanf(fopen("a.in","r"),"%d",&n),s[i=n*2-1]=10;i;
        j+=i<n?i:n*2-i,
        s[--i]=48+j%10
    )j/=10;
    fputs(s,fopen("a.out","w"));
}

C, 104 chars
(Assuming ugoren's comment is correct)
main(n,k){fscanf(fopen("a.in","r"),"%d",&n);for(k=1;--n;k=k*10+1);fprintf(fopen("a.out","w"),"%d",k*k);}

Note that I needed to compile it with -m32 on OSX to keep it from crashing.  Probably something to do with the implicit prototypes brought about by not including stdio.h.

N may be in range [1, 5*10^7]

@Maxim: then that should be part of the question.

C's implicit prototype assume functions return int. When they return a pointer, and it's larger than int, things go bad. 2. You can avoid initializing k if you switch it with n (and run the program without parameters). Saves 4 characters (if you also move fscanf into for. Or you can initialize k with fscanf's return value.

GolfScript 7
Another answer in an illegal language, for the same reason as the one invoked by Gareth.
~1`*~.*

Explanation:

takes a number as command line parameter
~ evaluates the number
1` pushes the '1' string on the stack
* multiplies the character '1' by the number specified as input (results in a string)
~ evaluates the string of 1s, thus storing the equivalent numeric value on the stack
.* squares the existing value

In order to get the expected output, the program should be called like this:
 more a.in | ruby golfscript.rb program.gs > a.out # :-)

J, 17 characters
Invalid answer and not really of any use to the OP, but I was bored and this occupied a few minutes.
*:10#.1$~".1!:1[1

1!:1[1 take input from the keyboard,
1$~ creates a list of 1s of the length specified by the input,
10#. converts to a base 10 number,
*: squares it.

Just for fun a 'dc' solution. It read/writes from stdin/stdout, because of its limitations
$ dc -e '?0sn[lnA*1+sn1-d0<x]dsxxlnd*p' <<< 3
12321

Jelly, 4 bytes (feedback welcome!)
1xV²

Try it online!
Repeat '1' a number of times equal to the input (x), concatenate and eValuate the result, and square it.
Old solution:
RŒBV

Try it online!
As per @ugoren's explanation. Make a range from 1 to N, then bounce it (mirror except the last element) with ŒB and use V to concatenate the digits.

This is wrong for inputs larger than 9.

Just wondering, why are you answering a bunch of questions that were last active in 2012?

@Nit Thank you! I missed that but found another more literal solution in the same amount of bytes. This one should work for larger inputs!

@JoKing Just trying to practice, and I figure might as well contribute to the site where other people can see. I'm just choosing questions I think that I can answer without considering the date. Hope it helps!

Wren, 55 bytes
Just do an invalid answer in case file manipulation doesn't work.
Fn.new{|x|Num.fromString("1"*Num.fromString(x)).pow(2)}

Try it online!
Explanation
Takes input as string:
Fn.new{|x|                                            } // New anonymous function
                             Num.fromString(x)          // Convert input into a number
          Num.fromString("1"*                 )         // Evaluate 1 with that number times
                                               .pow(2)  // Square the resulting value

Java, 198 chars
Saw you mention Java, thought I'd give it a try. This is the best I can get using the standard runtime:
import java.io.*;enum F{F;System s;{try{s.setOut(new PrintStream("a.out"));s.out.print((int)Math.pow(1/(9/Math.pow(10,new java.util.Scanner(new File("a.in")).nextInt())),2));}catch(Exception e){}}}

bash: 69 chars:
w=$(for i in $(seq 1 `<a.in`)
do
echo -n 1
done)
echo $((w**2))>a.out

a.out - really? :)
The only problem: invalid language.

C#, 172 chars
namespace System{class P{static void Main(){var b=Numerics.BigInteger.Parse(new String('1',int.Parse(IO.File.ReadAllText("a.in"))));IO.File.WriteAllText("a.out",b*b+"");}}}

Best I could do with a language with big integers.  Unless you're willing to add Python to the language list...

K, 13
Another invalid answer but what the hell.
{a*a:.:x#"1"}

Keg, -hr, 5 bytes
1⅍*ℤ²

Try it online!
Another illegal answer, but hey, as far as I know, there ain't any CGCC jail y'all can throw me into.

Japt, 5 bytes
Outputs a digit array.
ì1 ì²

Try it

C, 130 chars
char s[1<<27];main(i,n,j){for(read(open("a.in",0),s),n=atoi(s);j=j/10+n-abs(n-i);s[n*2-++i]=48+j%10);fputs(s,fopen("a.out","w"));}

Since you are actually willing to make the effort, would you please clarify your question? 3 people asked about some fine points; and got no answer. Also, you did some more clarifications in comments; they belong in the question itself.

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Write the prettiest bytebeat composition
Bytebeat is a style of music one can compose by writing a simple C program that's output is piped to aplay or /dev/dsp.
main(t){for(;;t++)putchar(((t<<1)^((t<<1)+(t>>7)&t>>12))|t>>(4-(1^7&(t>>19)))|t>>7);}

There is a good deal of information on the bytebeat site, a javascript implementation, and more demos and example compositions in this thread.
Very simple rules : Try to write a pretty sounding composition.  Most up votes wins since that's obviously subjective, although not that subjective considering the usual results.

Useful blog article

Are you holding this to strict bytebeat (i.e. no buffers)?

Why is it restricted to C?

There isn't afaik any intrinsic reason to restrict using buffers or other languages, but usually bytebeat means that particular C loop with the output defined by a formula.  I voted up Joey Adams answer even thought rand() is non-standard.

While I like this idea, the FAQ calls for an objective winning criteria (it's too easy to get trapped in calculations or ASCII art). Can we look for something better defined than "pretty"?

Also it should be tagged with one of [code-golf], [code-challenge], [king-of-the-hill], etc. I assume that you want [code-challenge] for this one.

Any suggestions?  I donno much music theory, but melodic or harmonic might be over specified.  How about "Write a bytebeat composition that doesn't sound too computer generated", not necessarily more objective, but specificity often yields objectivity in practice.  I doubt you want the up votes by March 1st precedent

Something like this maybe? It states that there is a correlation between  our enjoyment of music and how much it can be compressed. I doubt it is reliable in any way but it is an objective winning criteria

(Signed 16-bit little endian, 8000Hz mono (--format=S16_LE))
Music
Much better than before! (although it's quite long)
main(t){for(;;t++)putchar(((7&(((t>>17)+1)>>2)+((t>>10)&1+2*(t>>18&1))*(("23468643"[7&t>>12]-48)+(3&t>>11))+((3&t>>17)>0)*(3&t>>9)*!(1&t>>10)*(((2+t>>10&3)^(2+t>>11&3))))*t*"@06+"[3&t>>15]/32));}
(You can listen this at here)
I wrote this, but even I don't know how some part works, like >0 and (especially) the first 7&.
Change for loop to for(;!(t>>22);t++)... to listen it 'once'. I don't know whether it "loops" exactly the same way, however.
Melody (base of above music)
I love this melody I made (C-G-A-F ftw), but it's too 'plain'...
main(t){for(;;t++)putchar(((t>>10)&1)*(t*("23468643"[7&t>>12]-48)+t*(3&t>>11))*"@06+"[3&t>>15]/32);}
Simple music (which I made before)
main(t){for(;;t++)putchar(t*(3&t>>11)+(t&t>>11)*4*!((t>>11)%3));}

If you click the above bytebeat link, you'll see a sox command line to convert it to a .wav file, and an odd compressor command line.

+1 Amazing!  A few bits (e.g. 1:30 - 1:40) sound kind of "stuttering", but then again, much of the very charm of bytebeat is in these odd and unconventional rhythms and melodies, and the overall effect is excellent.  (Ps. I accidentally played this at 8 bits per sample, and I sounds surprisingly good that way too.  Sort of like playing a 45 rpm vinyl at 33.3 rpm.)

The ruler function in C minor:
#include <math.h>
#include <stdio.h>

#define PI 3.14159265358979323846

#define step(freq, n) ((freq) * pow(2, (n) / 12.0))
#define note(n)       step(440, n)
#define MIDDLE_C      note(-9)

int count_zeros(unsigned int n)
{
    int count = 0;
    for (; (n & 1) == 0; n >>= 1)
        count++;
    return count;
}

int minor_note(int note)
{
    int octave = note / 7;
    int scale[] = {0, 2, 3, 5, 7, 8, 10};

    note %= 7;
    if (note < 0) {
        note += 7;
        octave--;
    }

    return scale[note] + octave*12;
}

int main(void) {
    double t = 0.0;
    double freq = MIDDLE_C * 2;
    double step = PI * 2 / 8192;
    int n = 0;
    int i = 0;

    for (i = 1;; t += step, i++) {
        if (i == 1024) {
            i = 0;
            n++;
            freq = step(MIDDLE_C, minor_note(count_zeros(n)));
        }

        putchar(sin(t * freq) * 50.0 + 128.0);
    }

    return 0;
}

Nice melody, but to be a "composition" this IMO needs something more...

main(t){for(;;t+=(t%6)?1:2)putchar((((t<<t^(t>>8))|(t<<7))*((t<<t&(t>>12))|(t<<10))));}

Very classic bytebeat, if that's not an oxymoron.  +1 from me.

Emphasising "beat" over "byte":
#include<math.h>

double s(double,double);double r(double,double);double d(double);double f(double);

char bytebeat(int t){return (d(f(t/4000.)/3) + 1) * 63;}
double f(double t){
  double sn=s(1./2,t-1); sn*=(sn*sn);
  return 3*s(1./4,1/s(1,t))+3*s(4,1/sn)/2+s(4,1/(sn*sn*sn*sn*sn))/4
       +2*s(55+18.3*r(1./2,t),t)+s(110+s(5,t)/4000,t)*s(1,t)+s(220+110*r(1,t)+55*r(3,t),t)/5
       +s(880+440*r(1./2,t)-220*r(1,t)+110*r(2,t)+s(5,t)/4000,t)
       *(2+s(1760+438*r(3./2,t)-1234*r(2,t)+423*r(5,t),t))/9
       +s(s(1,t)+s(1./2,t)+s(1./4,t)+s(1./8,t),t)*s(s(1,t)+s(1./2,t)+s(1./4,t)+s(1./8,t)+1,t)
       +r(264+11*r(1./20,t),t)*s(1./20,t);
}
double s(double f,double t){return d(sin(f*3.14159265*(t+999)));}
double r(double f,double t){return s(f,t)<0;}
double d(double a){return tanh(a+a*a/4);}

main(t){for(;;++t)putchar(bytebeat(t));}

To be used at 8 kHz, uint8 mono. Sounds best over decently bass-capable loudspeakers.

main(){for(;;)putchar(rand());}

Sounds like the ocean ;-)

More like a really busy railway crossing to me. :)

Protip: if it sounds like a continuous tone, your RNG is broke.

easier way: $ cat /dev/urandom | aplay

@B1KMusic much more simple: aplay /dev/urandom

Combined melody and harmony:
r=3,
r=3,
m=(t*(t>>12|t>>13|t>>14|t>>15|t>>16|t>>17|t>>18))&63,

h= ((t&t>>7&t>>6)|t*5&t>>8-c^t*6&t>>9-c|t*7&t>>12-c^t*9&t>>11-c^t*11&t>>22^t*19&t>>20^t*14&t>>20|t*23&t>>15-c|t*12&t>>9|t*30&t>>30|t>>5|t>>4)-31, m|h