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

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?

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