Facebook had a mathematics problem which was as thus:-
6/2(1+2) = ?
Answer is 9.
My ancient Casio FX 730P mini computer written exactly as that gives 'error' only.
Now take a look at shell versions, and a python version:-
Are these bugs or is it mandatory in at least these two languages here to have the multiplication operator?
Last edited by wisecracker; 09-14-2016 at 02:27 PM..
Reason: Added the answer.
Multiplication is almost never implicit in a computer language. I don't actually know any which do it implicitly, but they probably exist, maybe math-specific languages and the like.
The overriding issue here is dependant on how the question is written and we are limited if we cannot express fractions easily.
Is it (6/2)*(1+2) with answer 9 or 6/(2*(1+2)) with answer 1. On a question paper, I would expect to see either this:-
p { margin-bottom: 0.1in; line-height: 120%; } 6/2(2+1)
or
p { margin-bottom: 0.1in; line-height: 120%; } 6/2(2+1)
That way we clearly know which it is. How would you know which order is expected in a line of code with an inserted multiplication sign. I suspect it would just go left to right so answer 9 but clarity is required.
Last edited by rbatte1; 09-15-2016 at 05:21 AM..
Reason: Correcting appearance of fractions
I thought like Robin last night, but then had a phone call so did not post and after I forgot..
you see when written like Robin its univoque but as presented in the first post (I find it ambiguous...), is it you should have used extra brackets to make it univoque otherwise, with all same weight you go from left to right?
In all the time I have written code a have assumed that hard coding the multiplication operator was the way to go. I had never even considered implicit multiplication in computer code at all but when I saw the expression in my OP I decided to try it out and true to form the results are there for all to see.
What we take for granted in our thought processes cannot be assumed in computer code.
Multiplication is almost never implicit in a computer language. I don't actually know any which do it implicitly, but they probably exist, maybe math-specific languages and the like.
Julia language understand implicit multiplication:
But, many syntaxe not work (in doc) :
Quote:
Neither juxtaposition of two parenthesized expressions, nor placing a variable before a parenthesized expression, however, can be used to imply multiplication:
julia> (x-1)(x+1)
ERROR: MethodError: objects of type Int64 are not callable
...
julia> x(x+1)
ERROR: MethodError: objects of type Int64 are not callable
...
Both expressions are interpreted as function application: any expression that is not a numeric literal, when immediately followed by a parenthetical, is interpreted as a function applied to the values in parentheses (see Functions for more about functions). Thus, in both of these cases, an error occurs since the left-hand value is not a function.
Regards.
This User Gave Thanks to disedorgue For This Post:
I'm new to playing with the command line on OS X and am puzzled by the response I am getting from the find command. I have a file structure similar to the following
/Volumes/
../Drobo/
../../Pictures/
../../../Image 1/
../../../../Image 1.jpg
../../../../Previews/
../../../../../Image... (2 Replies)
How to create a symbolic link to a command with certain argument?
When I man hexdump, it is said in the man page that "-C Canonical hex+ASCII display...Calling the command hd implies this option". Actually it is. hd equals to hexdump -C.
And then I examined the ln command but find it is a... (5 Replies)
Not sure why solaris couldn't detect the geometry of a hard disk which has a working OS of winxp pro.
Is it due to the different OS that the partition information is stored in different location?
When I type '"format" it is shown as below,
c3d1 < drive type unknown>... (5 Replies)
Hi all,
One disk on my root disk group failed in Veritas Volume manager.
I replaced it with new one, initialized it and placed it with removed one.
it Synchronized plexes and everything is fine. this node was second standby node of Sun cluster. yesterday I had failure on active node with boot... (1 Reply)
#include <iostream.h>
class A
{
public:
void f(void)
{
cout << "hello world \n" ;
}
};
void main()
{
A *a;
a = 0 ;
a->f(); // OOPs...Am I mad? What am I going to do ?
} (1 Reply)
I hava been reading AUPE these days. I really am puzzled with the presentation of real user(group) ID, effective user(group) ID. How do they effect on the execution of process? What's the relationship between them? Appreciate your help. (4 Replies)