#-------------------------------------------------------------
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#
#-------------------------------------------------------------



# A = 50x10
# B = 10x40
# C = 40x5
# D = 5x60
#
# 1. ((A%*%B)%*%C)%*%D = (50*10*40) + (50*40*5) + (50*5*60) = 20000 + 10000 + 15000 = 45,000
# 2. (A%*%(B%*%C))%*%D = (10*40*5) + (50*10*5) + (50*5*60) = 2000 + 2500 + 15000 = 19,500  -> OPTIMAL PLAN
# 3. (A%*%B)%*%(C%*%D) = (50*10*40) + (40*5*60) + (50*40*60) = 20000 + 12000 + 120000 = 152,000
# 4. A%*%((B%*%C)%*%D) = (10*40*5) + (10*5*60) + (50*10*60) = 2000 + 3000 + 30000 = 35,000
# 5. A%*%(B%*%(C%*%D)) = (40*5*60) + (10*40*60) + (50*10*60) = 12000 + 24000 + 30000 = 66,000

A = rand(rows=50, cols=10)
B = rand(rows=10, cols=40)
C = rand(rows=40, cols=5)
D = rand(rows=5, cols=60)

E = A %*% B %*% C %*% D

write(E, $1)
