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

Pages: 1-4041-

from /b/ plz Help

Name: Anonymous 2008-09-27 6:04

okay I am a starting cs major and I have one little snag

I get most of java so far but have to do:

is some number a multiple of 50

Now I divide the number by 50, Number/50 but dont know what to do after that.  This is due in a noon Saturday and I woke up early to do it can you guys help

Name: Anonymous 2008-09-27 6:06

(x % 50) == 0

% is the modulo operator

Name: Anonymous 2008-09-27 6:08

Okay I came up with this so far for reference

for (int i = 0; i < 100000; i = i + 1)
{if (number == i*50){ 
 System.out.print("It is a multiple of 50");}}


Unfortunately the test program that grades my project says it doesn't work with some values...

help me plz

Name: Anonymous 2008-09-27 6:10

Simple.  Use java.lang.Math

cos(number/50.0)

if this is -1 or 1 it is good

Name: Anonymous 2008-09-27 6:13

No

do

if ((number/50 - floor(number/50)) == 0)
   {
   System.out.print("It is a multiple of 50");
   }

Name: Anonymous 2008-09-27 6:48

Do this. You will get extra marks for use of the operator -->.



int remainder;
while(number-->0) {
  remainder++;
  if(remainder == 50) {
   remainder = 0;
  }
}
if(remainder == 0) {
  System.out.print("Gotcha!");
}

Name: Anonymous 2008-09-27 9:24

DON'THELPHIM !

Name: Anonymous 2008-09-27 9:28

the mod(%) operation is the best at finding if your number is a multiple of 50

Name: Anonymous 2008-09-27 9:29

the mod(%) operation is the best at finding if your number is a multiple of 50

Name: Anonymous 2008-09-27 9:35

the sage (mailo:sage) operation is the best at responding to obvious trolls

Name: Anonymous 2008-09-27 10:48

multOf50 :: Integral a => a -> Bool
multOf50 n =
    if (mod n 50) > 0
    {
         then True;
         else False;
    }

Name: Anonymous 2008-09-27 12:32

back to /b/, please.

Name: Anonymous 2008-09-27 13:49

uhhh good luck with your cs

Name: Anonymous 2008-09-27 16:53

>>11
multOf50 :: Integral a => a -> Bool
multOf50 = (0 ==) . (`mod` 50)

Name: Anonymous 2008-09-27 17:01

>>14
YHBT

Name: Anonymous 2008-09-27 17:03

: mult-of-50 ( n -- ? ) 50 mod zero? ;

Name: Anonymous 2008-09-27 17:05

>>14
That can't be Haskell, it looks almost sensible and not very convoluted at all. Explain the type signature though, wouldn't it just be a -> Bool or something? What's the Integral a => part do?

Name: Anonymous 2008-09-27 17:15

>>17
The Integral a is a constraint upon a. It's necessary here - otherwise, Haskell would not allow the usage of mod upon it, since mod's type is Integral a => a -> a -> a.

(Also, Haskell could infer the type of this function without a problem.)

Name: Anonymous 2008-09-27 17:16

Name: Anonymous 2008-09-27 17:20

>>17
you think that's elegant you should see my fibonacci

Name: Anonymous 2008-09-27 17:43

FUCK OFF HASKELL FUCK OFF

Name: Anonymous 2008-09-27 17:54

Read SICP
Thread over

Name: Anonymous 2008-09-27 23:29

multOf50 :: Integral a => a -> Bool
multOf50 n = n `mod` 50 == 0

Name: Anonymous 2008-09-28 2:43

>>23

multOf50 :: a -> Bool
multOf50 n = n % 50 == 0
             where x % y = if x>=y then (x-y) % y else x

Name: Anonymous 2008-09-28 3:56

