Thought provoking problem 
Author Message
 Thought provoking problem

Ralph,

Whats the significance of 109 characters ?
That is discriminatory against people who name variables meaningfully !

create table M ( N int )
go



begin


end

delete M
from M M
join M D
  on M.N % D.N = 0
 and M.N <> D.N

Select * from M

Regards
 AJ

Quote:

> What would some SQL requiring the least number of characters (excluding
> white spaces) to display all prime numbers less than 1000 without relying on
> existing tables?

> Can it be done using less than 109 characters?



Sun, 01 May 2005 15:43:35 GMT
 Thought provoking problem

What would some SQL requiring the least number of characters (excluding
white spaces) to display all prime numbers less than 1000 without relying on
existing tables?

Can it be done using less than 109 characters?



Sun, 01 May 2005 13:25:59 GMT
 Thought provoking problem
Perhaps it would be fairer to count keywords (including
variable names), and not count brackets in function calls,
to avoid giving an unfair advantage to languages that don't
use 'em, or that allow keywords to be abbreviated beyond
sense.

The rule given also rewards people who use GOTO, see below ;-)

I presume this is for some sort of contest.  We should share
the winnings.

I think I've made it to 109 in the following, including only

because it isn't part of the program specification, it just makes
the result more readable) - and that the text doesn't need to be

set nocount on
go

drop table M
go



create table M ( N int )


G:




Select * from M'



Come to think, Ralph didn't actually say it had to display
/only/ the prime numbers.


Trust me, all of them are in there ;-)

(And in fact Ralph also didn't say the program had to terminate -

SET ARITHABORT ON SET ANSI_WARNINGS OFF

Takes longer, though...)

Quote:

> Ralph,

> Whats the significance of 109 characters ?
> That is discriminatory against people who name variables meaningfully !

> create table M ( N int )
> go



> begin


> end

> delete M
> from M M
> join M D
>   on M.N % D.N = 0
>  and M.N <> D.N

> Select * from M

> Regards
>  AJ


> > What would some SQL requiring the least number of characters (excluding
> > white spaces) to display all prime numbers less than 1000 without relying on
> > existing tables?

> > Can it be done using less than 109 characters?



Sun, 01 May 2005 20:07:17 GMT
 Thought provoking problem

Quote:

> Come to think, Ralph didn't actually say it had to display
> /only/ the prime numbers.


> Trust me, all of them are in there ;-)

And upon further reflection:
WHILE 1=1 PRINT CONVERT(int, 1e3*RAND())

Has the merit of avoiding needless use of any tables or variables :-)



Mon, 02 May 2005 06:46:47 GMT
 Thought provoking problem



Quote:

> > Come to think, Ralph didn't actually say it had to display
> > /only/ the prime numbers.


> > Trust me, all of them are in there ;-)

> And upon further reflection:
> WHILE 1=1 PRINT CONVERT(int, 1e3*RAND())

> Has the merit of avoiding needless use of any tables or variables :-)

You said:
WHILE 1=1 PRINT CONVERT(int,1e3*RAND())
which without white space is:
WHILE1=1PRINTCONVERT(int,1e3*RAND())
which is 36 characters.

But no one said
they had to be integers.

So we can write this:
WHILE 1=1 PRINT FLOOR(1e3*RAND())
and even this:
G:PRINT FLOOR(1e3*RAND())GOTO G
which are shorter (33 and 31)
while still containing
necessary white space!

Without white space we have:
WHILE1=1PRINTFLOOR(1e3*RAND())
G:PRINTFLOOR(1e3*RAND())GOTOG
which are 30 and 29 characters.

So we are now down to
29 (non white space) characters.

Normally, one would count the necessary white spaces
in which case the count would be 31.

Bye,
Delbert Glass



Mon, 02 May 2005 09:18:17 GMT
 Thought provoking problem
Nice solution.  Tell you what, I'll give you half if it wins.  I managed to
shave a couple of extra characters by changing the line


to


Cheers


Quote:
> Perhaps it would be fairer to count keywords (including
> variable names), and not count brackets in function calls,
> to avoid giving an unfair advantage to languages that don't
> use 'em, or that allow keywords to be abbreviated beyond
> sense.

> The rule given also rewards people who use GOTO, see below ;-)

> I presume this is for some sort of contest.  We should share
> the winnings.

> I think I've made it to 109 in the following, including only

> because it isn't part of the program specification, it just makes
> the result more readable) - and that the text doesn't need to be

> set nocount on
> go

> drop table M
> go



> create table M ( N int )


> G:




> Select * from M'



> Come to think, Ralph didn't actually say it had to display
> /only/ the prime numbers.


> Trust me, all of them are in there ;-)

> (And in fact Ralph also didn't say the program had to terminate -

> SET ARITHABORT ON SET ANSI_WARNINGS OFF

> Takes longer, though...)




- Show quoted text -

Quote:
> > Ralph,

> > Whats the significance of 109 characters ?
> > That is discriminatory against people who name variables meaningfully !

> > create table M ( N int )
> > go



> > begin


> > end

> > delete M
> > from M M
> > join M D
> >   on M.N % D.N = 0
> >  and M.N <> D.N

> > Select * from M

> > Regards
> >  AJ




- Show quoted text -

Quote:
> > > What would some SQL requiring the least number of characters
(excluding
> > > white spaces) to display all prime numbers less than 1000 without
relying on
> > > existing tables?

> > > Can it be done using less than 109 characters?



Mon, 02 May 2005 12:03:19 GMT
 Thought provoking problem


variable name.

Steve Kass
Drew University

Quote:

>Nice solution.  Tell you what, I'll give you half if it wins.  I managed to
>shave a couple of extra characters by changing the line


>to


>Cheers



>>Perhaps it would be fairer to count keywords (including
>>variable names), and not count brackets in function calls,
>>to avoid giving an unfair advantage to languages that don't
>>use 'em, or that allow keywords to be abbreviated beyond
>>sense.

>>The rule given also rewards people who use GOTO, see below ;-)

>>I presume this is for some sort of contest.  We should share
>>the winnings.

>>I think I've made it to 109 in the following, including only

>>because it isn't part of the program specification, it just makes
>>the result more readable) - and that the text doesn't need to be

>>set nocount on
>>go

>>drop table M
>>go



>>create table M ( N int )


>>G:




>>Select * from M'



>>Come to think, Ralph didn't actually say it had to display
>>/only/ the prime numbers.


>>Trust me, all of them are in there ;-)

>>(And in fact Ralph also didn't say the program had to terminate -

>>SET ARITHABORT ON SET ANSI_WARNINGS OFF

>>Takes longer, though...)



>>>Ralph,

>>>Whats the significance of 109 characters ?
>>>That is discriminatory against people who name variables meaningfully !

>>>create table M ( N int )
>>>go



>>>begin


>>>end

>>>delete M
>>>from M M
>>>join M D
>>>  on M.N % D.N = 0
>>> and M.N <> D.N

>>>Select * from M

>>>Regards
>>> AJ



>>>>What would some SQL requiring the least number of characters

>(excluding

>>>>white spaces) to display all prime numbers less than 1000 without

>relying on

>>>>existing tables?

>>>>Can it be done using less than 109 characters?



Mon, 02 May 2005 13:04:17 GMT
 Thought provoking problem


Many thanks!


  variable name.

  Steve Kass
  Drew University


Nice solution.  Tell you what, I'll give you half if it wins.  I managed to
shave a couple of extra characters by changing the line


to


Cheers


Perhaps it would be fairer to count keywords (including
variable names), and not count brackets in function calls,
to avoid giving an unfair advantage to languages that don't
use 'em, or that allow keywords to be abbreviated beyond
sense.

The rule given also rewards people who use GOTO, see below ;-)

I presume this is for some sort of contest.  We should share
the winnings.

I think I've made it to 109 in the following, including only

because it isn't part of the program specification, it just makes
the result more readable) - and that the text doesn't need to be

set nocount on
go

drop table M
go



create table M ( N int )


G:




Select * from M'



Come to think, Ralph didn't actually say it had to display
/only/ the prime numbers.


