Player (36)
Joined: 9/11/2004
Posts: 2630
I'd like you to count to one million and skip every prime number and every number divisible by 7 as a demonstration that no one is perfect.
<curtmack> Okay I am now constructing a text file entitled "Numbers from 1 to 1 million skipping primes and multiples of 7.txt" <curtmack> after which I'll have a response for OmnipotentEntity <curtmack> of course I'm cheating since I'm using a program <curtmack> it's 5.2 megabytes <curtmack> I took it as a challenge <curtmack> gedit got confused about the encoding <OmnipotentEntity> curtmack, code golf it, <OmnipotentEntity> I'll challenge you.
So open challenge, code golf this, standard code golfing rules apply. PM me your code, several versions are OK, challenge closes at 7 Jan 7:00AM GMT. I'll keep a leaderboard here and update it continuously as submissions come in and release the code after the challenge is done. I have my single submission, I, of course, cannot improve upon it when I begin receiving submissions. So my submission is immutable. For brevity and execution speed, this challenge is for only numbers up to 1000. You may use any language and they will be placed in the following categories (partially arbitraily chosen): a) perl b) php c) python d) ruby e) anything and everything else expected output:
1 4 6 8 9 10 12 15 16 18 20 22 24 25 26 27 30 32 33 34 36 38 39 40 44 45 46 48 50 51 52 54 55 57 58 60 62 64 65 66 68 69 72 74 75 76 78 80 81 82 85 86 87 88 90 92 93 94 95 96 99 100 102 104 106 108 110 111 114 115 116 117 118 120 121 122 123 124 125 128 129 130 132 134 135 136 138 141 142 143 144 145 146 148 150 152 153 155 156 158 159 160 162 164 165 166 169 170 171 172 174 176 177 178 180 183 184 185 186 187 188 190 192 194 195 198 200 201 202 204 205 206 207 208 209 212 213 214 215 216 218 219 220 221 222 225 226 228 230 232 234 235 236 237 240 242 243 244 246 247 248 249 250 253 254 255 256 258 260 261 262 264 265 267 268 270 272 274 275 276 278 279 282 284 285 286 288 289 290 291 292 295 296 297 298 299 300 302 303 304 305 306 309 310 312 314 316 318 319 320 321 323 324 325 326 327 328 330 332 333 334 335 338 339 340 341 342 344 345 346 348 351 352 354 355 356 358 360 361 362 363 365 366 368 369 370 372 374 375 376 377 380 381 382 384 386 387 388 390 391 393 394 395 396 398 400 402 403 404 405 407 408 410 411 412 414 415 416 417 418 422 423 424 425 426 428 429 430 432 435 436 437 438 440 442 444 445 446 447 450 451 452 453 454 456 458 459 460 464 465 466 468 470 471 472 473 474 475 477 478 480 481 482 484 485 486 488 489 492 493 494 495 496 498 500 501 502 505 506 507 508 510 512 513 514 515 516 517 519 520 522 524 526 527 528 529 530 531 533 534 535 536 537 538 540 542 543 544 545 548 549 550 551 552 554 555 556 558 559 561 562 564 565 566 568 570 572 573 575 576 578 579 580 582 583 584 585 586 589 590 591 592 594 596 597 598 600 603 604 605 606 608 610 611 612 614 615 618 620 621 622 624 625 626 627 628 629 632 633 634 635 636 638 639 640 642 645 646 648 649 650 652 654 655 656 657 660 662 663 664 666 667 668 669 670 671 674 675 676 678 680 681 682 684 685 687 688 689 690 692 694 695 696 697 698 699 702 703 704 705 706 708 710 711 712 713 715 716 717 718 720 722 723 724 725 726 729 730 731 732 734 736 737 738 740 741 744 745 746 747 748 750 752 753 754 755 758 759 760 762 764 765 766 767 768 771 772 774 775 776 778 779 780 781 782 783 785 786 788 789 790 792 793 794 795 796 799 800 801 802 803 804 806 807 808 810 813 814 815 816 817 818 820 822 824 825 828 830 831 832 834 835 836 837 838 841 842 843 844 845 846 848 849 850 851 852 855 856 858 860 862 864 865 866 867 869 870 871 872 873 874 876 878 879 880 884 885 886 888 890 891 892 893 894 895 897 898 899 900 901 902 904 905 906 908 909 912 913 914 915 916 918 920 921 922 923 925 926 927 928 930 932 933 934 935 936 939 940 942 943 944 946 948 949 950 951 954 955 956 957 958 960 961 962 963 964 965 968 969 970 972 974 975 976 978 979 981 982 984 985 986 988 989 990 992 993 995 996 998 999 1000
Notice, space delimited. Trailing whitespace will be removed from your submission before it is compared against the expected output. EDIT: A few of you have been not getting the formatting down so, the md5sum of solution is: e5520566aa3e1456e05d1f17d91ab9d4 To check your solution simply run the program, strip the whitespace from the end and pipe the output to an md5sum utility. (contact me if you need help doing this.) EDIT: Clarification, output is expected to STDOUT, not to a file. EDIT: Code written in a different language will be accepted and placed into another category, I just don't know how much interest this will generate so I didn't want to overwhelm people. EDIT: Yes, you may submit code as many times as you would like in as many different languages as you like. EDIT: Clarification, leaderboard values are in characters, not in lines. EDIT: Clarification, of the categories and allowed languages. EDIT: Removed the no trailing whitespace requirement, walking through the submissions to find the ones that I rejected under that rule but are valid now.
Leaderboard: Perl: 56, OmnipotentEntity* 61, Bisqwit 76, Blublu PHP: 60, qFox & Bisqwit 62, Tub 69, Bisqwit 75, pauli 84, qFox Python: 83, lagdotcom 87, Mueen Nawaz 96, andymac 105, pauli 118, YtterbiJum Ruby: 50, flagitious 59, pauli 79, Bisqwit Others: 46, DK64_Master & DarkKobold (uses matlab) 79, Bisqwit (uses Javascript) 82, Warp (uses C, produces bad output when used with -O flags) 83, Warp (uses C) 84, Bisqwit (uses C) 96, POV-Ray Mascot (uses Haskell) 101, Bisqwit (uses QBASIC) 102, Bisqwit (uses GW-BASIC) 145, pauli (uses C#) 149, qFox (uses java) 150, Blublu (uses java) 260, YtterbiJum (uses WhiteSpace) 345, Andymac (LOLOLOLOL) 507, Pauli (uses befunge) Postmortem submissions: 118, bkDJ (uses C++)
* (immutable score) Leaderboard update: updated at 12/30/2008 17:30 GMT, several new versions were submitted, I don't have time to test them all yet, remember your md5sum should be e5520566aa3e1456e05d1f17d91ab9d4 Leaderboard update: updated at 12/31/2008 3:15 GMT, removed rejected versions, will send PM replies instead, flagitious blew right into the lead with an amazing ruby hack, I still haven't tested the PHP code, I'll get that done in the next few hours. Leaderboard update: updated at 1/1/2009 2:15 GMT, Blublu updated his java version and shaved a few characters, pauli updated his ruby submission a bit and shaved of a few as well. Leaderboard update: updated at 1/1/2009 6:00 GMT, pauli submitted a C# and a php version, added them Leaderboard update: updated at 1/2/2009 19:30 GMT, should be up to date, if I'm missing you let me know. Leaderboard update: Pauli and blublu are duking it out java vs. C#, it's kinda entertaining, *popcorn* Leaderboard update: updated at 1/7/2009 20:00 GMT, all submissions have been updated, I'm writing up the synopsis of the code received, thanks for the submissions. It's been fun. :D Leaderboard update: updated at 1/7/2009 20:30 GMT, opps missed pauli's 75-byte PHP solution, corrected
Build a man a fire, warm him for a day, Set a man on fire, warm him for the rest of his life.
Joined: 11/11/2006
Posts: 1235
Location: United Kingdom
I would participate, but it seems due to your arbitrary selection of languages you have cut out any languages I know :(
<adelikat> I am annoyed at my irc statements ending up in forums & sigs
Former player
Joined: 12/5/2007
Posts: 716
As I was just about to send you some code... the PM system eats out &lt; and &gt; :/
Experienced player (623)
Joined: 11/30/2008
Posts: 650
Location: a little city in the middle of nowhere
Just learned something: python is incredibly easy to learn. Sending you code in about 10 mins. EDIT: I have a question: can the output be 1.0, 2.0, 3.0, 4.0 ect. I made my own "prime" function and it turns out I can use less characters if it prints to one decimal place.]
Measure once. Cut twice.
Banned User
Joined: 3/10/2004
Posts: 7698
Location: Finland
If it's done in C, must it be standard-compliant, or is it enough that it compiles with gcc?
Experienced player (623)
Joined: 11/30/2008
Posts: 650
Location: a little city in the middle of nowhere
For brevity and execution speed, this challenge is for only numbers up to 1000. You may use any of the following (partially arbitrarily chosen) languages: a) perl b) php c) python d) ruby
you can't use C
Measure once. Cut twice.
Former player
Joined: 12/5/2007
Posts: 716
Warp wrote:
If it's done in C, must it be standard-compliant, or is it enough that it compiles with gcc?
I think GCC is pretty standard compliant, isn't it? <OmnipotentEntity> ShinyDoofy, if you write a submission in C or pascal I'll accept it. <OmnipotentEntity> provided I can get it to compile and run.
Banned User
Joined: 3/10/2004
Posts: 7698
Location: Finland
ShinyDoofy wrote:
Warp wrote:
If it's done in C, must it be standard-compliant, or is it enough that it compiles with gcc?
I think GCC is pretty standard compliant, isn't it?
gcc supports compiling standard-compliant C. It also supports compiling C from 20 years ago, which looks a bit different. For example, gcc will compile this C "program" just fine: main(){puts("Hello");} Mind you, that's the *entire* program. And it certainly is not standard-compliant (for instance, it lacks the proper #include, the return type of main() as well as its parameter type).
Experienced player (623)
Joined: 11/30/2008
Posts: 650
Location: a little city in the middle of nowhere
that would have been my first program! go easy on me, I've never programmed before.
Measure once. Cut twice.
Joined: 4/25/2004
Posts: 615
Location: The Netherlands
The best PHP I can come up with in an hour or so is 92 91 bytes, 89 88 if you allow <? ?> :p
qfox.nl
Editor, Active player (297)
Joined: 3/8/2004
Posts: 7469
Location: Arzareth
I'll throw in this C++ entry. It sports an example of metaprogramming. In telling the compiler what kind of program we're designing, we're making the compiler carry out the necessary calculations. The resulting program simply prints the results and does no calculations whatsoever. Mind you, this is not very typical C++ programming style. Note that some compilers may have trouble compiling this entry. For instance, it requires a template recursion depth of some 500. (Another topic is Microsoft's C++ compiler (CL version 12.00.8168), which fails to even understand the syntax.)
#include <iostream>
template<int p, int m> struct prime { enum {
    // Handling two iterations at once to overcome compiler limitation
    // with maximum template recursion depth
    result = ((p%m) != 0) && ((p%(m-1)) != 0) && prime<p,m-2>::result
}; };
template<int p> struct prime<p,1> { enum { result = 1 }; };
template<int p> struct prime<p,0> { enum { result = 1 }; };
template<int guess, int value, int i> struct int_sqrt_floor {
    enum { result = int_sqrt_floor<guess-(guess*guess-value)/(2*guess), value, i+1>::result
}; };
template<int guess, int value> struct int_sqrt_floor<guess,value,7> { enum { result = guess }; };
template<int value, int i> struct int_sqrt_floor<0,value,i> { enum { result = 0 }; };
template<int o> struct sieve { enum {
    result = (o==1) || (o%7 && o!=3
                   && !prime<o,int_sqrt_floor<o/2,o,1>::result+1>::result)
}; };
template<int k> struct sieveprint { sieveprint(std::ostream& o) {
    (sieveprint<k-5>(o));
    // loop unrolling to overcome compiler limitation
    // of maximum template recursion depth
    if(sieve<k-4>::result) o << k-4 << ' ';
    if(sieve<k-3>::result) o << k-3 << ' ';
    if(sieve<k-2>::result) o << k-2 << ' ';
    if(sieve<k-1>::result) o << k-1 << ' ';
    if(sieve<k>::result)   o << k   << ' ';
} };
template<> struct sieveprint<0> { sieveprint(std::ostream&) {} };

int main() { (sieveprint<1000>(std::cout)); }
Obviously, the goal of this entry is not to get the smallest filesize. I just posted it for fun.
Active player (356)
Joined: 1/16/2008
Posts: 358
Location: The Netherlands
I like such mini competitions (although I can imagine some ppl will probably put quite some time into it :D) thought I'd write a haskell version of it... I suppose it can be shortened but at the moment I don't have the time to look into it ps. it builds the entire (infinite) list ps2. it's not efficient at all
1:[x|x<-[2..],mod x 7>0,[y|y<-[1..x],mod x y<1]!!1/=x]
edit4: fixed to display with the help of bisqwit tried to make it display the list using map (putStr.show) myList but it doesn't work
TASes: [URL=http://tasvideos.org/Movies-298up-Obs.html]Mr. Nutz (SNES), Young Merlin 100% (SNES), Animaniacs 100% (SNES)[/URL]
Editor, Active player (297)
Joined: 3/8/2004
Posts: 7469
Location: Arzareth
DaTeL237 wrote:
thought I'd write a haskell version of it...
1:[x|x<2>0,[y|y<-[1..x],mod x y<1]!!1/=x]
I tried Haskell first, but I couldn't figure out how to do AND conditions. Also, your code fails to print the result. EDIT: Rest of the post not applicable anymore.
Active player (356)
Joined: 1/16/2008
Posts: 358
Location: The Netherlands
Bisqwit wrote:
EDIT: It fails to compile as well. $ ghc tmp.hs tmp.hs:2:0: parse error (possibly incorrect indentation) EDIT 2: Fails to honor the mission goals too. It should exclude numbers divisible by 7.
yeah sorry, the code wouldn't be displayed properly so part of it got 'removed' you're right about the result not being displayed though... I don't know how to do it in haskell :shame:
TASes: [URL=http://tasvideos.org/Movies-298up-Obs.html]Mr. Nutz (SNES), Young Merlin 100% (SNES), Animaniacs 100% (SNES)[/URL]
Editor, Active player (297)
Joined: 3/8/2004
Posts: 7469
Location: Arzareth
DaTeL237 wrote:
yeah sorry, the code wouldn't be displayed properly so part of it got 'removed'
I sent you a private message, but since you aren't reading it... might as well say it here for the benefit of others as well. Do this: [V] Disable HTML in this post This lets phpBB understand that when you are posting < and >, you don't mean a HTML tag, and it won't try to sanitize them. While you are at it, you might go to your profile page and set the HTML setting disabled by default, since it's very rare that you actually need it and since the inconvenience with posts containing < and > mingled is usually greater than is the inconvenience of having to uncheck the box when you do want to use HTML markup.
Player (36)
Joined: 9/11/2004
Posts: 2630
Raiscan wrote:
I would participate, but it seems due to your arbitrary selection of languages you have cut out any languages I know :(
Raiscan, you may submit in any language. I just have a separate category for those four.
Build a man a fire, warm him for a day, Set a man on fire, warm him for the rest of his life.
arflech
He/Him
Joined: 5/3/2008
Posts: 1120
Maple should be a breeze, something like print "1"; for (n=4..1000) if (!isprime(n) and n%7!=0) then print " "+n; fi rof Well that or anything else with primality checking in its standard library (Mathematica, Matlab, MathCad)...
i imgur com/QiCaaH8 png
Active player (333)
Joined: 11/25/2004
Posts: 75
I don't know enough Perl to stand a chance, but I do know some Python. Here's 118 chars:
import sys
w=sys.stdout.write
w('1')
for i in range(1001):
 if i%7!=0 and any([i%n==0 for n in range(2,i)]):w(' %d'%i)
Currently working on: SNES Star Fox, Level 3 (100%, published) SNES Star Fox, Level 2 (33%, after Sector X) SNES Star Fox 2, Expert mode (100%, published)
Player (36)
Joined: 9/11/2004
Posts: 2630
qFox wrote:
The best PHP I can come up with in an hour or so is <strike>92</strike> 91 bytes, <strike>89</strike> 88 if you allow <? ?> :p
I allow anything at all as long as it parses correctly and gives the expected output.
Build a man a fire, warm him for a day, Set a man on fire, warm him for the rest of his life.
Player (36)
Joined: 9/11/2004
Posts: 2630
YtterbiJum wrote:
I don't know enough Perl to stand a chance, but I do know some Python. Here's 118 chars:
snip
Please refrain from posting code in a major category until the contest is over. Unless you really want to share it with everyone. *yoink* ;D
Build a man a fire, warm him for a day, Set a man on fire, warm him for the rest of his life.
Active player (333)
Joined: 11/25/2004
Posts: 75
Oh believe me, I'd be happy if people improved on my code. :D
Currently working on: SNES Star Fox, Level 3 (100%, published) SNES Star Fox, Level 2 (33%, after Sector X) SNES Star Fox 2, Expert mode (100%, published)
Editor, Active player (297)
Joined: 3/8/2004
Posts: 7469
Location: Arzareth
qFox wrote:
The best PHP I can come up with in an hour or so is <strike>92</strike> 91 bytes, <strike>89</strike> 88 if you allow <? ?> :p
I got 134, under the condition that it must run warning-free even with E_ALL error reporting level and short tags disabled. For the record, I also did Ruby in 79 and Python in 93... (Though the Ruby one has trailing space and the Python one has extra delimiters.)
Experienced player (623)
Joined: 11/30/2008
Posts: 650
Location: a little city in the middle of nowhere
I believe this is below 118 characters:(python) I'm not going to enter this because it is almost a direct copy of Ytterboiwhatever's code. I used the "KISS" theory. Undoubtedly it can be improved if "import" is used, but I know too little about python to use it efficiently.
d='1'
for x in range(1001):
 if x%7!=0 and any([x%f==0 for f in range(2,x)]):d=d+' '+str(x)
print d
Measure once. Cut twice.
Player (36)
Joined: 9/11/2004
Posts: 2630
There is a reason why he used sys.stdout.write. ;)
Build a man a fire, warm him for a day, Set a man on fire, warm him for the rest of his life.
Experienced player (623)
Joined: 11/30/2008
Posts: 650
Location: a little city in the middle of nowhere
it still works and it's shorter, so why not? EDIT: i'm an idiot:
EDIT: Clarification, output is expected to STDOUT, not to a file.
Measure once. Cut twice.