r/dailyprogrammer • u/rya11111 3 1 • Jun 08 '12
[6/8/2012] Challenge #62 [easy]
Give the Ullman's Puzzle
Write a function that makes that determination
17
Upvotes
r/dailyprogrammer • u/rya11111 3 1 • Jun 08 '12
Give the Ullman's Puzzle
Write a function that makes that determination
5
u/astrosi Jun 08 '12 edited Jun 08 '12
Python: This seems very short, am I missing something?
3
u/jsnk Jun 08 '12
3
u/eruonna Jun 08 '12
Haskell:
2
u/[deleted] Jun 08 '12 edited Jun 08 '12
Java without error checking on the input...
2
u/tehstone Jun 09 '12
The problem simply asks for testing of the existence of such a subset, not the members of the subset or the total number of possible subsets.
Asking for the total number of possible k-length subsets whose sum is less than t would have been a better challenge imo, and still fairly easy. In fact, xjtian's solution would do just that if it accumulated the matching subsets rather than returning when it finds the first one.
2
u/[deleted] Jun 09 '12
J:
2
u/cdelahousse Jun 09 '12
Javascript:
2
u/xjtian Jun 08 '12 edited Jun 08 '12
I feel like I'm missing something, this feels too easy.
EDIT: YES, I AM MISSING SOMETHING... posting the actual solution in a minute
Here it is... Python:
1
u/luxgladius 0 0 Jun 08 '12
Perl
Output
1
1
u/emcoffey3 0 0 Jun 08 '12
C# with LINQ:
1
u/ixid 0 0 Jun 08 '12
In D:
1
u/Arthree Jun 08 '12
This seems easier than the usual easy challenges...
edit: woops, I missed the part about k... I guess it's not so easy.
1
u/ashashwat Jun 08 '12
This seems very easy unless I missed something. :-/
For a k-element subset to be less than t, we can simple calculate the sum of k-minimums and see if they are less than t, if yes then return True.
Quick hack in python:
1
u/Nohsk Jun 08 '12 edited Jun 08 '12
In C++:
1
u/Steve132 0 1 Jun 08 '12
C++, O(n), 5 lines (not including the test case or includes)
1
u/[deleted] Jun 08 '12
C++, very easy today:
1
u/huck_cussler 0 0 Jun 11 '12
1
u/beltorak Jun 11 '12
Java, with input validation: http://www.syntax-highlighting.com/p/show?id=4964
1
u/bh3 Jun 11 '12
Python:
1
u/loonybean 0 0 Jun 16 '12
Python:
0
u/SwimmingPastaDevil 0 0 Jun 08 '12
Used
itertools.permutations. Not sure if it beats the purpose of the question.0
u/herpderpdoo Jun 09 '12
python, two different implementations:
whats the lowest big Oh for this problem?