text:
Find the Smoothest Number
Your challenge is to find the smoothest number over a given range. In other words, find the number whose greatest prime factor is the smallest.
A smooth number is one whose largest prime factor is small. Numbers of this type are useful for the fast Fourier transform algorithm, cryptanalysis, and other applications.
For instance, over the range 5, 6, 7, 8, 9, 10, 8 is the smoothest number, because 8's greatest prime factor is 2, whereas all of the other numbers have a prime factor of 3 or greater.
Input: The input will be two positive integers, which define a range. The minimum allowable integer in the range is 2. You may choose whether the range is inclusive, exclusive, semi-exclusive, etc, as long as an arbitrary range can be specified within the bounds of your language. You may take the numbers via function input, stdin, command line argument, or any equivalent method for your language. No encoding extra information in the input.
Output: Return, print or equivalent one or more integers in the input range which are maximally smooth (minimal greatest factor). Returning multiple results is optional, but if you choose to do so the results must be clearly delimited. Native output format is fine for multiple results.
Please state in your answer how you are taking input and giving output.
Scoring: Code golf. Count by characters if written in ASCII, or 8*bytes/7 if not in ASCII.
Test cases:
Note: These are Python-style ranges, including the low end but not the high end. Change as appropriate to your program. Only one result is necessary.
smooth_range(5,11)
8
smooth_range(9,16)
9, 12
smooth_range(9,17)
16
smooth_range(157, 249)
162, 192, 216, 243
smooth_range(2001, 2014)
2002

Are ranges specified as (start,length) instead of (start,end) acceptable?

@CodesInChaos Sure. It's covered under the "or whatever" clause.

I don't see the point in penalizing non-ASCII answers. It would be simpler to just count bytes in all cases.

@nyuszika7h Ascii is significantly smaller than a byte - it only uses 7 bits. Therefore, I denote one character by 7 bits, and scale other languages accordingly. However, if the language is non-ASCII but can pack all of its characters into 7 bits, I will not apply the surcharge. See J/K vs. APL. tl;dr Bytes is simpler, but gives APL et. al. a subtle but unfair advantage.

@isaacg you're encouraging the creation of pseudo-languages using smaller character sets. if we score 7-bit character sets different from 8-bit character sets, someone can pack most modern languages into 6 bits (64 characters gets us A-Z, 0-9, a handful of whitespace, 20 punctuation, and a few to spare).

CJam - 13
q~,>{mfW=}$0=

Try it at http://cjam.aditsu.net/
Example input: 2001 2014
Example output: 2002
Explanation:
q~ reads and evaluates the input, pushing the 2 numbers on the stack (say min and max)
, makes an array [0 1 ... max-1]
> slices the array starting at min, resulting in [min ... max-1]
{…}$ sorts the array using the block to calculate the sorting key
mf gets an array with all the prime factors of a number, in order
W= gets the last element of the array (W=-1), thus obtaining the largest prime factor to be used as a sorting key
0= gets the first element of the (sorted) array

Awesome! How does it work?

Well, I guess that's that.

Amazing. What a compact answer! Very nice.

I need to add a factorize function to pyth.

As I would say in my games : gg

This language is wizardry.

This is as close to just pulling some HQ9+ s**t as it can be without becoming a loophole. Awesome!

ヽ༼ຈل͜ຈ༽ﾉ mfW someone solved it in 13 chars.

@Brobin  It's not wizardry, it's just highly evolved for a very specific purpose - solving code golfs.  Personally, I give more credit to a chef who can julienne with an 8" knife than some bloke on TV with a one-slap julienne machine.  At least the knife has broader practical utility...

@J... I basically agree with you, but I created CJam partly as a reaction to GolfScript stealing the show every time while my 200+ char java answers barely got 1 or 2 upvotes

@aditsu It's still just a collection of one-char macros wrapped around a huge pile of code made to solve the CG of the day.  Magic unicorn points will be the ruination of us all...

On the other hand, most languages are "wrappers" to serve a certain purpose. No one wants to write assembler/machine code. It's a blurry line to walk on.

@IngoBürk I... I like to write machine code ;D

@J... My point still stands :)

So when do we start submitting code golf answers via a single character that just maps to the real answer which is hard coded into the language?

@CoryKlein never - it's a standard loophole to be avoided.

@EricTressler No one's done APL yet, so there's still a chance...

Looks like a mix of Forth and APL... :-)

Regex (.NET PCRE flavour), 183 129 bytes
Don't try this at home!
This is not really a contender for the win. But Eric Tressler suggested solving this problem with nothing but a regex, and I couldn't resist giving it a go. This might be is possible in PCRE as well (and even shorter, see below), but I chose .NET because my solution needs arbitrary-length lookbehinds. Here we go:
(?<=^(1+),.*)(?=\1)(?=((11+)(?=.*(?=\3$)(?!(11+?)\4+$))(?=\3+$)|(?!(11+)\5+$)1+))(?!.+(?=\1)(?:(?!\2)|(?=((11+)(?=.*(?=\7$)(?!(11+?)\8+$))(?=\7+$)|(?!(11+)\9+$)1+)).*(?=\2$)(?=\6)))1+

The input is encoded as an inclusive comma-separated range, where both numbers are given in unary notation using 1s. The match will be the trailing S 1s where S is the smoothest number in the range. Ties are broken in favour of the smallest number.
So the second example from the question would be the following string (match underlined)
111111111,1111111111111111
                 =========

It is based on the (by now rather well-known) prime-checking regex, variations of which are embedded in there a whopping 6 times.
Here is a version using free-spacing and comments for those who want to know what's going on.
# Note that the beginning of the match we're looking for is somewhere
# in the second part of the input.
(?<=^(1+),.*)          # Pick up the minimum range MIN in group 1
(?=\1)                 # Make sure there are at least MIN 1s ahead

                       # Now there will be N 1s ahead of the cursor
                       # where MIN <= N <= MAX.

(?=(                   # Find the largest prime factor of this number
                       # store it in group 2.
  (11+)                # Capture a potential prime factor P in group 3
  (?=                  # Check that it's prime
    .*(?=\3$)          # Move to a position where there are exactly
                       # P 1s ahead
    (?!(11+?)\4+$)     # Check that the remaining 1s are not composite
  )
  (?=\3+$)             # Now check that P is a divisor of N.
|                      # This does not work for prime N, so we need a
                       # separate check
  (?!(11+)\5+$)        # Make sure that N is prime.
  1+                   # Match N
))

(?!                    # Now we need to make sure that here is not
                       # another (smaller) number M with a smaller
                       # largest prime factor

  .+                   # Backtrack through all remaining positions
  (?=\1)               # Make sure there are still MIN 1s ahead

  (?:
    (?!\2)             # If M is itself less than P we fail
                       # unconditionally.
  |                    # Else we compare the largest prime factors.
    (?=(               # This is the same as above, but it puts the
                       # prime factor Q in group 6.
      (11+)
      (?=
        .*(?=\7$)
        (?!(11+?)\8+$)
      )
      (?=\7+$)
    |
      (?!(11+)\9+$)
      1+
    ))
    .*(?=\2$)          # Move to a position where there are exactly
                       # P 1s ahead
    (?=\6)             # Try to still match Q (which means that Q is
                       # less than P)
  )
)
1+                     # Grab all digits for the match

You can test it online over here. Don't try too large inputs though, I make no guarantees about the performance of this monster.
Edit:
I ended up porting this to PCRE (which only requires two steps), and shortening the regex by almost a third. Here is the new version:
^(1+),.*?\K(?=\1)(?=((11+)(?=.*(?=\3$)(?!(11+?)\4+$))(?=\3+$)|(?!(11+)\5+$)1+))(?!.+(?=\1)(?:(?!\2)|(?=((?2))).*(?=\2$)(?=\6)))1+

This is essentially the same, with two changes:

PCRE does not support arbitrary-length lookbehind (which I used to get the MIN into group 1). However, PCRE does support \K which resets the beginning of the match to the current cursor position. Hence (?<=^(1+),.*) becomes ^(1+),.*?\K, which already saves two bytes.
The real savings come from PCRE's recursion feature. I'm not actually using recursion, but you can use (?n) to match group n again, similar to a subroutine call. Since the original regex contained the code for finding a number's largest prime factor twice, I was able to replace the whole bulk of the second one with a simple (?2).

Holy mother of god

You write “This does not work for prime N, so we need a separate check”. However, could you not make it work for prime N simply by changing (=\3+$) to (=\3*$) (and also (=\7+$) to (=\7*$)) and then save yourself the extra primality check? This would save 32 characters.

@Timwi I need to check that the largest prime factor (group 3 or 7) is actually prime. This requires that there is another copy of the factor after first capturing it, which wouldn't be the case for primes. While I work around that in .NET by putting a lookbehind somewhere in there such that I could move back a bit for the check, this wouldn't be possible in the shorter PCRE version due to the lack of variable-length lookbehinds. It probably is possible to shorten that bit, but I don't think just changing + to * works.

@MartinEnder Hi! I imagine you're long since over this challenge, but I just surfed in, saw a regex solution, and couldn't help but totally ignore your warning at the top of this post :) I find it hard to golf other people's code, so after looking at your regex and getting confused, I attempted it from scratch and came up with this:
(.*),.*?\K(?=(..+)((?=((?(R)\6|\2))*$).*(?=\4$)(?!(..+)\5+$)))(?!.+(?=\1)(?=(..+)(?3)).*(?!\2)\6).+
99 bytes in PCRE. Also, I've come across a lot of your work on this site and I'm a big fan :D Looking forward to a regex battle in the future!

I was playing code golf with that comment so I'll just put the addendum here: you can knock off 4b by taking \4$ out of the lookahead and sticking it after the negative lookahead, but this severely impacts performance (every subgroup of digits <= \4 is checked for compositeness rather than just \4 itself) and fails on longer inputs.

@jaytea Sorry for taking forever to get back to you on this. Since you wrote the thing from scratch, I think you should post a separate answer. That's a great score and you deserve the credit for it. :)

Very kind of you to say, but I feel it's too similar in the context of a challenge that wasn't actually supposed to be solved with regex! Haha.

I tackled this myself and came up with a 66 byte PCRE solution: ((.+).*),(?!.*(?=\1)(((?=(..+)(\5+$))\6)*)(?!\2)).*(?=\1)\K(?3)\2$

@jaytea Ran your regex through an automated test and it fails on (and only on) singleton ranges [P,P] where P is any prime number, returning P-1 instead of P – and on [2,2], [2,3], and [3,3], it returns a non-match. Other than that it passes perfectly. The after-the-negative-lookahead length optimization results in a 10.3× slowdown in my engine when tested on all ranges [A,B] where A≤B and A+B ≤ 255, and a 4.38× slowdown for A+B ≤ 127.

Regex (Perl / PCRE), 66 65 (64) bytes
Inspired by seeing that both Martin Ender and jaytea, two regex geniuses, wrote regex solutions to this code golf, I wrote my own from scratch. The famous prime-checking regex does not appear anywhere in my solution.
Do not read this if you don't want some unary regex magic spoiled for you. If you do want to take a shot at figuring out this magic yourself, I highly recommend starting by solving some problems in ECMAScript regex:

Match prime numbers (if you aren't already familiar with doing this in regex)
Match powers of 2 (if you haven't already done so). Or just work your way through Regex Golf, which includes Prime and Powers. Make sure to do both the Classic and Teukon problem sets.

 Find the shortest way to match powers of N where N is some constant (i.e. specified in the regex, not the input) which can be composite (but is not required to be). For example, match powers of 6.

 Find a way of matching Nth powers, where N is some constant >=2. For example, match perfect squares. (For a warmup, match prime powers.)

 Match correct multiplication statements. Match triangular numbers.

 Match Fibonacci numbers (if you're as crazy as I am), or if you want to stick to something shorter, match correct statements of exponentiation (for a warmup, return as a match the logarithm in base 2 of a power of 2 – bonus, do the same for any number, rounding it however you like), or factorial numbers (for a warmup, match primorial numbers).

 Match abundant numbers (if you're as crazy as I am)

 Calculate an irrational number to requested precision (e.g. divide the input by the square root of 2, returning the rounded result as a match)

(The regex engine I wrote may be of help, as it is very fast at unary math regexes and includes a unary numerical mode which can test ranges of natural numbers (but also has a strings mode which can evaluate non-unary regexes, or unary with delimiters). By default it is ECMAScript compatible, but has optional extensions (which can selectively add subsets of PCRE, or even molecular lookahead, something that no other regex engine has).)
Otherwise, read on, and also read this GitHub Gist (warning, many spoilers) which chronicles the journey of pushing ECMAScript regex to tackle natural number functions of increasing difficulty (starting with teukon's set of puzzles, not all of them mathematical, which sparked this journey).
As with the other regex solutions to this problem, the input is given as two numbers in bijective unary, separated by a comma, representing an inclusive range. Only one number is returned. The regex could be modified to return all of the numbers that share the same smallest largest prime factor, as separate matches, but that would require variable-length lookbehind and either putting \K in a lookahead or returning the result as a capture instead of a match.
The technique used here of repeated implicit division by smallest prime factor is identical to that used in the Match strings whose length is a fourth power answer I posted a while back.
With no further ado:
((.+).*),(?!.*(?=\1)((?=(..+)(\4+$))\5)*(?!\2)).*(?=\1)\K(?3)*\2$

Try it online! - Perl
Try it online! - PCRE
Try it on regex101
And the free-spacing version, with comments:
                        # No ^ anchor needed, because this algorithm always returns a
                        # match for valid input (in which the first number is less than
                        # or equal to the second number), and even in /g mode only one
                        # match can be returned. You can add an anchor to make it reject
                        # invalid ranges.

((.+).*),               # \1 = low end of range; \2 = conjectured number that is the
                        # smallest number in the set of the largest prime factor of each
                        # number in the range; note, it is only in subsequent tests that
                        # this is implicitly confined to being prime.
                        # We shall do the rest of our work inside the "high end of range"
                        # number.

(?!                     # Assert that there is no number in the range whose largest prime
                        # factor is smaller than \2.
  .*(?=\1)              # Cycle tail through all numbers in the range, starting with \1.

  # Subroutine call (?3) - defines one loop iteration, and needs to be called as (?3)*
  # Finds the largest prime factor of tail, and leaves it in tail. It will both be
  # evaluated here as-is, and later as a subroutine call. Here, it's followed by an
  # assertion that tail is less than something; if this fails to match, the regex
  # engine will try to backtrack, but that will never result in a match because
  # backtracking will only make tail larger.
  (                     # Repeatedly divide tail by its smallest prime factor, leaving
                        # only the largest prime factor at the end.

    (?=(..+)(\4+$))     # \5 = tool to make tail = \4 = largest nontrivial factor of
                        # current tail, which is implicitly the result of dividing it
                        # by its smallest prime factor.
    \5                  # tail = \4
  )*
  (?!\2)                # matches iff tail < \ 2
)

# At this point, \2 is guaranteed to be less than or equal to the smallest number in the
# set containing the largest prime factor of each of the numbers in the inputted range.
# The first time the regex engine reaches this point, \2 will be equal to the smallest
# number in that set, but if it backtracks, \2 will become smaller.

# now, pick a number in the range whose largest prime factor is \2
.*(?=\1)                # Cycle tail through all numbers in the range, starting with \1.
\K                      # Set us up to return tail as the match.
(?3)*                   # tail = largest prime factor of tail
\2$                     # Match iff tail == \2, then return the number whose largest
                        # prime factor is \2 as the match. If this fails to match, the
                        # regex engine will try to backtrack, but that will never result
                        # in a match, because backtracking makes tail a composite number
                        # that is larger than the largest prime factor of the currently
                        # marked return value, which makes it larger than any value \2
                        # can have.

Note that ((.+).*) can be changed to ((.+)+), dropping the size by 1 byte (from 65 to 64 bytes) with no loss of correct functionality – but the regex exponentially explodes in  slowness:
((.+)+),(?!.*(?=\1)((?=(..+)(\4+$))\5)*(?!\2)).*(?=\1)\K(?3)*\2$

Try it online! - Perl
Try it online! - PCRE
Regex (ECMAScript), 80 (79) bytes
The algorithm can be easily ported to ECMAScript by replacing the subroutine call with a copy of the subroutine, and returning the match as capture group \6 instead of using \K. The result is 80 bytes in length:
((x+)x*),(?!.*(?=\1)((?=(xx+)(\4+$))\5)*(?!\2)).*(?=\1)(((?=(xx+)(\8+$))\9)*\2$)

Try it online! - 80 byte version
Try it online! - 79 byte exponential-slowdown  version (amazingly, this can handle all the test cases in 49 seconds)

Python 2, 95
i=input()
for a in range(*i):
 s=a;p=2
 while~-a:b=a%p<1;p+=1-b;a/=p**b
 if p<i:i=p;j=s
print j

Finds the smoothness of the the numbers by trial division until the number is 1. i stores the smallest smoothness so far, j stores the number that gave that smoothness.
Thanks to @xnor for the golfs.

That if/else has got to be shortenable. My first thought is b=a%p<1;p+=1-b;a/=p**b. Or an exec that runs one of the two in an interleaved string. Also, maybe while~-a works.

isaacg — I love this answer! What a brilliant way you found to search for the largest prime factor! I have updated my answer to borrow your method, with credit to you on the method.

Great solution! Using s,p=a,2, i,j=p,s, @xnor's ideas, removing redundant indentation and putting the while block into one line yields 95 characters. Not sure how you came up with 98...

this code is full of emoticons, :)

@Falko those two changes save no characters. 7->7.

@isaacg: Oh, you're totally right!

Mathematica, 61 45 39 characters
Range@##~MinimalBy~Last@*FactorInteger&

Very straightforward implementation of the spec as an unnamed function.

Get the range (inclusive).
Factor all integers.
Find the minimum, sorted by largest prime factor.

J, 22 20 19 chars
({.@/:{:@q:)@(}.i.)

E.g.
   2001 ({.@/: {:@q:)@(}. i.) 2014
2002

(Functions taking two arguments are infix in J.)

I also had a crack at it, didn't get it as short as this answer. Still: (#~ (= <./)@:(i:"1&1)@:*@:(_&q:))@:([ + i.@-~)

Here {: is the same as >./ and saves 1 byte.

@randomra You're right—good call!

Beautiful.  TIO if you'd like to add it: Try it online!

Haskell, 96 94 93 86 80 characters
x%y|x<2=y|mod x y<1=div x y%y|0<1=x%(y+1)
a#b=snd$minimum$map(\x->(x%2,x))[a..b]

usage via GHCi (a Haskell shell):
>5 # 9
8
>9 # 15
9

EDIT: now a much simpler algorithm.
this solution includes both numbers in the range (so 8 # 9 and 7 # 8 are both 8)
explanation:
the (%) function takes two parameters, x and y. when y is 2, the function returns the smoothness of x.
the algorithm from here is simple - get the combined list of all smoothnesses of numbers in the input with each smoothness storing a reference to it's original number, sort then to get the smallest, and return it's referenced number.

here is an ungolfed javascript version with the same algorithm:
function smoothness(n,p)
{
    p = p || 2
    if (x == 1)
        return p
    if (x % p == 0)
        return smoothness(x/p, p)
    else
        return smoothness(x,p+1);
}
function smoothnessRange(a, b)
{
    var minSmoothness = smoothness(a);
    var min=a;
    for(var i=a+1;i <= b;i++)
        if(minSmoothness > smoothness(i))
        {
            minSmoothness = smoothness(i)
            min = i
        }
    return min;
}

Would it be possible to alias minimum to something shorter? That looks like it would save some characters.

I tried it, but because of the monomorphism restriction it actually costs one character

You can't just do m=minimum? Haskell is still a mystery.

No, because of the monomorphism restriction. It is something to do with type classes

@isaacg To bypass the monomorphism restriction one would have to write m l=minimum l

I was going to post a Haskell solution, until I saw yours which beats even my incomplete version... +1

Bash+coreutils, 56 bytes
seq $@|factor|sed 's/:.* / /'|sort -nk2|sed '1s/ .*//;q'

Input is from from exactly two command-line arguments (Thanks @nyuszika7h !!!).  Output is a singular result printed to STDOUT.

seq provides the range of numbers, one per line, from the command-line arguments.
factor reads those numbers and outputs each number followed by a colon and the sorted list of prime factors of that number.  So the largest prime factor is at the end of each line.
The first sed removes the colon and all but the last/largest prime factor, so leaves a list of each number (column 1) and its largest prime factor (column 2).
sort numerically in increasing order by the column 2.
The final sed matches line 1 (number whose largest prime factor is the smallest in the list), removes everything including and after the first space, then quits.  sed automatically prints the result of this substitution before quitting.

Output:
$ ./smooth.sh 9 15
12
$ ./smooth.sh 9 16
16
$ ./smooth.sh 157 249
162
$ ./smooth.sh 2001 2014
2002
$

Note ranges in this context are inclusive of both endpoints.

seq $@ is 3 bytes shorter, if you can assume that there are only two arguments.

@nyuszika7h Nice idea - thanks!

Lua - 166 chars
I don'tdidn't have (yet!) enough reputation to comment on AndoDaan's solution, but here are some improvements on his code
a,b=io.read("*n","*n")s=b for i=a,b do f={}n=i d=2 while n>1 do while n%d<1 do f[#f+1]=d n=n/d end d=d+1 end p=math.max(unpack(f))if p<s then s=p c=i end end print(c)

Changes :

The n%d==0 by n%d<1 which is equivalent in this case
Removed a space
Replaced table.insert(f,d) by f[#f+1]=d  (#f is the number of elements of f)

Ah, glad I glanced here. Ah, the first two i should have checked and caught, but your third improvement is new to me (I mean just different than what I'm used to). That's going to help me a lot here and over at golf.shinh.com. Thanks!

Python 2, 67
f=lambda R,F=1,i=2:[n for n in range(*R)if F**n%n<1]or f(R,F*i,i+1)

Thinking about another golf gave me an idea for a new algorithm to check smoothness, hence the late answer.
The prime factorization of the factorial i! includes exactly the primes at most i. So, if n is a product of distinct primes, its smoothness (largest prime factor) is the smallest i for which n is a divisor of i!. To account for repeated prime factors in n, we can instead use a sufficiently high power of i!. In particular, (i!)**n suffices.
The code tries increasing factorials F=i!, updated recursively. We filter for the divisors of F in the input range, and output them if there are any, and otherwise move on to (i+1)!.
Test case:
>> f([157, 249])
[162, 192, 216, 243]

C,  149   95
Edited answer:
I cannot claim credit for this solution. This updated answer borrows the beautiful method used by isaacg in his Python solution. I wanted to see if it was possible to write it in C as a nested for/while loop with no curly braces, and it is!
R(a,b,n,q,p,m){for(;a<b;m=p<q?a:m,q=p<q?p:q,n=++a,p=2)while(n>1)if(n%p)p++;else n/=p;return m;}

Explanation:

Function R(a,b,n,q,p,m) scans the range a to b-1 and returns the first smoothest number found. Invocation requires adherence to the following form: R(a,b,a,b,2,0) so that variables inside the function are effectively initialized as follows: n=a;q=b;p=2;m=0;.

Original answer:
This was my original answer...
P(n,f,p){for(;++f<n;)p=p&&n%f;return p;}
G(n,f){for(;--f>1;)if(n%f==0&&P(f,1,1))return f;}
R(a,b,p,n){for(;++p;)for(n=a;n<b;n++)if(G(n,n)==p)return n;}

Explanation:

Function P(n,f,p) tests value n for primality and returns true (nonzero) if n is prime or false (zero) if n is non-prime. f and p must both be passed as 1.
Function G(n,f) returns the greatest prime factor of n. f must be passed as n.
Function R(a,b,p,n) scans the range a to b-1 and returns the first smoothest number found. p must be passed as 1. n can be any value.

Test driver:
test(a,b){printf("smooth_range(%d, %d)\n%d\n",a,b,S(a,b,1,0));}
main(){test(5,11);test(9,16);test(9,17);test(157,249);test(2001,2014);}

Output:
smooth_range(5, 11)
8
smooth_range(9, 16)
9
smooth_range(9, 17)
16
smooth_range(157, 249)
162
smooth_range(2001, 2014)
2002

I would argue this falls foul of "No encoding extra information in the input" clause.

@Alchymist — You may be right...but I don't think there's any actual extra information in the pseudo-arguments. At least not any information that is any kind of clue as to the answer.

Haskell - 120
import Data.List
import Data.Ord
x!y=(minimumBy(comparing(%2)))[x..y]
x%y|x<y=y|x`mod`y==0=(x`div`y)%y|otherwise=x%(y+1)

Example usage:
> 5 ! 10
8
> 9 ! 15
9
> 9 ! 16
16
> 157 ! 248
162
> 2001 ! 2013
2002

Couldn't you use <1 instead of ==0?

Yeah, that would be a nice improvement. There's lots of little things that could be done better. Fortunately this answer already does all of them: https://codegolf.stackexchange.com/a/36461

Q, 91 characters K, 78 characters
{(x+{where x=min x}{(-2#{x div 2+(where 0=x mod 2_til x)@0}\[{x>0};x])@0}'[(x)_til y+1])@0}

k would probably shave a dozen characters
edit:
indeed, treating the upper bound as non inclusive this time
{*:x+{&:x=min x}{*:-2#{6h$x%2+*:&:x={y*6h$x%y}[x]'[2_!x]}\[{x>0};x]}'[(x)_!y]}

Note: This answer is not allowable.
This answer uses multiple features of Pyth added after the challenge was asked.
I added another new feature, calling unary range on a 2 element tuple, which shortens the solution by two characters, to this:
Pyth, 7
hoePNUQ

Input is now taken comma separated. The rest is the same.

This answer uses a feature of Pyth that was added after this question was asked, specifically after seeing @aditsu's wonderful CJam solution. That being said, I wanted to demonstrate what adding that feature has made possible. The feature is P, which is an arity-1 function which on integer input returns a list of all prime factors of the input, sorted smallest to largest.
Pyth, 9
hoePNrQvw

Uses Python-style ranges, newline separated on STDIN. Outputs smallest solution to STDOUT.
Explanation:
      Q = eval(input())                         Implicit, because Q is present.
h     head(                                     First element of
 o         order_by(                            Sort, using lambda expression as key.
                    lambda N:                   Implicit in o
  e                          end(               Last element of
   PN                            pfact(N)),     List containing all prime factors of N.
  r                 range(                      Python-style range, lower inc, upper exc.
   Q                      Q,                    A variable, initialized as shown above.
   vw                     eval(input()))))      The second entry of the range, same way.

Tests:
$ newline='
'

$ echo "9${newline}16" | ./pyth.py -c 'hoePNrQvw'
9

$ echo "9${newline}17" | ./pyth.py -c 'hoePNrQvw'
16

$ echo "157${newline}249" | ./pyth.py -c 'hoePNrQvw'
162

$ echo "2001${newline}2014" | ./pyth.py -c 'hoePNrQvw'
2002

@MartinBüttner Yep, as suggested by his comment on the CJam solution

@MartinBüttner Yeah, P, is the new feature. I'll put that in the answer.

Allowable or not, not only I like it, but I also think that those short "macros" are readable if you pay attention - they convert to straightforward Python, after all. Something has to be said for a golf language that is good for golf but not necessarily obfuscating.

@KubaOber Thanks, Kuba. That's always been my intention in writing Pyth, to make it as golfed and as readable as possible. I'm glad it's working.

Lua - 176 characters
a,b=io.read("*n","*n")s=b for i=a,b do f={}n=i d=2 while n>1 do while n%d==0 do table.insert(f, d)n=n/d end d=d+1 end p=math.max(unpack(f))if p<s then s=p c=i end end print(c)

I really should stop golfing in Lua. There's no point.

IMHO, code golfing is like boxing: there are weight-classes. A given language may not win outright, but it is fun and illuminating to golf within that class/language.

Clojure - 173 170 chars
I'm a Clojure newbie. Golfed:
(defn g[x,d](if(and(= 0(mod x d))(.isProbablePrime(biginteger d) 1))d 0))(defn f[i](apply max-key(partial g i)(range 2(inc i))))(defn s[a,b](first(sort-by f(range a b))))

Sample runs:
Ranges include low-end, exclude high-end: [a,b)
Only prints one of the smoothest numbers, if multiple occur.
(println (s 5 11))
(println (s 9 16))
(println (s 9 17))
(println (s 157, 249))
(println (s 2001, 2014))

yields:
bash$ java -jar clojure-1.6.0.jar range.clj
8
9
16
192
2002

Ungolfed:
(defn g [x,d] (if (and (= 0(mod x d)) (.isProbablePrime (biginteger d) 1)) d 0))
(defn f [i] (apply max-key (partial g i) (range 2 (inc i))))
(defn s [a,b] (first (sort-by f (range a b))))

A range that includes the low end and excludes the high end is usually written [a,b).

yep, thanks for the note

C# LINQ: 317 303 289 262
using System.Linq;class P{static void Main(string[]a){System.Console.Write(Enumerable.Range(int.Parse(a[0]),int.Parse(a[1])).Select(i=>new{i,F=F(i)}).Aggregate((i,j)=>i.F<j.F?i:j).i);}static int F(int a){int b=1;for(;a>1;)if(a%++b<1)while(a%b<1)a/=b;return b;}}

Ungolfed:
using System.Linq;

class P
{
  static void Main(string[]a)
  {
    System.Console.Write(
      Enumerable.Range(int.Parse(a[0]), int.Parse(a[1])) //create an enumerable of numbers containing our range (start, length)
        .Select(i => new { i, F = F(i) }) //make a sort of key value pair, with the key (i) being the number in question and the value (F) being the lowest prime factor
        .Aggregate((i, j) => i.F < j.F ? i : j).i); //somehow sort the array, I'm still not entirely sure how this works
  }
  static int F(int a)
  {
    int b=1;
    for(;a>1;)
      if(a%++b<1)
        while(a%b<1)
          a/=b;
    return b;
  }
}

It takes in the start and the length from the command line and will return the largest smooth number.
I used answers from here and here to make my answer.
Thanks to VisualMelon for tweaking it and shaving 12 bytes off! I also got rid of the braces in the if saving 2 bytes, and CodeInChaos pointed out some obvious stuff I missed (thanks again).

Couple of general purpose small things, you can save 4 bytes in F by defining int b next to m. In a couple of places you perform the comparison a%b==0, and  a and b are always positive you can cut a byte for each by checking if it's less than 1 a%b<1. You can also save a byte by incrementing b in the if's condition a%++b<0 rather than in the for by initializing it to 1. I also think in this case it's cheaper to just fully qualify System.Console.WriteLine and avoid the namespace clause.

@VisualMelon Thanks, updated with your ideas :)

The m=...:m; thingy falls outside the while loop. Therefore, you can drop the m=0, and replace return m; with return m=b>m?b:m;. Then, you can drop the m=...:m; entirely.

It may sound weird, but this is - to me- less redable than CJam and J. I guess C# was designed to be verbose, and attempts at making it less so make it unreadable? Hmm....

No I agree, LINQ looks like a demon when you just see it here and there and never actually play with it yourself. Once you grasp it though, it's really cool :) With that said, I still don't fully understand how Aggregate works, I just tried it after seeing it in another answer to get to my new object instead of just one field within it, and it just happened to work perfectly :)

OP clarified that -int.Parse(a[0]) is not required -16 2) Why namespace instead of using? -5 3) WriteLine to Write-4 4) TurnFinto an instance method -1 5) replaceI = ibyi` -2

Didn't see that, thanks  2) Good point. 3) will change 4) How would an instance method help? 5) will change.

Ruby, 65 62
require'prime'
s=->a,b{(a..b).min_by{|x|x.prime_division[-1]}}

With apologies to https://codegolf.stackexchange.com/a/36484/6828, this is the golfed (and slightly simplified) version of that. Uses an inclusive range since it's a character shorter.
1.9.3-p327 :004 > s[157,249]
 => 192
1.9.3-p327 :005 > s[5,11]
 => 8
1.9.3-p327 :006 > s[9,15]
 => 12
1.9.3-p327 :007 > s[9,16]
 => 16

And thanks to YenTheFirst for saving three characters.

You can actually get away without the [0], since array comparison will prioritize the first element anyway. This will give different, but still correct, results.

R, 83
library(gmp)
n=a:b
n[which.min(lapply(lapply(lapply(n,factorize),max),as.numeric))]

where the bottom of the input range is assigned to a and the top (inclusive) is assigned to b.
gmp is a package that is available on CRAN. It felt dirty until I saw that absurd mf function in CJam. Install by typing install.packages("gmp") in the console.

If you're using lapply 3 times you might want to alias it (i. e. l=lapply and then use l(...). Similarly since factorize is the only function you use from package gmp you can use gmp::factorize instead of loading the library and then using factorize. Your code thus would become l=lapply;n=a:b;n[which.min(l(l(l(n,gmp::factorize),max),as.numeric))] which is 69 bytes.

PowerShell - 85
($args[0]..$args[1]|sort{$d=2
while($_-gt1){while(!($_%$d)){$m=$d;$_/=$d}$d++}$m})[0]

This will sort a range of numbers (inclusive) based on each number's max prime factor. It returns the lowest sorted element.
> smooth 5 10
8
> smooth 9 15
12
> smooth 9 16
16
> smooth 157 248
243
> smooth 2001 2013
2002

J - 16 char
Using the (start, length) style of range, as allowed by the comments.
(0{+/:{:@q:@+)i.

To be used as a dyadic verb: left argument is start, right is length.
   5 (+)i. 6              NB. range
5 6 7 8 9 10
   5 (q:@+)i. 6           NB. prime factorizations
5 0 0
2 3 0
7 0 0
2 2 2
3 3 0
2 5 0
   5 ({:@q:@+)i. 6        NB. largest prime factors
5 3 7 2 3 5
   5 (+/:{:@q:@+)i. 6     NB. sort range by smallest factors
8 6 9 5 10 7
   5 (0{+/:{:@q:@+)i. 6   NB. take first entry
8
   f=:(0{+/:{:@q:@+)i.    NB. can also be named
   2001 f 13
2002

A (start, end) solution is +2 chars, and excludes the end; including the end is +2 more. But on the bright side, it looks rather nice since we match up all the {braces}.
(0{}./:{:@q:@}.)i.    NB. excluding
(0{}./:{:@q:@}.)1+i.  NB. including

Seriously, 8*14/7 = 16 (non-competitive)
,x;`yM`M;m@í@E

Seriously was created after this challenge, but I wanted to post this answer because it exemplifies the type of challenges Seriously is good at.
Try it online!
Explanation:
,x;`yM`M;m@í@E
,x;             make two copies of range(a,b) (a,b = input())
   `  `M;       make two copies of the result of the map:
    yM            push maximum prime factor
         m@í    push index of minimum element from prime factors
            @E  push element from range with given index

Pyth, 7 bytes
.mePbrF

Try it here!
Outputs all smooth integers in the range \$[a, b)\$. For the smooth integers in \$[a, b]\$, just use } in place of r.
.mePbrF – Full program with arguments a and b.
     rF – Fold by half-inclusive range. Yields the integers in [a, b).
.m      – Values b in that list which give minimal results when applied f.
  ePb   – function / block f.
   Pb   – Prime factors of b.
  e     – Last element. This is guaranteed to yield the largest, as they're sorted.

Whispers v2, 183 bytes
> Input
> Input
>> 1…2
>> ∤L
>> L’
>> Each 4 3
>> Select∧ 5 L
>> Each 7 6
>> Lⁿ10
> -1
>> Each 9 8
>> L‖R
>> Each 12 11 3
>> 13ᴺ
>> Each 9 14
> 0
>> 15ⁿ16
>> Output 17

Try it online!
Aside from revamping the algorithm, the only real golfing opportunity can be found on lines 9 and 10, but swapping them. When they're the other way round, the code is 1 byte longer, due to the repeated use of 9 or 10.
The structure tree for this program is:

Red represents nilad lines, green represents function arguments. Arrows from \$a \to b\$ show the use of line \$a\$ as an argument for line \$b\$.
How it works.
We start at lines 1, 2 and 3. The first two simply take and store the inputs \$\alpha\$ and \$\beta\$ on lines 1 and 2 respectively. There two values are then passed to line 3, 1…2, which form the range
$$R := [\alpha, \alpha+1, ..., \beta-1, \beta]$$
As you can see from the tree above, \$R\$ is used in two places: line 6 and line 13. As line 6 eventually leads to line 13, we'll take the path down 6.
Line 6 is an Each statement, that maps a function (the first line reference) over an array (the second line reference). Here, the function is defined on line 4 as \$f(x) = \{i \: | \: (i | x), (i \le x), i \in \mathbb{N}\}\$ i.e. the array of \$x\$'s divisors. The array is \$R\$, so line 6 iterates over \$R\$, returning the divisors of each integer, forming a new array
$$D := [f(\alpha), f(\alpha+1), ..., f(\beta-1), f(\beta)]$$
We then get more complicated as we skip down to line 8. Line 8 is also an Each statement, but its function argument, line 7 is split over two lines, 7 and 5:
>> L’
>> Select∧ 5 L

Mathematically, this is the function \$g(A) = \{i \: | \: (i \in \mathbb{P}), (i \in A)\}\$, that takes a set \$A\$ and returns all the primes in \$A\$. Line 8 is iterating over \$D\$, essentially filtering all composite numbers from each subarray in \$D\$, to form
$$A := [g(f(\alpha)), g(f(\alpha+1)), ..., g(f(\beta-1)), g(f(\beta))]$$
Then, we encounter yet another Each statement on line 11, which iterates line 9 over \$A\$. Line 9 takes an array and returns the final element of that array. As \$g(A)\$ returns the array sorted, this is equivalent to return the largest value in that array. At this point, we remember that \$g(f(x))\$ returns the list of prime factors of \$x\$, so line 9 maps each \$x\$ to its largest prime factor, returning
$$B := [\max(g(f(\alpha))), \max(g(f(\alpha+1))), ..., \max(g(f(\beta-1))), \max(g(f(\beta)))]$$
Once we have \$B\$, we now have an array we can sort \$R\$ by, e.g. we sort each value \$x\$ in \$R\$ by the resulting value of \$\max(g(f(x)))\$. However, we do not have a sort-by command in Whispers, only the simple Python sort(list). Luckily, due to how sort sorts lists of lists, we can concatenate each \$x\$ with \$\max(g(f(x))\$ and sort by the first element, what Python does naturally.
Lines 12 and 13 perform this concatenation, by iterating a concatenate function (line 12) over \$B\$ and \$R\$. This forms an array of pairs of numbers, in the form \$[\max(g(f(x))), x]\$. Next, we sort this array on line 14, which, due to the way Python compares lists, places the numbers with the lowest largest prime factor towards the end.
Almost finished. The only things left to do are to extract \$R\$, sorted by \$B\$ (we'll call this array \$R_B\$. This is done simply by taking the last element of each subarray (line 9 already does this for us, so we simply need Each 9 14 on line 15, rather than defining a new function). Once that's done, we simply take the first element in \$R_B\$, which will be (one of) the number with the lowest largest prime factor i.e. the smoothest number.

Brachylog, 5 bytes
⟦₃ḋᵒh

Try it online!
Takes input as a list of two (or more, actually) values in no particular order, and outputs a single value through the output variable of the predicate (if you try to run it as a full program, it'll just print true. at you, unless you stick a w on the end). The input is interpreted as a Python-style range because to feed ⟦ multiple values I need to give it a subscript no matter whether it's ₂, ₃, or ₄ so I may as well choose the one that matches the test cases.
    h The first item of
⟦₃    the range represented by the input
   ᵒ  after it's been sorted by
  ḋ   prime factorization.

Saves three bytes over the more obvious ⟦₃{ḋh}ᵒh by taking advantage of that Brachylog sorts its lists by elements first rather than lengths, such that the first step of sorting by prime factorizations is sorting by largest prime factors.

Husk, 5 bytes = 5.71 characters
◄o▲p…

Try it online!
How?
◄       # element that minimizes result of
 o      # combining these 2 functions:
  ▲     # maximum of
   p    # prime factors
    …   # for the range from arg 1 ... arg 2

Cobra - 150
def f(r as vari int)
    x,y=r
    c,o=y,0
    for n in x:y,for m in n:0:-1
        p=1
        for l in 2:m,if m%l<1,p=0
        if n%m<=0<p
            if m<c,c,o=m,n
            break
    print o

Not even sure why I bothered, cobra just can't compete here.

Cobra looks identical to python... What are the differences?

@BetaDecay Cobra is what happens when you give C# the syntax of Python. The Cobra Website

Python 2 (84)
f=lambda n,p=2:n>1and f(n/p**(n%p<1),p+(n%p>0))or p
print min(range(*input()),key=f)

@isaacg's solution, but with a min by function key in place of explicit min-finding, and a recursive function playing the role of the iteration.
Run in Stackless Python to avoid recursion limits.
It looks wasteful to use the paranthesized condition (n%p<1), then repeat its negation also in parantheses (n%p>0), but that was the best I got. I tried things a bunch of things, but they turned out worse.
f(n/p**(n%p<1),p+(n%p>0))     # Current for comparison
f(*[n/p,n,p,p+1][n%p>0::2])
n%p and f(n,p+1)or f(n/p,p)
f(*n%p and[n,p+1]or[n/p,p])

I welcome any improvements you can think of.

Ruby - 113 chars
Using the stdlib. Returns one result. Tested on ruby 2.1.2.
require 'prime'
def smooth_range(a,b)
  (a...b).sort_by{|e|e.prime_division.flat_map{|f,p|[f]*p}.uniq.max}[0]
end

Welcome to Programing Puzzles and Code Golf Stack Exchange. Thanks for posting your result. Since this is a code-golf question, please include your character count in your answer. You can use a tool such as this one: http://www.javascriptkit.com/script/script2/charcount.shtml

Perl (5.10+), 83
for(<>..<>){$n=$_;$p=2;$_%$p&&$p++or$_/=$p while$_>1;$m=$p,$r=$n if$p<$m||!$m}
say$r

(linebreak can be removed). Takes two endpoints of an inclusive range on two lines of stdin (because <> is cheaper than accessing ARGV) and outputs the smoothest to stdout. If there's a tie for smoothest, prints the smallest. Could print the biggest at the cost of one character.
The algorithm is basically isaacg's way of finding the greatest prime factor, although we came up with it independently. That part golfs down beautifully to a single statement in perl, the rest has more overhead than I'd like though.
Should be run under perl -E or with a use 5.012 preamble. If you can't do that, replace say$r with print$r,$/.

Java 8 - 422 454 chars
I'm learning Java 8, and wanted to give this a shot relative to Java (or even Java 8 streams).
Compared to other languages, this is brutal but an interesting exercise.
Golfed:
import java.util.stream.*;import java.math.*;
class F{int v;int i;public int getV() { return v; }
F(int i){this.i = i;v=IntStream.range(2,i+1).map(j->((i%j==0)&&new BigInteger(""+j).isProbablePrime(1))?j:0).max().getAsInt();}}
public class T{
int s(int a, int b){return IntStream.range(a,b+1).boxed().map(F::new).sorted(java.util.Comparator.comparingInt(F::getV)).collect(java.util.stream.Collectors.toList()).get(0).i;}}

Ungolfed:
import java.util.stream.*;
import java.math.*;

class F {
    int v;
    int i;
    public int getV() { return v; }
    F (int i) {
        this.i = i;
        v = IntStream.range(2,i+1)
                     .map( j -> ((i%j==0) &&
                           new BigInteger(""+j).isProbablePrime(1))?j:0)
                     .max()
                     .getAsInt();
    }
}

public class T {
    int s(int a, int b) {
        return IntStream.range(a,b+1)
                    .boxed()
                    .map(F::new)
                    .sorted(java.util.Comparator.comparingInt(F::getV))
                    .collect(java.util.stream.Collectors.toList())
                    .get(0).i;
    }
}

example run using:
public static void main(String[] s) {
    System.out.println(new T().s(157,249));
}

192

MATL (non-competitive), 20 bytes
This language was designed after the challenge
Range is inclusive at both ends. The numbers are taken as two separate inputs.
2$:t[]w"@YfX>v]4#X<)

Try it online!
Explanation
2$:          % implicitly input two numbers. Inclusive range
t            % duplicate
[]           % empty array
w            % swap elements in stack
"            % for each
  @          %   push loop variable
  Yf         %   prime factors
  X>         %   maximum value
  v          %   vertical concatenation
]            % end for each
4#X<         % arg min
)            % index with this arg min into initial range of numbers

I guess today this would be 17 bytes &:[]y"@YfX>h]&X<) or perhaps 16 :[]y"@YfX>h]&X<). The & really was a great idea (and I'm guessing y wasn't available back then?).

And it looks like broadcast Yf with prefixed 1's would have been useful here too, but that's probably not enough to decide it's a good idea in general. :)

Yes, this was the very beginning, so no y or &. Credit to Suever for the very useful semantics of the latter (my initial idea was make it mean "one input more than default"). If we see more instances where Yf with adding ones would be useful, it may really be worth adding that feature. Problem is, there are about 34 answers that use Yf (according to this script), so it's hard to tell

Jelly, 7 bytes, score = 7÷7×8 = 8, language postdates challenge
rÆfṀ$ÐṂ

Try it online!
Takes the lower and upper range endpoints as two separate arguments. Outputs a list of all the smoothest numbers in the range. (This can be viewed as a function, in which case the output is a Jelly list, or as a full program, in which case the output happens to use the same list representation that JSON does.)
Explanation
Those times when your Jelly program is just a literal translation of the spec…
rÆfṀ$ÐṂ
r        Range from {first argument} to {second argument}
     ÐṂ  Return the elements which have the minimum
   Ṁ$      largest
 Æf          prime factor

05AB1E, 6 bytes
Input as a list of two items, outputs just one found integer in the [A,B] range (inclusive on both sides):
ŸΣfθ}н

Try it online or verify all test cases.
Explanation:
Ÿ          # Create a list in the inclusive range of the (implicit) input
           #  i.e. [9,15] → [9,10,11,12,13,14,15]
 Σ  }      # Sort it by:
  f        #  Get the prime factors
           #   i.e. 9 → [3]
           #   i.e. 10 → [2,5]
   θ       #  Pop and push the last item
           #   i.e. [3] → 3
           #   i.e. [2,5] → 5
           #  i.e. [9,10,11,12,13,14,15] → [9,12,10,15,14,11,13]
     н     # After sorting, pop and push the first item
           #  i.e. [9,12,10,15,14,11,13] → 9
           # (and output the result implicitly as result)

8 bytes alternative with same input-format, but outputs all found integers (as string) instead of one:
ŸDf€θWQÏ

Try it online or verify all test cases.
Explanation:
Ÿ          # Create a list in the inclusive range of the (implicit) input
           #  i.e. [9,15] → [9,10,11,12,13,14,15]
 D         # Duplicate this list
  f        # Get the prime factors of each
           #  i.e. [9,10,11,12,13,14,15] → [[3],[2,5],[11],[2,3],[13],[2,7],[3,5]]
   €θ      # Only leave the last value of each inner list
           #  i.e. [[3],[2,5],[11],[2,3],[13],[2,7],[3,5]] → [3,5,11,3,13,7,5]
     W     # Get the minimum of this list (without popping the list itself)
           #  i.e. [3,5,11,3,13,7,5] → 3
      Q    # Check for each value in the list if it is equal to this minimum
           #  i.e. [3,5,11,3,13,7,5] and 3 → [1,0,0,1,0,0,0]
       Ï   # Leave only the values of the duplicated list at the truthy indices
           #  i.e. [9,10,11,12,13,14,15] and [1,0,0,1,0,0,0] → ["9","12"]
           # (and output the result implicitly as result)

Factor + math.primes.factors, 37 bytes
[ [a,b) [ factors last ] infimum-by ]

Try it online!
Explanation:
This is a quotation (anonymous function) that takes two integers from the data stack as input and leaves one integer on the data stack as output. Assuming 2001 2014 is on top of the data stack when this quotation is called...

[a,b) Create a range object from two integers. The lower bound is included but the upper bound is excluded. Stack: T{ range f 2001 13 1 }
[ factors last ] Push a quotation to the data stack to be used later by the infimum-by word. Stack: T{ range f 2001 13 1 } [ factors last ]
infimum-by Apply a quotation to each element of a sequence, returning the element whose result is smallest. (Inside the quotation now...) Stack: 2001
factors Get the sorted list of prime factors given an integer. Stack: { 3 23 29 }
last Get the last element of a sequence. Stack: 29
Now infimum-by takes note of 29 and moves onto the next element in its input range...

Vyxal, 5 bytes
ṡ‡ǐt∵

Try it Online!
ṡ     # Range from a to b
    ∵ # Minimum by...
 ‡--  # Next two as function
   t  # Last
  ǐ   # Prime factor

C#, 240 234 226 161 characters

int S(int i,int b){int s=2<<29,n=0,k,j,p;for(k=i;i<b;k=++i){for(;k>1;--k){if(i%k<1){p=1;for(j=2;j<k;++j)if(k%j<1)p=0;if(p>0)break;}}if(k<s){s=k;n=i;}}return n;}}

Acknowledgements & Reduction Explanations
- Thanks to CodesInChaos for reductions to 226, see comments for specifics
- Reduced to 161 after re-reading the rules and seeing that a mere function is allowed (i.e., a free-standing program is not required.)
Usage
function:
- input: two integers
- output: if multiple valid answers exist, returns the smallest
Explanation (with comments and runnable test-wrapper)
class Test
{
    int S(int i, int b)
    {
        //s = lowest gpf found so far
        //n = best answer so far
        //i = range iterator
        //p = prime indicator (1=true, 0=false)
        int s = 2 << 29, n = 0, k, j, p;
        for(k=i; i<b; k=++i)
        {
            //iterate through the factors of i
            for(;k>1;--k)
            {
                if (i % k < 1)
                {
                    p=1;
                    //determine if k is prime
                    for (j = 2; j < k; ++j)
                        if (k % j < 1)
                            p = 0;
                    if (p>0) break;
                }
            }
            if (k < s)
            {
                s = k;
                n = i;
            }
        }
        return n;
    }

    public static void Main(string[] args)
    {
        var d = new D();
        System.Diagnostics.Debug.Assert(d.S(5, 11) == 8);
        System.Diagnostics.Debug.Assert(d.S(9, 16) == 9);
        System.Diagnostics.Debug.Assert(d.S(9, 17) == 16);
        System.Diagnostics.Debug.Assert(d.S(157, 249) == 162);
        System.Diagnostics.Debug.Assert(d.S(2001, 2014) == 2002);
    }
}

Why using System? As far as I can tell, you're only using it once, a qualified name System.Console.Write should be shorter.

thanks @CodesInChaos.  In my early iterations, I used System for 3 things, then forgot to cleanup after eliminating the other 2.   Code updated.

Turing p into an int should save 6 chars.

yes @CodesInChaos, that thought also occurred to me over the weekend, and just hadn't gotten around to posting an update.

reduced to 161 by changing from a command-line app to a simple method  (after re-reading the rules)

Japt -g, 8 bytes
õV ñ_k Ì

Try it

Explanation
             :Implicit input of integers U & V
õV           :Range [U,V]
   ñ_        :Sort by passing each through a function
     k       :  Prime factors
       Ì     :  Last element
             :Implicitly output the first element in that array

Julia, 58 bytes
using Primes
!r=[r;][indmin(max(factor(Set,n)...)for n=r)]

Takes a Range object of the form 5:9 as input, returns the smallest of the smoothest numbers in the range. (No TIO link, because TIO doesn't seem to have the Primes package.)

ECMAScript 2016 - 100 characters
m=>M=>(r=_=>M-m?[m,...r(++m)]:[])().sort((x,y)=>(s=(n,p=2)=>n>p?n%p?s(n,p+1):s(n/p,p):p)(x)-s(y))[0]

Definitely gets hurt by the lack of a built-in range.
This is a pretty standard anonymous function. It takes in a minimum (inclusive) and a maximum (exclusive), and then spits out the smallest smoothest number in that range.

Charcoal, 44 bytes
Ｎθ≔…θＮη≔¹ζＷ¬№η¹«≦⊕ζＷ⊙η¬﹪λζＵＭη⎇﹪λζλ÷λζ»Ｉ⁺θ⌕η¹

Try it online! Link is to verbose version of code. Takes input as a half-open range and returns the lowest smoothest number from that range. Works by trial division of all the numbers in the range until at least one has become completely factorised (in which case it is the smoothest). Explanation:
Ｎθ

Input the lower end of the range.
≔…θＮη

Create an array covering the whole range.
≔¹ζ

Set the initial factor to 1.
Ｗ¬№η¹«

Repeat until there is at least one 1 in the array.
≦⊕ζ

Increment the factor.
Ｗ⊙η¬﹪λζ

Repeat while at least one element is divisible by the factor.
ＵＭη⎇﹪λζλ÷λζ»

Divide all divisible elements by the factor.
Ｉ⁺θ⌕η¹

Look up the (first) index of the 1, add on the lower end of the range, and print the result as a string.

MathGolf, 9 bytes
↨áæ─g¶╙0§

Try it online!
Explanation
Could be 1-2 bytes shorter with a "get prime factorization" operator.
↨           pop a, b, loop from a to b (inclusive)
 á          sort by comparator
  æ         start block of length 4
   ─        get divisors
    g       pop a, (b), pop operator from code, filter
     ¶      is_prime(n)
      ╙     maximum of two elements, max of list, maximum by filter
       0    push 0
        §   get from array

Stax, 9 bytes
üwπ┼♦Σjô≤

Run and debug it
Thought this would be shorter.

Thunno 2 h, 4 bytes
IÞfG

Try it online!
Explanation
IÞfG  # Implicit input
I     # Range between the inputs
 Þ    # Sorted by the following:
  f   #  Prime factors of the number
   G  #  Take the maximum of this list
      # Implicit output of first item

source: Stack Exchange

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

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

sort: votes


text:
Run the Nth characters to get N
Write the shortest program possible such that when you combine the first character and every Nth character after it into a new program, the output is N. This must work for N = 1, 2, ..., 16.
Another way to say it is, if you remove all the characters from your program except for the first one and every Nth one after that, the output of the remaining code should be N.
Example
If your code was
ABCDEFGHIJKLMNOP

N = 1 results in ABCDEFGHIJKLMNOP. Running this should output 1.
N = 2 results in ACEGIKMO. Running this should output 2.
N = 3 results in ADGJMP. Running this should output 3.
N = 4 results in AEIM. Running this should output 4.
N = 5 results in AFKP. Running this should output 5.
N = 6 results in AGM. Running this should output 6.
N = 7 results in AHO. Running this should output 7.
N = 8 results in AI. Running this should output 8.
N = 9 results in AJ. Running this should output 9.
N = 10 results in AK. Running this should output 10.
N = 11 results in AL. Running this should output 11.
N = 12 results in AM. Running this should output 12.
N = 13 results in AN. Running this should output 13.
N = 14 results in AO. Running this should output 14.
N = 15 results in AP. Running this should output 15.
N = 16 results in A. Running this should output 16.
Details

All characters are allowed, ASCII and non-ASCII. (Newlines and unprintable ASCII are allowed as well. Note that carriage return and line feed count as distinct characters.)
Your score is the length in characters of your unaltered program (15 in example). The lowest score wins.
A score below 16 is clearly impossible because then at least two of the altered programs would be identical.
Output may be to a file or stdout or anything else reasonable. However, the output of the 16 different programs must all go to the same place (e.g. it's not ok if AO goes to stdout but A goes to a file). There is no input.
The output must be in decimal, not hex. The actual output should only contain the 1 or 2 characters that make up the number from 1 to 16, nothing else. (Things like Matlab's ans =  are ok.)
Your program does not have to work for N = 17 or above.

Your stance on comments in the program? Yay or nay?

@AndoDaan Yay .

What about newlines, are those treated as characters?
Also, what about outputting unprintable characters to STDOUT additionally to the numbers?

It looks like when code is ABCDEFGHIJKLMNO and N = 15, result code is just A.

@githubphagocyte and Snack Fixed the examples and unclear parts. Thanks!

@overactor Newlines are fine. Additional output is not.

The specification leaves output undefined when input does not correspond to an N, is this correct?

@Taemyr Yes, that's right

APL, 49
⌊⊃⍟○7⍟⍟1|/2111118 9⍝×-1 ×○3×4_5_×   1_   _⍝_⍝ __2

Altered programs
1  ⌊⊃⍟○7⍟⍟1|/2111118 9⍝×-1 ×○3×4_5_×   1_   _⍝_⍝ __2
2  ⌊⍟7⍟|21189×1×345× 1  ⍝⍝_2
3  ⌊○⍟/119-××5 1 ⍝ 2
4  ⌊7|18××4×1 ⍝2
5  ⌊⍟21×○5
6  ⌊⍟19×51⍝2
7  ⌊11-4 ⍝
8  ⌊|8×× 2
9  ⌊/9×1
10 ⌊2×5
11 ⌊11 ⍝
12 ⌊1×12
13 ⌊13
14 ⌊14⍝
15 ⌊15
16 ⌊8×2

Explaination
I'll start from the bottom as it would make explaining easier
There are two language feature of APL to keep in mind. One, APL has no operator precedence, statements are always evaluated right to left. Two, many APL functions behave quite differently depending if it is given one argument on its right (monadic) or two arguments on its left and right (dyadic).
Monadic ⌊ is round down (floor function), Dyadic × is obviously multiplication, ⍝ comments out rest of the line
This should make these obvious:
16 ⌊8×2
15 ⌊15
14 ⌊14⍝
13 ⌊13
12 ⌊1×12
11 ⌊11 ⍝
10 ⌊2×5

9: ⌊/9×1
/ is Reduce. Basically it takes the function of the left and the array on the right, insert the function between every pair of elements of the array and evaluate. (This is called "fold" in some languages)
Here, the right argument is a scalar so / does nothing.
8: ⌊|8×× 2
Monadic × is the signum function and monadic | is the absolute value function
So, × 2 evaluates to 1 and |8×1 is of course 8
7: ⌊11-4 ⍝ should be obvious
6: ⌊⍟19×51⍝2
Monadic ⍟ is natural log
So, ⍟19×51 evaluates to ln(19×51) = 6.87626..., and ⌊ rounds it down to 6
5: ⌊⍟21×○5
Monadic ○ multiplies its argument by π
⍟21×○5 is ln(21×5π) = 5.79869...
4: ⌊7|18××4×1 ⍝2
Dyadic | is the mod function
×4×1 evaluates to 1, and 7|18×1 is 18 mod 7 = 4
3: ⌊○⍟/119-××5 1 ⍝ 2
Space-separated values is an array. Note that in APL, when most scalar functions are give array arguments, it is an implicit map.
Dyadic ⍟ is log
So ××5 1, is signum of signum on 5 and 1, which gives 1 1, 119-1 1 is ¯118 ¯118 (¯ is just the minus sign. APL has to distinguish between negative numbers and subtraction), and ⍟/¯118 ¯118 is log-118(-118) = 1
2: ⌊⍟7⍟|21189×1×345× 1  ⍝⍝_2
You can work it out yourself
1: ⌊⊃⍟○7⍟⍟1|/2111118 9⍝×-1 ×○3×4_5_×   1_   _⍝_⍝ __2
This one consist of a more complicated use of /. If n is a number, F is a function, and A is an array, then nF/A takes each group of n consecutive entries of A and apply F/. For example, 2×/1 2 3 takes each pair of consecutive entries (which are 1 2 and 2 3) and apply ×/ to each group to give 2 6
So, 1|/2111118 9 just returns 2111118 9 (as it applies |/ to scalars). Then, ⍟○7⍟⍟ applies ln, then log7 to those numbers, then multiplies them by π and ln again. The numbers that come out the other side are 1.46424... 0.23972...
Here, ⊃ is just used to select the first element of an array.

Python - 1201 1137 (generator: 241 218) - Long live the hashes!
Strategy:
I tried to start every line with as many hashes as the desired output n. Then all other versions will skip this line completely.
The main difficulty, however, was to append the correct number of hashes so that the next run will hit the beginning of the next line exactly. Furthermore, interferences with other versions might occur, e.g. version 16 jumping right into the print command of line 5 and so on. So this was a lot of trial and error combined with a helper script for rapid testing.
Statistics:

Characters: 1201 1137
Hashes: 1066 1002 (88.1 %)
Non-hashes: 135 (11.9 %)

Code:
#
print 1#####
#p#r#i#n#t# #2######################
##p##r##i##n##t## ##3###
###p###r###i###n###t### ###4
####p####r####i####n####t#### ####5#########
#####p#####r#####i#####n#####t##### #####6##########
######p######r######i######n######t###### ######7###########
#######p#######r#######i#######n#######t####### #######8###
########p########r########i########n########t######## ########9##
#########p#########r#########i#########n#########t######### #########1#########0##
##########p##########r##########i##########n##########t########## ##########1##########1##
###########p###########r###########i###########n###########t########### ###########1###########2##
############p############r############i############n############t############ ############1############3##
#############p#############r#############i#############n#############t############# #############1#############4##
##############p##############r##############i##############n##############t############## ##############1##############5##
###############p###############r###############i###############n###############t############### ###############1###############6

Test script:
with open('printn.py', 'r') as f:
    c = f.read()

for n in range(1, 17):
    print "n =", n, "yields",
    exec c[::n]

Output:
n = 1 yields 1
n = 2 yields 2
n = 3 yields 3
n = 4 yields 4
n = 5 yields 5
n = 6 yields 6
n = 7 yields 7
n = 8 yields 8
n = 9 yields 9
n = 10 yields 10
n = 11 yields 11
n = 12 yields 12
n = 13 yields 13
n = 14 yields 14
n = 15 yields 15
n = 16 yields 16

Update: A generating script!
I thought about my solution and that there must be a pattern to generate it algorithmically. So here we go:
lines = ['#']
for i in range(1, 17):
    lines.append(('#' * (i - 1)).join('\nprint ' + `i`))
    fail = True
    while fail:
        while ''.join(lines)[::i].find('print ' + `i`) < 0:
            lines[i] = '#' + lines[i]
        fail = False
        for n in range(1, 17):
            try:
                exec ''.join(lines)[::n]
            except:
                lines[i] = '#' + lines[i]
                fail = True
                break
print ''.join(lines)

It builds the program line by line:

Start with a hash.
Append a new line i with the print i command and i - 1 hashes in between each two neighboring characters.
While the "i-version" (every i-th character) of the current program does not contain the command print i (due to misalignment) or any n-version with n in range(1, 17) throws an exception, add another hash to the previous line.

It actually returned a shorter program than I found manually this morning. (So I updated my solution above.) Furthermore, I'm pretty sure there is no shorter implementation following this pattern. But you never know!
Golfed version - 241 218:
h='#';L=[h];I=range(1,17);J=''.join
for i in I:
 p='print '+`i`;L+=[(h*(i-1)).join('\n'+p)]
 while 1:
  while J(L)[::i].find(p)<0:L[i]=h+L[i]
  try:
   for n in I:exec J(L)[::n]
   break
  except:L[i]=h+L[i]
print J(L)

Note that there might be a shorter generator, e.g. by hard-coding the required number of succeeding hashes for each line. But this one computes them itself and could be used for any N > 16.

The character is usually called "hash" (or "octothorpe" if you feel fancy, or "number sign")

Nice work! Using Ruby you could shorten it a lot by using p 1 instead of print 1.

Yes, absolutely! In terms of code golf this might be Python's major weakness. - But thanks to AndoDaan's 5765776-character solution my code length is still far beyond average! :)

Befunge 93 - Five million seven-hundred sixty-five thousand and seven-hundred and seventy six characters
I demand to be taken seriously...
v                                                                               &(720 720 - 80) X SPACE
""""""""""""""""                                                                &(720 720 - 80) X SPACE
1234567890123456                                                                &(720 720 - 80) X SPACE
"""""""""1111111                                                                &(720 720 - 80) X SPACE
,,,,,,,,,"""""""                                                                &(720 720 - 80) X SPACE
@@@@@@@@@,,,,,,,                                                                &(720 720 - 80) X SPACE
         ,,,,,,,                                                                &(720 720 - 80) X SPACE
         @@@@@@@                                                                &(720 720 - 80) X SPACE

3 reasons why. 1st reason: a befunge script is always 80x25, so no matter what, there had to be something that got reduced on the lines with code. 2nd reason: why that something is about 5.5 million spaces is because 720 720 is the smallest common multiple of 1 to 16... Means there will be no wrap around mess when we're skipping characters. 3rd reason: wow, this is pretty absurd.

209 characters (Various languages)
I just tried to keep things simple and avoid putting anything in positions with a lot of prime factors. The advantage is an ability to run in many scripting languages. It should work in any language that is not deliberately perverse and has the following features:

Integer literals
Basic arithmetic operators +, - (subtraction and negation), *, /
Prints the evaluation of a bare expression
Has a single character that begins a line comment

For example,
Python 2 command-line interpreter (though not from a file):
+                1 #            4 /   23      #    #   5            #            9   #            7   6 *         #    # -        5     2   *  -        ##  2        6   #2                     *   2       6   4

MATLAB (simply replace '#' with '%'):
                 1 %            4 /   23      %    %   5            %            9   %            7   6 *         %    % -        5     2   *  -        %%  2        6   %2                     *   2       6   4

N.B. There should be 17 spaces preceding the first '1'.
You guys know a lot of languages, so please help me list more that it could run in ( :
EDIT: Added unary + at position 0 for Python to avoid the line being indented.

Spyder throws an IndentationError run in the command line. But maybe you didn't use the correct markdown syntax when posting the code here.

As I feared the number of spaces turned out wrong, but now it is fixed. @Falko Each program should be all on one line so I don't think the missing spaces should cause an indentation error. Maybe your interpreter demands that everything be left aligned, or maybe the program for each number needs to be run separately instead of all together.

My interpreter expects the first line to start at the very beginning. So your code can't be executed.

I'm getting unexpected indent in the Python 2.7 console as well. But it works in Matlab so no worries. I believe it also works in Ruby.

Oops sorry Falko and Calvin's Hobbies, you are right it didn't work. But I've managed to circumvent the error by changing the first character to '+'.

Nice generic solution. Validated on MATLAB by assigning to a variable s and calling for example eval(s(1:13:end)), note that s(1:13:end) is then    3    * 5-2%  4

CJam, 89 bytes
GiiAHH(5A5(7ii)ii;(;(-i((i(-i)i)ii)i()i((i(i(iiii(iii(iiiii(iiiii(i-i(iiiiiii(ii(ii(-ii-

This approach doesn't use any kind of comments.
i casts to integer, so it is a noop here. It could be replaced by whitespace, but the letters seem more readable  to me...
Try it online by executing the following Code:
G,{)
"GiiAHH(5A5(7ii)ii;(;(-i((i(-i)i)ii)i()i((i(i(iiiii(iii(iiiii(iiiii(i-i(iiiiiii(ii(ii(-ii-"
%_~}%N*

Example run
$ cat nth-char.cjam
G,{)"GiiAHH(5A5(7ii)ii;(;(-i((i(-i)i)ii)i()i((i(i(i
iii(iii(iiiii(iiiii(i-i(iiiiiii(ii(ii(-ii-"%_~}%N*N
$ cjam nth-char.cjam
GiiAHH(5A5(7ii)ii;(;(-i((i(-i)i)ii)i()i((i(i(i
iii(iii(iiiii(iiiii(i-i(iiiiiii(ii(ii(-ii-
1
GiH(A(i)i((i((iii)(i(((
i(i(ii(ii(-(iii(ii(i-
2
GA(5ii(-(-ii(((iii(i(i(iii(((i
3
GHAii((ii(((iii(i-iii(-
4
GH(i(iii(i(i(i(ii-
5
G(i((i((i(((i((
6
G5)-ii(iii(i(
7
GAi(i(iiiii-
8
G5(-(i(ii(
9
G((i((((i
10
G7ii(i(i-
11
Gi((i(i(
12
Gi((ii(
13
G)i(i((
14
Giii(i
15
Giiiii
16

GolfScript, 61 bytes
1})_#;#;;00123358_(_};}_}_}} _}_(__6
_})4_)_+)__(__}__;_}___6

This takes advantage of comments (#) and the undocumented "super-comments" (everything following an unmatched } it is silently ignored).
_ is a noop. It could be replaced by whitespace, but the underscores seem more readable to me...
Try it online.
Example run
$ cat nth-char.gs
16,{)"1})_#;#;;00123358_(_};}_}_}} _}_(__6
_})4_)_+)__(__}__;_}___6"\%.~}%n*
$ golfscript nth-char.gs
1})_#;#;;00123358_(_};}_}_}} _}_(__6
_})4_)_+)__(__}__;_}___6
1
1)##;0238(}}}} }(_
}4)+_(__;}_6
2
1_#025(;}}}_
)))(};_6
3
1#;28}} (
4+(_}6
4
1;05}_}64)__6
5
1#2(}}
)(;6
6
1;3; 6)_}
7
1;8}(4(}
8
10(}
);
9
10}}4_6
10
11}_+_
11
12}
(6
12
13})_
13
13 )}
14
15})6
15
18((
16

Zsh, 249 bytes
b
y
e

2y
y
yyyy
e
bye 1
e e
e
e

9

1

1

11

1

13

4

5

6

b

b

b
y
y
y

e

6

8

1

0

b

b

y

e

e

7b

y

e

1

5

2

b
b
yy

e

3
4
Verify all slices online!
Every sliced program is of the form:
[...junk]
bye N
[junk...]

For example, for \$ N = 8 \$:
b2y1e
 11
6

bye 8

y

 e
2
be4

Attempt This Online!
The only code that matters is the bye 8, which exits the program with the exit code of 8.
The rest of the junk is just ignored by zsh, because it's all invalid commands. (Everything after the first valid bye also doesn't matter, because it never gets executed).

To optimise this answer, we want to interleave the programs bye 1, b y e   2, b  y  e     3, etc., so that:

every program starts at an offset that is a multiple of its corresponding value of \$ N \$
none of the programs "overlap", putting different characters in the same place, which will break the code
the total length is minimised (of course)

This problem boils down to searching over the permutations of \$ [1, 16] \$, and then inserting each program in the chosen order at the first valid offset in the output code.
I tried various strategies to solve these constraints, including some obvious orderings picked by hand, and a greedy breadth-first search, but the most successful was a crude "Monte Carlo" method:

shuffle the range into a particular order
arrange the programs in that order
if this solution was shorter than the previous iteration, then save it as the current shortest possibility
repeat ad nauseam

Here's my optimiser code, in Python:

import re, random, time

def valid(code, n):
    match = pattern.search(''.join(code))
    return match and match[1] == str(n)

pattern = re.compile(r"^\s*bye\s+(\d+)\s*$", re.MULTILINE)

# for repeatability
seed = int(time.time() * 1e6)
print(f"{seed=}")
random.seed(seed)

ns = list(range(1, 17))

# it's pretty much guaranteed we'll find a solution shorter than this fake one
result = "dummy" * 100

while True:
    code = ["\n"] * 1000
    random.shuffle(ns)
    used = set()
    for n in ns:
        used.add(n)
        out = code.copy()
        insert = f"bye {n}"
        offset = 0
        out[offset:offset + len(insert) * n:n] = insert
        while not all(valid(out[::i], i) for i in used):
            offset += n
            if offset >= 250:
                # too long
                break
            out = code.copy()
            out[offset:offset + len(insert) * n:n] = insert
        # hack to propogate break
        else:
            code = out
            continue
        break
    else:
        candidate = "".join(code).rstrip("\n")
        if len(candidate) < len(result):
            result = candidate
            print("------")
            print("length:", len(result))
            print(result)
Attempt This Online! (but due to ATO's timeout and non-streaming nature, this is probably better run on your actual computer)

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


text:
The Forest Path
After your disastrous canoe ride, you ended up falling off a waterfall at the end of the river rapids. Your canoe exploded, but you managed to survive the explosion. However, your river journey went completely off the map - you have now found yourself lost in the midst of a forest. Luckily, you still have your programming skills, so you decide to carve a program into the side of a tree to help you find your way through the forest. However, there is not much surface area on the tree, so you must make your program as short as possible.
The forest can be described as a n by n (n > 5) square of characters, which will only consist of the lowercase letters a-z. An example forest:
anehcienwlndm
baneiryeivown
bnabncmxlriru
anhahirrnrauc
riwuafuvocvnc
riwnbaueibnxz
hyirorairener
ruwiiwuauawoe
qnnvcizdaiehr
iefyioeorauvi
quoeuroenraib
cuivoaisdfuae
efoiebnxmcsua

You may have noticed that in this forest, there is a diagonal line of a characters running through it from the top left corner to the bottom right corner. This is a "path" through the forest which will lead you somewhere if you follow it. Your task is to write a program which will find the singular path. I will now more specifically describe what connotates a "path" in this challenge.
A "path", in this challenge, is defined as a line similiar to one which might have been generated with a Bresenham algorithm, but with the added requirements that:

The line must be a minimum 6 characters long
Each collinear (completely adjacent) group of characters in the line must be the same length.
It will begin at one edge of the forest and end at the opposite edge (see my comment here for elaboration)

To explain the second requirement more clearly, consider the following line:
aaa
   aaa
      aaa
         aaa
            aaa

This line is composed of collinear "segments" of characters, each of which are exactly three characters long. It qualifies as a path. Now consider this line:
a
 aa
   a
    aa
      a
       aa

This line is composed of collinear "segments" that are not all exactly the same length of characters (some of them are 1 character long and some of them are 2). Thus, this one does not qualify as a path.
Your program, given a map of the forest, identify the characters used in the path. Input is to whatever is convienient (e.g. command line argument, STDIN, prompt(), etc.). It cannot be pre initialised into a variable. The first part of the input is a single integer n representing the size of the forest (the forest is always a square). After that is a space and then the entire forest as a single string. For instance, the example forest would be presented, as an input, like this:
13  anehcienwlndmbaneiryeivownbnabncmxlriruanhahirrnraucriwuafuvocvncriwnbaueibnxzhyirorairenerruwiiwuauawoeqnnvcizdaiehriefyioeorauviquoeuroenraibcuivoaisdfuaeefoiebnxmcsua

The output for this would be:
a

because the path is formed using the letter a. There will only be one path in the forest. This is code golf, so the lowest number of characters wins. If you have questions, ask in the comments.

What if there are multiple paths?

@EricTressler There will be only one path in any given forest. I'll edit the specification to reflect that.

Could the path letter be used somewhere else where it doesn't belong to the path?

The example forest contains that so probably. The first a on this line in the example forest is not part of the path anhahirrnrauc

@MartinBüttner Yes. But they won't be two paths made from the same letter at any point.

By '[A path] will begin at one edge of the forest and end at the opposite edge', do you mean an edge can only run horizontally, vertically, or from corner-to-corner?

@BeetDemGuise It can run from, 1) the left edge to the right edge or vice versa, 2) the top to the bottom or vice versa, 3) from any corner to any other corner.

If you say Each collinear [...] must be the same length. does that mean, that for a forest of size 13x13 there can be no paths except those running exactly horizontal, vertical or diagonal, because 13 is a prime number and thus cannot be divided in other equal-sized parts?

@Howard That implication is indeed correct.

APL (Dyalog 14) (70)
⎕ML←3⋄Z/⍨1=≢¨Z←∪¨(↓⍉F),(↓F),{(⍳≢⍵)⌷¨↓⍵}¨(⊂F),⊂⌽F←⊃{⍵⍴⍨2/⍎⍺}/I⊂⍨' '≠I←⍞

Explanation:

⎕ML←3: set ML to 3, meaning ⊂ has its APL2 meaning.
I←⍞: read a line from the keyboard and store it in I
I⊂⍨' '≠I: split I on the spaces
{...}/: apply this function to the two resulting strings:

2/⍎⍺: evaluate the left argument and replicate it twice, giving the matrix size
⍵⍴⍨: format the right argument using that size

F←⊃: unbox it and store it in F.
{(⍳≢⍵)⌷¨↓⍵}¨(⊂F),⊂⌽F: get the diagonals: from each row in both F and ⌽F (vertically mirrored F), get the value at column X, where X is its row number
(↓⍉F),(↓F),: get the rows and columns of F
Z←∪¨: find the unique values on each row, column and diagonal and store them in Z.

Since the 'forest' is rectangular, if there is a valid path it means one of these will consist of only one character, which is the path character, so:

Z/⍨1=≢¨Z: take those subarrays from Z that have only one element.

This will display the characters for all valid paths, but since there should be only one that doesn't matter.

Lua - 506 380 - bytes
I felt kinda bad that you hadn't received any submission for your well thought out challenge, so I threw this together. It was quit fun inferring what the minimum distinguishable properties the path must have from the information you gave. I hope I got it right... AND correctly implemented it.
a=io.read"*l"n=a:match("%d+")+0 m=a:match"[a-z]+"o=""for i=1,n do for k=1,n^2,n do o=o..m:sub(i+k-1,i+k-1)end end q={m,o}for g=1,n^2 do for u=1,2 do l=q[u]:sub(g,g)for r=1,n do i=1 t=0 e=0 while i do s,e=q[u]:find(l:rep(r),e+1)if s then x=s-(e-s)-i-1 print(s,i,r,n,r)if x==n or x==n-2 or t==0 then t=t+1 i=s end else i=nil end end if t*r==n then print(l)os.exit()end end end end

It can be tested with:
lua divisorPath.lua "input"

If a wild challenger appears, I'll look to golf my code for what it's worth.
Update: golfed in honour of those who will rise above us. While I was at it I had to fix my code to recognized path going from right to left. Oops.

Python - 384 325 275
This Algorithm basically checks the first and last row of the matrix for matching characters and then calculates the length of each line segment
012345
------
aaVaaa|0
aaVaaa|1
aaaVaa|2
aaaVaa|3
aaaaVa|4
aaaaVa|5

In the Example above:
The V in the first row is at index 2, the V in the last row at index 4.
So the length of each line segment would be n / (4-2)+1 = 2 with n=6.
It then checks if the line is valid.
In order to find a path from left to right, it swaps rows with columns and does the same thing again.
Edit: Can't quite get to 270 (Damn you Python and your damn indentation!!)
n,m=raw_input().split()
n,r=int(n),range
t=r(n)
a=[m[i:i+n]for i in r(0,n*n,n)]
for v in a,["".join([a[i][j]for i in t])for j in t]:
 for i in t:
  for j in t:
   p=1-2*(j-i<0);d,c=p*(j-i)+1,v[0][i]
   if 6<=sum([v[z][i+(z/(n/d))*p*(n%d==0)]==c for z in t])==n:print c;exit()

MATLAB - 270 characters
The following defines a function x that accepts a forest string as an argument and returns the character representing the valid "path" through the forest subject to the given rules.
function F=x(s),A=sscanf(s,'%d%s');n=A(1);A=reshape(A(2:end),n,n);for c=A(:)',B=A==c;for i=1:n,if~mod(n,i),C=[kron(eye(i),ones(n/i,1)),zeros(n,n-i)];for j=0:n-i,f=@(B)sum(sum(B&circshift(C,[0,j]))==n;D=fliplr(B);if f(B)|f(B')|f(D)|f(D'),F=char(c);end;end;end;end;end;end

The non-minified version is
function F = x(s)
    A = sscanf( s, '%d %s' );
    n = A(1);
    A = reshape( A(2:end), n,n );
    for c = A(:)'
        B = A==c;
        for i = 1:n
            if ~mod( n, i )
                C = [kron( eye(i), ones( n/i,1 ) ), zeros( n,n-i )];
                for j = 0:n-i
                    f = @(B) sum(sum( B & circshift( C, [0 j] ))) == n;
                    D = fliplr(B);
                    if f(B) | f(B') | f(D) | f(D')
                        F = char(c);
                    end
                end
            end
        end
    end
end

The basic premise is to construct a boolean mask for every possible valid path and return any character whose index function in the matrix covers any mask. To accomplish this, only vertical or top-to-bottom backslash-shaped masks are created, but the forest matrix is compared in all four orientiations: identity, flipped, rotated 90°, flipped rotated 90°.
The function runs for any n. An example of it being invoked on the commandline is
x('13 anehcienwlndmbaneiryeivownbnabncmxlriruanhahirrnraucriwuafuvocvncriwnbaueibnxzhyirorairenerruwiiwuauawoeqnnvcizdaiehriefyioeorauviquoeuroenraibcuivoaisdfuaeefoiebnxmcsua')

ans =

    a

authors: محمد احمد محمد عبد الظاهر


text:
Standardise leading zeroes in an input string
Write a program in the shortest number of bytes possible that will parse any string given to it by input, and output that string with any and all numbers padded with leading zeroes to match the largest number's length.
For example:
Input:
This 104 is an -8 example of 4.518 a string 50.

The generated output should become:
This 104 is an -008 example of 004.518 a string 050.

Note that any digits after the period are not considered part of the "length" of a number. Numbers are considered any sequence of digits with either 0 or 1 periods in the sequence. Numbers will be delimited with either the string boundary, spaces, commas, or newlines. They can also be followed by a period, but only if the period is then followed by a delimiting character. They can also be preceded with a '-' to indicated negatives.  So something like this:
The strings 20.d, 5.3ft and &450^ are not numbers, but 450.2 is.

Should output the following:
The strings 20.d, 5.3ft and &450^ are not numbers, but 450.2 is.

That is to say, no modifications.
String input will be no more than 200 characters, if your program has an upper bound for some reason.
The winning answer will be the answer in the shortest number of bytes in seven days from the posting of this question.
Test cases
Input:
2 40 2

Output:
02 40 02

Explanation: both substrings 2 are bounded on one side by a string boundary and on the other side by  .

Input:
E.g. 2,2.,2.2,.2,.2., 2 2. 2.2 .2 .2. 2d 2.d 2.2d .2d .2.d 40

Output:
E.g. 02,02.,02.2,00.2,00.2., 02 02. 02.2 00.2 00.2. 2d 2.d 2.2d .2d .2.d 40

Explanation: in the first two groups the first four numbers are followed by a delimiter (, or  ) and the final one is followed by a period then a delimiter; in the third group, each sequence is followed by the non-delimiter d.

@MartinBüttner yeah, that's a bit confusing, but basically it means that in "253.47", " 253" isn't a number even though it's followed by a period - it's part of a number. Will reword it when I'm back home.

@JanDvorak I feel like doing so would kind of defeat the point of the challenge - that's an exercise left to the reader. Happy to provide more examples and clarification though.

so, there's no number in 257.24ft? Now that's interesting...

@SebastianLamerichs note that 253.47 is not a sequence of digits...

@MartinBüttner I padded "4.518", not "4". Functionally they're the same. Basically, don't treat "4.518" as two separate numbers, despite them being delimited by a period.

also, your spec (sequence of digits, then period, then not a digit) makes 123 in 123.ft a number but not in 123ft

@JanDvorak That's correct. This challenge is designed to be trickier than it looks. Hopefully it lives up to that.

@SebastianLamerichs but 253.47 isn't a sequence of digits, and doesn't count as a number under your current spec... Will you fix your spec, or your example?

@JanDvorak I'm going to fix my spec. Unfortunately on my phone right now, though. Give me 20-30mins.

Edited the requirements to have more clarity, is there more ambiguity there?

The '-' is present in the examples but not in the spec.

@MartinBüttner Yeah, not sure what happened there. You seem to have caught the post in between two edits as i corrected it.

So, if I'm reading your rules right: This sentence ends in the number 50. This sentence does not end in a number 5.0. (Because 50. has one period, but 5.0. has two.) Confirm?

@IlmariKaronen 5.0. is not a number, but 5.0 is - the period is delimiting there.

Well, it wasn't a valid delimiter when I posted that comment. :) Anyway, now that periods are allowed as delimiters, which numbers, if any, should a string like 1.2.3.4.5 be considered to contain? Is it 1.2, 3.4 and 5, or perhaps 1.2, .3, .4 and .5, or something else?

@IlmariKaronen You can handle that however you like - it's not in spec because none of the test cases include it specifically because it's so ambiguous.

The spec's still broken. "Numbers are considered any sequence of digits with either 0 or 1 periods in the sequence", so in the example strings 20.d there is a number 20 with 0 full stops delimited by a leading space and a trailing full stop.

@PeterTaylor Is that better?

I will answer that question with a question: do you agree that the test cases I've added are correct? (If so, they need to be completed to cover all the corners of the spec).

@PeterTaylor I disagree with the first test case, but can't think of the word for the start of a file to list as a delimiter. I figured that it would be logically assumed (and indeed, all answers so far have done so).

2.2., is the other one which I thought you might disagree with.

@PeterTaylor I don't see that case anywhere, but maybe I'm blind.

That's a "sequence of digits with either 0 or 1 periods in the sequence" (2.2) "followed by a period [which] is then followed by a delimiting character".

@PeterTaylor Yeah, it's in the spec, but I don't see it in the examples - or were you referring to the spec in the first place?

Ah, it's .2.,. My mistake.

Ruby, 111 bytes
I hope this catches all the details of the spec
puts $*[0].gsub(r=/(?<![^,\s])(-?)(\d+)(?=\.?\d*(?![^,\s]))/){$1+$2.rjust(i.scan(r).map{|m|m[1].size}.max,'0')}

It reads the input as the first command line argument and prints the result to STDOUT.

Cobra - 282
class P
    def main
        r,s,l,n=RegularExpressions.Regex(r'^[\n,]?-?(\d+).?\d*[\n,]?$'),Console.readLine.split(' '),0,0
        for m in 2,for y,x in s.numbered,if r.isMatch(x),while (n-=n-r.match(x).groups[1].length)<if(n>l,l-=l-n,l),x=s[y]=if(x[0]=='-','-0'+x[1:],'0'+x)
        print s.join(' ')

For those of you wishing to test this without installing Cobra, it's rather easily converted into equivalent C# code.

 JavaScript, 201 chars
s=prompt();j=k=l=0,t={}
for(i in s){s[i]==+s[i]&&s[i]!=" "?j++:(t[i-j]=j,j=0);if(j>k)k=j;}if(j!=0)t[+i+1-j]=j
for(i in s){if(t[i])while(k-t[i]){s=s.slice(0,+i+l)+"0"+s.slice(+i+l);t[i]++;l++;}}alert(s)

I'm confused as to how input is meant to be handled here - without spaces (comma delimiting, for example) it seems to just print "0", and with spaces I can't even work out what it's doing (I got an output of "7" for "45 200" but am somehow unable to replicate that).

@SebastianLamerichs Guess I have to print the output in the program, forgot that.

@lazertyuiopl Yeah, there has to be output in some form, I was getting tripped up by JavaScript's insistence on returning a value even when not explicitly told to. Not sure where that 7 came from, though. I can confirm that it works fine for comma-delimited input now.

Are you sure it works? If I input "2 40 2", I get "02 40 2", not "02 40 02".

@IngoBürk I just inputted 2 40 2 and got 02 40 02 using Chrome 36 -- test here

@IazertyuiopI On the fiddle it works, but if I copy the code from the answer into the console it doesn't work.

Well I have no idea why. If you include it between  in a html page it also works, so I assume it is safe to say it is valid JavaScript. The code on the fiddle is copy pasted from the answer.


text:
Convert to uppercase and lowercase without branching and comparisons
Write two functions/programs which take an ASCII code of character (8-bit unsigned integer) and one of them converts char to uppercase and other to lowercase.
That is, they must be equivalent to following functions:
unsigned char toUpper(unsigned char c){
    if (c >= 97 && c <= 122) return c - 32;
    return c;
}
unsigned char toLower(unsigned char c){
    if (c >= 65 && c <= 90) return c + 32;
    return c;
}

However you are not allowed to use branching (ifs, gotos), loops and comparison and logical operators. Recursion, language built-in functions, regular expressions, arrays and objects also not allowed.
You may use only arithmetic and bitwise operations on 8-bit unsigned integers.
Score:
1 - for | & ^ ~ >> << operators
1.11 - for + - operators
1.28 - for * operator
1.411 - for / % operators
Answer with lowest total score (for two functions added) wins. If answers with equal score than first (oldest) answer wins.

Are regular expressions allowed? If yes, this is a duplicate of Converting a string to lower-case.

@ProgramFOX No.

This good valid question deserves more upvotes. If you are an anti-micro-optimization kind of a guy, then you shouldn't even be at this question, let alone allowing your own biases and prejudices to cloud your judgement and downvote this legitimate question. Also, off-topicly, I would be very interested (fascinated) to see how you generated those score numbers. I'm not criticizing them, rather, just the opposite, I'm intrigued. Mabey you could comment a link to a resource about it?

@lolzerywowzery How I chose scores: At start I defined approximate scores I want operations should have, like 1, 1.1, 1.3 and 1.4. Then with trial and error I modified them a bit so equal score is unlikely with small operator amount. Checked that in Mathematica.

C, C++ and related languages, 6.22
unsigned char toggle(unsigned char c, unsigned char lo, unsigned char hi)
{
    unsigned char m = (unsigned char)((lo - c) ^ (hi - c)) >> 7;
    return c ^ (m << 5);
}

unsigned char toUpper(unsigned char c)
{
    return toggle(c, 96, 122);
}

unsigned char toLower(unsigned char c)
{
    return toggle(c, 64, 90);
}

Your score is 12.44 - total score for 2 functions.

That seems unreasonable - there is only one instance of each operator, not two, and there was nothing in the rules to forbid factoring out common code.

One more time I failed writing rules.

If merging common code allowed, why not share all operators? (char xor(char a, char b){return a^b}) @Somnium

C and other languages with integer division, 15.204 14.644 14.084 11.864
unsigned char toUpper(unsigned char c){
    return c - ((c/97) ^ (c/123)) << 5;
}

unsigned char toLower(unsigned char c){
    return c + ((c/65) ^ (c/91)) << 5;
}

Just realized that toUpper gives wrong value for n in range [194 - 245] and toLower for almost all n >= 130.

@Somnium. Afaik ASCII contains only 128 characters. Everything else is extended ASCII which does not seem to be part of your spec.

@MartinBüttner Forgot about that fact. Then your solution is ok.

C, 11.482
My functions I have found before posting question, I hope there will better ones.
unsigned char toUpper(unsigned char c){
    unsigned char a = c - 97;
    return c - ((32 - a / 26) & 32);
}
unsigned char toLower(unsigned char c){
    unsigned char a = c - 65;
    return c + ((32 - a / 26) & 32);
}

C (gcc), 9.042 step score
uchar toUpper(uchar c){
    return c^(((uchar)(c+133)/230)<<5);
}
uchar toLower(uchar c){
    return c^(((uchar)(c+165)/230)<<5);
} // 9.042 step score

Try it online!
C (gcc), 2.11 existance score
uchar sub(uchar a, uchar b) {return a-b;}
uchar shr(uchar a, uchar b) {return a>>b;}
uchar add(uchar a, uchar b) {return sub(a, sub(0, b));}
uchar isneg(uchar a) {return shr(a, 7);}
uchar reach230(uchar a) {return shr(add(isneg(a),isneg(sub(229,a))),1);}
uchar dif(uchar a) {uchar t=reach230(a); t=add(t,t); t=add(t,t); t=add(t,t); t=add(t,t); t=add(t,t); return t;}
uchar toUpper(uchar c){ return sub(c,dif(add(c,133))); }
uchar toLower(uchar c){ return add(c,dif(add(c,165))); }

Try it online!