Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Java&Sepples Challenge

Name: Anonymous 2008-08-02 15:56

Okay, here is the challenge.
The first one after me creates a very easy problem. The first person to post a working solution to that problem with either Java or C++ posts another problem but this time slightly more difficult then the previous and so on.

Name: Anonymous 2008-08-02 15:58

For a set of integers S, is there a non-empty subset that sums to N.

Name: Anonymous 2008-08-02 15:59

Challenge: Create an application that will delete this thread and permanently ban the thread starter.

Name: Anonymous 2008-08-02 16:15

>>3
If you don't want to participate in a bit of fun, STFU and DIAF. You can probably don't program Hello World in QBasic, shitcock.

Name: Anonymous 2008-08-02 16:16

>>2
need more info and example plese.

Name: Anonymous 2008-08-02 16:18

>>4
YHBT.

Name: OP 2008-08-02 16:20

Oh, and start with some very easy. Like "make a calculator with operations +/-///* of two integers.". Not subset sum problem.

Name: Anonymous 2008-08-02 16:27

>>7
Oh, and start with some very easy. Like "make a calculator with operations +/-///* of two integers.". Not subset sum problem.
Is this the best Java or Sepples `programmers' can do?

Name: Anonymous 2008-08-02 16:28

Problem the first: Write a recursive factorial in HASKELL.

Name: Anonymous 2008-08-02 16:30

Problem: There's a bug in OP's assignment, which leads to an infinite loop of exactly two problems. Find it.

Name: Anonymous 2008-08-02 16:31

>>8
I would classify the calculator as more easy. But it is my personal opinion.
The thing is, this should get gradually more difficult with each challenge. Where the fun is 1) solve the problem 2)make a new, only slightly more difficult problem. But with so many trolls and idiots here, I better go to /code/.

Name: 8 2008-08-02 16:34

>>11
But with so many trolls and idiots here, I better go to /code/.
Yeah, I think that is a good idea.

Name: Anonymous 2008-08-02 16:38

>>12
I wanted to point out the same thing when I read that post.

Name: Anonymous 2008-08-02 16:57

>>2
#include <stdio.h>

static int subset_sum_p_helper(int target, const int *set, int length, int nonempty)
{
    if(length < 0)
        return 0;
    if(! length && nonempty && ! target)
        return 1;
    if(subset_sum_p_helper(target-*set, set+1, length-1, 1))
        { printf("+ %d ", *set); return 1; }
    return subset_sum_p_helper(target, set+1, length-1, nonempty);
}

static int subset_sum_p(int target, const int *set, int length)
{
    if(subset_sum_p_helper(target, set, length, 0))
        { printf("= %d\n", target); return 1; }
    return 0;
}

int main(void)
{
    const int set[] = {1, 3, -5, -10, 3};
    return subset_sum_p(0, set, sizeof(set) / sizeof(int));
}


VALID C99 / SEPPLES POLYGLOT
Increasing the difficulty: improve subset_sum_p to run in O(length2) time.

Name: Anonymous 2008-08-02 17:01

import Data.List (delete)

combinations [] = [[]]
combinations (x:xs) = map (x:) xs' ++ xs'
  where xs' = combinations xs

subsetsum n = any ((== n) . sum) . delete [] . combinations

Name: Anonymous 2008-08-02 17:28

>>15
combinations [] = [[]]
combinations (x:xs) = xs' ++ map (x:) xs'
  where xs' = combinations xs

subsetsum n = any ((== n) . sum) . tail . combinations

Name: Anonymous 2008-08-02 17:36

>>16
Still O(2|S|)

Name: ThE_DaRkNeSs[MOD] 2008-08-02 17:39

I’ve removed content from this thread because Trolling, Baiting and Flaming are a violation of the Code of Conduct. You can review the Code of Conduct here: http://www.yhbt.net

Name: Anonymous 2008-08-02 18:03

>>18
[code]:\[/code]

Name: Anonymous 2008-08-02 22:13

>>19
lol escaped

Name: Anonymous 2008-08-03 0:04

Name: Anonymous 2011-01-31 21:19

<-- check em dubz

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List