Trust me, all of them are in there ;-)

(And in fact Ralph also didn't say the program had to terminate -

SET ARITHABORT ON SET ANSI_WARNINGS OFF

Takes longer, though...)


Ralph,

Whats the significance of 109 characters ?
That is discriminatory against people who name variables meaningfully !

create table M ( N int )
go



begin


end

delete M
from M M
join M D
  on M.N % D.N = 0
 and M.N <> D.N

Select * from M

Regards
 AJ


What would some SQL requiring the least number of characters

(excluding

white spaces) to display all prime numbers less than 1000 without

relying on

existing tables?

Can it be done using less than 109 characters?



Mon, 02 May 2005 13:26:21 GMT
 Thought provoking problem

Quote:





> > > Come to think, Ralph didn't actually say it had to display
> > > /only/ the prime numbers.

> > WHILE 1=1 PRINT CONVERT(int, 1e3*RAND())

> But no one said
> they had to be integers.

> So we can write this:
> WHILE 1=1 PRINT FLOOR(1e3*RAND())

If they don't have to be integers, we can probably even lose FLOOR().

G:PRINT 1e3*RAND()GOTO G

The prime numbers are still there in the mixture, probably...
if I get bored again, I'll try to prove it (not too hard,
since we already have a couple of working versions of the
Sieve of Eratosthenes.)



Mon, 02 May 2005 19:10:57 GMT
 Thought provoking problem

Quote:


> works well.

> Many thanks!

It surprised this reader, too.

One thought: is the contest for Microsoft Transact-SQL,
is it perhaps only for ANSI SQL-92 or some such?
We're using some Microsoft-only tricks now, I think.

Other considerations are that (1) I make that three guys
here besides yourself who contributed to the solution now
(but don't sweat it as far as I'm concerned), and (2) this
discussion is kind of open to the public.  Unfortunately
adding a copyright mark to our code would have boosted the
program length further ;-)

Anyway, I make that 100 non-whitespace characters, and it
/would/ be 99 if the upper limit of the number range was 99
instead of 1e3.

Now if Oracle allows decimal 0 and 1 as truth values, I think
they might beat us that way - but then again, ...?



Mon, 02 May 2005 21:37:41 GMT
 Thought provoking problem
I was thinking type.
However, you are correct, FLOOR should not be needed.
The prime values should still show up
unless there is a little glitch.

But of course it will likely take more looping
to get them all then without FLOOR.

Next there can be a contest to see
who can identify the seed that makes
the primes show up in the fewest
number of loops.

Bye,
Delbert Glass



Quote:




> > > > Come to think, Ralph didn't actually say it had to display
> > > > /only/ the prime numbers.

> > > WHILE 1=1 PRINT CONVERT(int, 1e3*RAND())

> > But no one said
> > they had to be integers.

> > So we can write this:
> > WHILE 1=1 PRINT FLOOR(1e3*RAND())

> If they don't have to be integers, we can probably even lose FLOOR().

> G:PRINT 1e3*RAND()GOTO G

> The prime numbers are still there in the mixture, probably...
> if I get bored again, I'll try to prove it (not too hard,
> since we already have a couple of working versions of the
> Sieve of Eratosthenes.)



Tue, 03 May 2005 01:59:05 GMT
 Thought provoking problem

This isn't ANSI, but it's short.  It's too late for me to count
reliably, so perhaps someone else can say whether it's the shortest yet.

select 2 N into M





delete M
from M, M A
where M.N%A.N=-A.N/M.N
Select * from M

SK

Quote:



>>works well.

>>Many thanks!

>It surprised this reader, too.

>One thought: is the contest for Microsoft Transact-SQL,
>is it perhaps only for ANSI SQL-92 or some such?
>We're using some Microsoft-only tricks now, I think.

>Other considerations are that (1) I make that three guys
>here besides yourself who contributed to the solution now
>(but don't sweat it as far as I'm concerned), and (2) this
>discussion is kind of open to the public.  Unfortunately
>adding a copyright mark to our code would have boosted the
>program length further ;-)

>Anyway, I make that 100 non-whitespace characters, and it
>/would/ be 99 if the upper limit of the number range was 99
>instead of 1e3.