src/Main.hs(49,13):
    No instances for (Num a, Ord a)
      arising from use of `%' at src/Main.hs:49:13-18
    Possible fix:
      add (Num a, Ord a) to the type signature(s) for `multOf50'
    In the first argument of `(==)', namely `n % 50'
    In the expression: (n % 50) == 0
    In the definition of `multOf50':
    multOf50 n = (n % 50) == 0
           where
               % x y = if x >= y then (x - y) % y else x

Name: Anonymous 2008-09-28 13:16

>>24
multOf50 :: (Num a, Ord a) => a -> Bool
multOf50 n = until (< 50) (subtract 50) n == 0

OPTIMIZED

Name: Anonymous 2008-09-28 13:43


multOf50 :: Int -> Bool
multOf50 n = cycle (True: replicate 49 False) !! n

Name: Anonymous 2008-09-28 15:16

multOf50 :: Int -> Bool
multOf50 n | n==1 = True
           | n==2 = True
           | n==5 = True
           | n==10 = True
           | n==25 = True
           | n==50 = True
           | otherwise = False

Name: Anonymous 2008-09-28 15:19

>>28
multOf50 :: Int -> Bool
multOf50 n | n==1 = True
           | n==2 = True
           | n==5 = True
           | n==10 = True
           | n==25 = True
           | n==50 = True
           | otherwise = False

Name: Anonymous 2008-09-28 16:23

FUCK OFFFFFFFFFFFFFFFFF

Name: Anonymous 2008-09-28 16:46


multOf50 :: Int -> Bool
multOf50 n | n==0 = True
           | n==50 = True
           | n==100 = True
           | n==150 = True
           | n==200 = True
           | n==250 = True
           | n==300 = True
           | n==350 = True
           | n==400 = True
           | n==450 = True
           | n==500 = True
           | n< 500 = False
           | otherwise = error "multOf50: argument too big"

Name: Anonymous 2008-09-28 18:39

DON'T HELP HIM!!!

Name: Anonymous 2008-09-28 18:45

multOf50 :: (Num a, Enum a) => a -> Bool
multOf50 = (`elem` [0,50..])

Name: Anonymous 2008-09-28 19:20

>>33
Winrar

Name: Anonymous 2008-09-28 20:05

>>33
Beautiful.

Name: Anonymous 2008-09-28 20:31

>>33
FP is superior.

Name: Anonymous 2008-09-28 20:47

>>35,36
It also does not terminate on non-multiples of 50.

Name: Anonymous 2008-09-28 21:25


#!/usr/bin/perl
print "yes" unless (#_ % 5 != 0);

Name: Anonymous 2008-09-28 21:40

sub mult_of_50(@){ return map{ !($_ % 50) } @_ }

Name: Anonymous 2008-09-28 22:50

>>38
Invalid perl code.

>>39
Who puts a return on such a simple expression?

Name: Anonymous 2008-09-29 6:31

>>1
public static void main(String[] args) {
    System.out.println("Yes");
}

Name: Anonymous 2008-09-29 8:52

package org.4chan.dis.prog.1222505434;

public class Idiots extends Object {
  pubic static void main(int argc, char* argv) {
    int input = Integer.parseInt(argv[1]);
    if (isMultipleOf50(input)) {
      std::cout << " Yes";
    } else {
      throw new IllegalArgumentException("No");
    }
  }

  /* Implemented natively using JNI for performance reasons */
  private static volatile synchronized native void strictfp boolean isMultipleOf50();
}

Name: Anonymous 2008-09-29 9:10

>>42
Using exceptions to control program flow is bad programming practice and results in a large performance hit when used in mission-critical enterprise software.

Name: Anonymous 2008-09-29 9:29

>>43
YHBT

Name: Anonymous 2008-09-29 9:32

org 4chan.dis.prog.1222505434.public;

class Idiots extends Object pubic {
  static void main int(argc char, argv* int) {
    input Integer = parseInt.argv(1[if]);
    isMultipleOf50 (input(std)) {
      cout::Yes << " else";
    } throw {
      new IllegalArgumentException No("Implemented");
    }
  }

  /* natively using JNI for performance reasons private */
  static volatile synchronized native void strictfp boolean isMultipleOf50 package();
}

Name: Anonymous 2008-09-29 10:04

>>45
EXPERT DYSLEXIC PROGRAMMER

Name: Anonymous 2008-09-29 10:07

>>44
YHBMT

Name: Anonymous 2008-09-29 10:37

>>45
I enjoyed this. I think I may have some weird and nerdy programming guro fetish.

Name: Anonymous 2008-09-29 12:00

>>48
Oh do you, Randel?

Name: Anonymous 2008-09-29 12:39

Oh, >>47 is right. IHBMT

Name: Anonymous 2008-09-29 14:19

int number;

if(log(number/50) <= 2) {
    System.out.println("Multiple of 50!");
} else {
    System.out.println("Not multiple of 50!");
}

Name: Anonymous 2008-09-29 14:20

int number;

if(log(number/50) > 2) {
    System.out.println("multiple of 50");
} else {
    System.out.println("not a multiple of 50");
}

Name: Anonymous 2008-09-29 14:23

int number;

if(log(number/50) > 2) {
    System.out.println("multiple of 50");
} else {
    System.out.println("not a multiple of 50");
}

Name: Anonymous 2008-09-29 14:23

lol

Name: Anonymous 2008-09-29 15:58

def mod50(n):
  if n >= 50:
    return mod50(n-50)
  if n < 0:
    return mod50(n+50)
  return (n==50)

Name: Anonymous 2008-09-29 17:27

>>53
actually it should be....

    public static void mult50(int number) {
       
        double logNumDiv50 = Math.log(number/50);
       
        if(logNumDiv50 < 2) {
            System.out.println(number+": multiple of 50");
        } else {
            System.out.println(number+": not a multiple of 50");
        }
    }

Name: Anonymous 2008-09-30 21:06

>>56
one word FORCED IMPLEMENTATION OF CLASSES

Name: Anonymous 2008-10-01 1:06

>>56
fffffuck

THIS IS WHY I LOVE FUNCTIONAL PROGRAMMING

double LogNumDiv50 = bullshit function;


should be a function itself

so it becomes

if ( lugnumdiv50 number < 2)

SO MUCH MORE BEAUTIFUL and DYNAMIC

ImPERATIVE IS PIG DIGUSTING

Name: Anonymous 2008-10-01 2:07

sub mult_of_50{shift=~/[50]0$/}

Name: Anonymous 2008-10-01 3:32

>>59
sub mult_of_50{1>$_[0]%50}

Name: Anonymous 2008-10-01 3:51

>>60
This doesn't use the power of REGULAR EXPRESSIONS
And $_[0] does not look as good as shift does

Name: Anonymous 2008-10-01 3:59

>>61
the power to make the code longer and slower?
and shift%50 doesn't work.

Name: Anonymous 2008-10-01 4:28

>>62
The power to solve problem in not obvious way. Seriously x%50 is too trivial, it doesn't deserve to be posted in this nice thread.

Name: Anonymous 2008-10-01 10:25

>>1
from /b/ import Help?

Name: Anonymous 2008-10-01 17:04

sed 's/^[0-9]*[50]0$/yes/;t;s/.*/no/' <<< "$num"

Name: Anonymous 2008-10-01 17:15

>>61
Thanks for the idea:

#include <string.h>
#include <stdio.h>

int main( int argc, char *argv[] ) {
    if ( argc != 2 ) return 1;
    for ( argc = 0; argc < strlen( argv[1] ); ++argc )
        if ( argv[1][argc] < '0' || argv[1][argc] > '9' )
            return 1;
    argc = strlen( argv[1] ) == 1 ? 2 : strlen( argv[1] );
    return ! ( ( argv[1][argc-2] == '0' || argv[1][argc-2] == '5' ) && ( argv[1][argc-1] == 0 || argv[1][argc-1] == '0' ) );
}

Name: Anonymous 2008-10-02 6:49

>>66
You damn fool! You're calling strlen twice on the same string! And you're iterating over the result anyway!

Name: Anonymous 2008-10-02 7:54

>>67
One word, common subexpression elimination and loop fusion, thread over.

Name: Anonymous 2008-10-02 8:01

Wait... Did we all just get trolled, or what?

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