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:
Anonymous2008-09-27 6:06
(x % 50) == 0
% is the modulo operator
Name:
Anonymous2008-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:
Anonymous2008-09-27 6:10
Simple. Use java.lang.Math
cos(number/50.0)
if this is -1 or 1 it is good
Name:
Anonymous2008-09-27 6:13
No
do
if ((number/50 - floor(number/50)) == 0)
{
System.out.print("It is a multiple of 50");
}
Name:
Anonymous2008-09-27 6:48
Do this. You will get extra marks for use of the operator -->.
>>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:
Anonymous2008-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.)
>>17
you think that's elegant you should see my fibonacci
Name:
Anonymous2008-09-27 17:43
FUCK OFF HASKELL FUCK OFF
Name:
Anonymous2008-09-27 17:54
Read SICP
Thread over
Name:
Anonymous2008-09-27 23:29
multOf50 :: Integral a => a -> Bool
multOf50 n = n `mod` 50 == 0
Name:
Anonymous2008-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:
Anonymous2008-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:
Anonymous2008-09-28 13:16
>>24 multOf50 :: (Num a, Ord a) => a -> Bool
multOf50 n = until (< 50) (subtract 50) n == 0 OPTIMIZED
Name:
Anonymous2008-09-28 13:43
multOf50 :: Int -> Bool
multOf50 n = cycle (True: replicate 49 False) !! n
>>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.