>Now if Oracle allows decimal 0 and 1 as truth values, I think
>they might beat us that way - but then again, ...?



Tue, 03 May 2005 17:21:20 GMT
 Thought provoking problem

We are now down to 95 and it sounds like the mark to beat is 92,  Anyone got any clever ideas to get around using DECLARE  etc.....


  This isn't ANSI, but it's short.  It's too late for me to count reliably, so perhaps someone else can say whether it's the shortest yet.

  select 2 N into M





  delete M
  from M, M A
  where M.N%A.N=-A.N/M.N
  Select * from M

  SK



works well.

Many thanks!

It surprised this reader, too.

One thought: is the contest for Microsoft Transact-SQL,
is it perhaps only for ANSI SQL-92 or some such?
We're using some Microsoft-only tricks now, I think.

Other considerations are that (1) I make that three guys
here besides yourself who contributed to the solution now
(but don't sweat it as far as I'm concerned), and (2) this
discussion is kind of open to the public.  Unfortunately
adding a copyright mark to our code would have boosted the
program length further ;-)

Anyway, I make that 100 non-whitespace characters, and it
/would/ be 99 if the upper limit of the number range was 99
instead of 1e3.

Now if Oracle allows decimal 0 and 1 as truth values, I think
they might beat us that way - but then again, ...?



Fri, 06 May 2005 11:44:30 GMT
 Thought provoking problem

Quote:

> This isn't ANSI, but it's short.  It's too late for me to count
> reliably, so perhaps someone else can say whether it's the shortest yet.

> select 2 N into M





> delete M
> from M, M A
> where M.N%A.N=-A.N/M.N
> Select * from M

> SK

Not quite, I put you at 114, but your "SELECT INTO" is
worth stealing ;-)

And having done so, I'm down to 95 now (with the active code

feel free to steal /that/ [you might want to make it take out
CHAR(9) for the count as well]), and I think I also cut
execution time by looping on odd numbers only -

(If the rules specify prime numbers in /order/, then
I have to count the "ORDER BY"; that'd be 103?)

use [rjac021113a]
set nocount on
go

drop table M
go



select 2 N into M


G:




Select * from M'



I think you had a claim on a share in the collective prize pot
already, I'm not sure if you get 2 shares now ;-)



Fri, 06 May 2005 18:11:37 GMT
 Thought provoking problem

Here's one with no DELETE, but it's 99 characters:

select 2 N into M





select n from m

SK

Quote:


>>This isn't ANSI, but it's short.  It's too late for me to count
>>reliably, so perhaps someone else can say whether it's the shortest yet.

>>select 2 N into M





>>delete M
>>from M, M A
>>where M.N%A.N=-A.N/M.N
>>Select * from M

>>SK

>Not quite, I put you at 114, but your "SELECT INTO" is
>worth stealing ;-)

>And having done so, I'm down to 95 now (with the active code

>feel free to steal /that/ [you might want to make it take out
>CHAR(9) for the count as well]), and I think I also cut
>execution time by looping on odd numbers only -

>(If the rules specify prime numbers in /order/, then
>I have to count the "ORDER BY"; that'd be 103?)

>use [rjac021113a]
>set nocount on
>go

>drop table M
>go



>select 2 N into M


>G:




>Select * from M'



>I think you had a claim on a share in the collective prize pot
>already, I'm not sure if you get 2 shares now ;-)



Fri, 06 May 2005 22:18:39 GMT
 
 [ 25 post ]  Go to page: [1] [2]

 Relevant Pages 

1. HELP!! Distribution disks provoke error during install process

2. HELP!!! Distribution disks provoke error during install process

3. Thinking about WinHelp Tools? Think $$$

4. Thinking about WinHelp Tools? Think $$$

5. Combo Box Problem.. I think

6. Simple problem..I think

7. I think it might be network configuration problem

8. MAX problem (I think!)

9. LWLock contention: I think I understand the problem

10. I think??? BDE problem

11. cast problem, I think

12. Replication problem (I think)


 
Powered by phpBB® Forum Software