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

Pages: 1-4041-

What Am I Doing Wrong?

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;
}

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

Name: Anonymous 2008-05-22 22:43

>>1
Posting here. /pr/ is that way --------->

Name: Anonymous 2008-05-22 22:49

You can't be serious.

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 ----@

Name: Anonymous 2008-05-23 0:53

>>5
More like: ...^...

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

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.

Name: Anonymous 2008-05-23 4:38

scoreTest a@(x:y:xs) | x > y = False
                     | otherwise = scoreTest (tail a)
scoreTest _ = True

Name: Anonymous 2008-05-23 4:39

oops

scoreTest (x:y:xs) | x >= y = False
                   | otherwise = scoreTest xs
scoreTest _ = True

Name: Anonymous 2008-05-23 4:39

fucking xorg copypaste

scoreTest a@(x:y:xs) | x > y = False
                     | otherwise = scoreTest (tail a)
scoreTest _ = True

Name: Anonymous 2008-05-23 8:46

>>11
Please explain the @ witchery.

Name: Anonymous 2008-05-23 10:13

>>12
you best be joking, nigger.

Name: Anonymous 2008-05-23 10:30

import Control.Monad.Instances

notDecreasing = null . filter (<0) . (zipWith (-) =<< tail)

Name: Anonymous 2008-05-23 10:33

Even better.

import Control.Monad.Instances

notDecreasing = and . (zipWith (>=) =<< tail)

Name: Anonymous 2008-05-23 11:03

>>13
I am not.

Name: Anonymous 2008-05-23 12:03

>>16
you best be joking, cracka.

Name: Anonymous 2008-05-23 12:23

>>1
read that as javabloat.com

Name: Anonymous 2008-05-23 13:57

>>18
read that as javabat.com

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

Name: Anonymous 2008-05-23 15:54

Please explain the @ (or give link).

Name: Anonymous 2008-05-23 16:12

It's the ``commercial at'' symbol. It's commonly used in email addresses.

Name: Anonymous 2008-05-23 16:45

Please explain the @ in Haskell (or give link).

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.

Name: Anonymous 2008-05-23 17:14

>>24
How would you google the @ symbol, hm?

Name: Anonymous 2008-05-23 17:37

>>25
It wouldn't, that's why I said lrn2google.

http://www.google.com/search?q=haskell+pattern+matching

Name: Anonymous 2008-05-23 17:40

>>25
Better yet, lrn2hoogle.

http://haskell.org/hoogle/?q=@

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

Name: Anonymous 2008-05-24 17:40

canBalance (a:b:cs) = a == sum (b:cs) || can ((a + b):cs)
canBalance _ = False

Name: Anonymous 2008-05-24 17:41

canBalance (a:b:cs) = a == sum (b:cs) || canBalance ((a + b):cs)
canBalance _ = False

Name: Anonymous 2008-05-24 18:30

canBalance l = or [a == b| a <- scanl (+) 0 l | b <- scanr (+) 0 l]

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

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;
}

Name: Anonymous 2008-05-24 21:12

>>33
It should return false when scores.length < 2, because there's no even split possible.

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]

Name: Anonymous 2008-05-25 3:24

>>1
lol java

Name: Anonymous 2008-05-25 13:04

>>34
Uh, no
A sequence of zero or 1 integers is in increasing order

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   : (

Name: Anonymous 2008-05-25 13:21

>>32
Now sort it if it isn't ordered.

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.

Name: Anonymous 2008-05-25 20:26

This thread is pig disgusting.

Name: Sgt.Kabukiman╮霨 2012-05-23 6:04

All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy

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