Haskell finding mean of cubes of odd members Any ideas? [closed] - list

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
Please find the mean of cubes of odd members of given list of Int type.
Try to use (.), ($), map, filter or foldl (You should use at least one of them).

I would give you some hints to get you started up:
Use filter function to get the odd members of the given list.
Cube the resultant list using map function.
Find the mean of them by summing the list and dividing it by the length of the list.

The only thing I would add to the other comments and answers is the use of fromIntegral to convert the Int type to Fractional for using the (/) operator.

Related

Check for even or odd [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
Given N amd M how to check whether floor value of N!/M will be even value or odd value where N can go upto 10^5 and M can go upto 10^18.
Please help to check this condition in efficient way.
EDIT
My attempt : I first think of breaking N!=(2^a)(some odd value) and similarly for M but as the odd value of N! can be very large so i was thinking of some better solution.

Calculating large numbers in C++ without external libraries [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I need to write a program that will perform operations on float numbers higher than 10^100.
I can't use any arbitrary precision mathematics libraries that are not included in GCC package by default.
I have NO idea how how to go about it.
Can you point me in the right direction?
You can create a class that can store larger numbers. 12345678 equals to 1234 * 10e4 + 5678.
For large numbers I use string buffers and do manual computation on it. It is much overhead and slow but you get infinite precision.

Obtaining an algorithm [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Let's say I have a variable a and b. Now I want to find a value for c such that the fraction a / c is a positive integer, and where c is as close to b as possible.
For example: a = 100 and b = 30.
In this case I want c to be 25; because a / c is an integer, and c is as close as b for which this holds.
Any ideas how I can program a function in C++ which does exactly this?
Find the factors of a. (search web for methods)
Scan resulting list for minimum difference vs b.
Is this a homework assignment? Either way, think about how you would solve this problem without writing any code. A good algorithm comes from a good design. Break the problem down into pieces and walk through some more examples. For example, how would you solve the problem of determining whether the division results in an integer value? Hint: There is a different operator you could use as opposed to division to achieve this easily. Now, how would you solve the problem of determining what number to start at for c in the algorithm? Do not write any code until you have the pseudocode figured out.

List of lists in scala changing particular elements [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I am given a list of list made of integers. I have to override the toString method to print this list of lists in a particular format.
However, I also need to change every '1' element that is in the list into an 'a.
Remember your list is a list of lists, so you need something like:
list.map(_.map { case 1 => "a"; case x => x})
I think you cannot override a method for the Int class, but you create your own class which inherits from Int and use instances of that class instead.
Here is a way to make your code work. I used x.toString because this returns a List[List[String]]. If you omit it, you'll get a List[List[Any]] which contains strings and integers, rather than all strings.
list.map(_.map { case 1 => "a"; case x => x.toString } )

Is there a "generics-like" feature in C++? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm trying to create a list class in C++ similar to the lists in Java. Is there a way I can have it be able to list whatever object it wants to? The class resizes arrays to create the list, but what I need to do is find out the kind of object that's needed to store.
Yes, C++ has templates that can be used to create generic containers roughly similar to Java generic containers.
While your immediate reaction might be to assume that std::list is similar to a Java list, that would be a mistake. In Java, a list basically just means a sequence. In C++, a std::list is a linked list (which is rarely useful). Most of the time you want to use an std::vector (which is more like Java's ArrayList).
Yes, there is, and it's called Templates