What Am I Doing Wrong?
1
Name:
Anonymous
2008-05-22 22:02
http://javabat.com/prob?id=AP1.scoresIncreasing
public boolean scoresIncreasing(int[] scores) {
boolean increase = true;
for (int i = 1; ((i) < (scores.length + 1)); i++){
if (scores
[i] > scores[i+1]){
increase = false;
}
}
return increase;
}
2
Name:
Anonymous
2008-05-22 22:03
Given an array of scores, return true if each score is equal or greater than the one before. The array will be length 2 or more.
scoresIncreasing({1, 3, 4}) → true
scoresIncreasing({1, 3, 2}) → false
scoresIncreasing({1, 1, 4}) → true
3
Name:
Anonymous
2008-05-22 22:43
>>1
Posting here. /pr/ is that way --------->
4
Name:
Anonymous
2008-05-22 22:49
You can't be serious.
5
Name:
Anonymous
2008-05-23 0:01
>>3
Actually, /pr/ is on another site entirely, and you will require a portal to get there. /pr/ is that way ----@
6
Name:
Anonymous
2008-05-23 0:53
7
Name:
sage
2008-05-23 1:35
if you start from 1 you should be comparing to the preceding spot in the array, not the next spot
8
Name:
Anonymous
2008-05-23 1:48
bool sortedIncr(int[] a) {
for (int i = 1; i < a.size; i++) if (a[i - 1] > a[i]) return false;
return true;
}
No need to keep checking once you've found an element out of order.
9
Name:
Anonymous
2008-05-23 4:38
scoreTest a@(x:y:xs) | x > y = False
| otherwise = scoreTest (tail a)
scoreTest _ = True
10
Name:
Anonymous
2008-05-23 4:39
oops
scoreTest (x:y:xs) | x >= y = False
| otherwise = scoreTest xs
scoreTest _ = True
11
Name:
Anonymous
2008-05-23 4:39
fucking xorg copypaste
scoreTest a@(x:y:xs) | x > y = False
| otherwise = scoreTest (tail a)
scoreTest _ = True
12
Name:
Anonymous
2008-05-23 8:46
>>11
Please explain the @ witchery.
13
Name:
Anonymous
2008-05-23 10:13
>>12
you best be joking, nigger.
14
Name:
Anonymous
2008-05-23 10:30
import Control.Monad.Instances
notDecreasing = null . filter (<0) . (zipWith (-) =<< tail)
15
Name:
Anonymous
2008-05-23 10:33
Even better.
import Control.Monad.Instances
notDecreasing = and . (zipWith (>=) =<< tail)
16
Name:
Anonymous
2008-05-23 11:03
17
Name:
Anonymous
2008-05-23 12:03
>>16
you best be joking, cracka.
18
Name:
Anonymous
2008-05-23 12:23
>>1
read that as javabloat.com
19
Name:
Anonymous
2008-05-23 13:57
>>18
read that as javabat.com
20
Name:
Anonymous
2008-05-23 14:06
>>19
read that as firebat.com
What do you think? Write to me at
Firebat@aol.com , put
www.firebat.com on the Subject line, and send me your comments about the web site. It's been fun putting it together, with the expert help from Network Solutions - especially from Ryan Wisnasky (site design) and Kurt Tiede (logo design). Many "Thanks" to both
Ryan and
Kurt !
Very best to all,
Steve "Firebat" Johnson
21
Name:
Anonymous
2008-05-23 15:54
Please explain the @ (or give link).
22
Name:
Anonymous
2008-05-23 16:12
It's the ``commercial at'' symbol. It's commonly used in email addresses.
23
Name:
Anonymous
2008-05-23 16:45
Please explain the @ in Haskell (or give link).
24
Name:
Anonymous
2008-05-23 16:56
>>23
func list@(x:xs) = ...
is the same thing as
func (x:xs) = let list = (x:xs) in ...
But seriously, lrn2google.
25
Name:
Anonymous
2008-05-23 17:14
>>24
How would you google the @ symbol, hm?
26
Name:
Anonymous
2008-05-23 17:37
27
Name:
Anonymous
2008-05-23 17:40
28
Name:
FUCK
2008-05-24 15:50
Given a non-empty array, return true if there is a place to split the array so that the sum of the numbers on one side is equal to the sum of the numbers on the other side.
canBalance({1, 1, 1, 2, 1}) → true
canBalance({2, 1, 1, 2, 1}) → false
canBalance({10, 10}) → true
29
Name:
Anonymous
2008-05-24 17:40
canBalance (a:b:cs) = a == sum (b:cs) || can ((a + b):cs)
canBalance _ = False
30
Name:
Anonymous
2008-05-24 17:41
canBalance (a:b:cs) = a == sum (b:cs) || canBalance ((a + b):cs)
canBalance _ = False
31
Name:
Anonymous
2008-05-24 18:30
canBalance l = or [a == b| a <- scanl (+) 0 l | b <- scanr (+) 0 l]
32
Name:
Anonymous
2008-05-24 18:43
>>8
public boolean scoresIncreasing(int[] scores) {
int i = 0;
while (i < scores.length - 1)
if (scores[i] > scores[++i])
return false;
return true;
}
OMGOPTIMIZED
33
Name:
Anonymous
2008-05-24 19:58
public boolean isScoresIncr(int[] scores) {
if (scores.length < 2)
return true;
int i=0;
do {
if (scores[i] > scores[++i])
return false;
} while (i < scores.length - 1);
return true;
}
34
Name:
Anonymous
2008-05-24 21:12
>>33
It should return
false when
scores.length < 2, because there's no even split possible.
35
Name:
Anonymous
2008-05-24 21:18
>>31 will give a false positive for
[] and
[0].
canBalance l = or [a == b| a <- scanl1 (+)l | b <- tail $ scanr1 (+) l]
36
Name:
Anonymous
2008-05-25 3:24
37
Name:
Anonymous
2008-05-25 13:04
>>34
Uh, no
A sequence of zero or 1 integers is in increasing order
38
Name:
Anonymous
2008-05-25 13:12
>>37
Yeah, I didn't read the whole thing and thought it was an answer to
>>28 .
i f e e l k i n d o f b a d a b o u t i t : (
39
Name:
Anonymous
2008-05-25 13:21
>>32
Now sort it if it isn't ordered.
40
Name:
Anonymous
2008-05-25 13:28
>>35
Then add patterns for [] and [0]. It's two lines of fucking code, don't rewrite everything.
Newer Posts