Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buggy code in the correct directory GENERATE_INTEGERS #2

Closed
BEbillionaireUSD opened this issue Dec 11, 2024 · 5 comments
Closed

Buggy code in the correct directory GENERATE_INTEGERS #2

BEbillionaireUSD opened this issue Dec 11, 2024 · 5 comments

Comments

@BEbillionaireUSD
Copy link

BEbillionaireUSD commented Dec 11, 2024

Content in the src/java/humaneval/correct is:

// Given two positive integers a and b, return the even digits between a
// and b, in ascending order.

// For example:
// generate_integers(2, 8) => [2, 4, 6, 8]
// generate_integers(8, 2) => [2, 4, 6, 8]
// generate_integers(10, 14) => []

public class GENERATE_INTEGERS {
    public static ArrayList<Integer> generate_integers(int a, int b) {
        int lower = Math.max(2, Math.min(a, b));
        int upper = Math.min(8, Math.max(a, b));

        ArrayList<Integer> result = new ArrayList<Integer>();
        for (int i = lower; i <= upper; i += 1) {
            if (i % 2 == 0) result.add(i);
        }
        return result;
    }
}

The code is faulty, yet its corresponding buggy version is correct. The right one and the wrong one are reversed.
The test code is also faulty.

@ZodPSC
Copy link

ZodPSC commented Dec 11, 2024

hm...
GENERATE_INTEGERS.generate_integers(2,8); //[4, 6]
GENERATE_INTEGERS.generate_integers(8,2); //[4, 6]
GENERATE_INTEGERS.generate_integers(7,1); //[2, 4, 6]

        int lower = Math.min(a, b);
        int upper = lower == a ? b : a;

        ArrayList<Integer> result = new ArrayList<Integer>();
        for (int i = lower + 1; i < upper; i += 1) {
            if (i % 2 == 0) result.add(i);
        }
        return result;

@andre15silva
Copy link
Member

Hi!

Thanks for reporting this problem. Could you open a PR to fix this?

Also, please note that we do not maintain this benchmark. This is simply a fork of the original repo (https://github.com/lin-tan/clm)

@ZodPSC
Copy link

ZodPSC commented Dec 11, 2024

#3

@ZodPSC
Copy link

ZodPSC commented Dec 11, 2024

I have an error when extracting that archive. so I corrected the sources here and created a pull request.

@BEbillionaireUSD
Copy link
Author

Thanks for your discussion. I think I misunderstood the original description. I guess "even digits" are defined as [0, 2, 4, 6, 8], so if the lower bound is larger than 8, then the function should return an empty list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants