My Math Forum  

Go Back   My Math Forum > Math Forums > Math

Math General Math Forum - For general math related discussion and news


Thanks Tree2Thanks
  • 1 Post By Country Boy
  • 1 Post By skipjack
Reply
 
LinkBack Thread Tools Display Modes
April 28th, 2018, 02:36 PM   #1
Member
 
Joined: Sep 2014
From: Sweden

Posts: 94
Thanks: 0

Question How to describe a programming array mathematically?

Hi! This post is mostly out of curiosity. I have a program that you give a text file with hours and minutes you have worked. Like this:

workedHours.txt
09.30-14.00
09.30-15.00
09.30-14.00
08.30-18.00

And the program automatically calculates the hours and minutes worked. It does that by putting the hours into one array and minutes into an array. So how do you describe these arrays mathematically?

Here is a picture to make it clearer:
http://www.mediafire.com/view/oue81l...428_232906.jpg

Last edited by greg1313; April 28th, 2018 at 05:00 PM.
DecoratorFawn82 is offline  
 
May 3rd, 2018, 04:33 AM   #2
Math Team
 
Joined: Jan 2015
From: Alabama

Posts: 3,261
Thanks: 894

Does "09.30-14.00" mean that a person worked form 9:30 am to 2:00 pm? That is 4 hours and 30 minutes. I "rounded" 9.30 up to 10.00 to get 14.00- 10.00= 4 hours.

Similarly "9.30- 15.00" is 15- 10= 5 hours and 30 minutes, "9.30-14.00" is again 14- 10= 4 hours and 30 minutes, and "8.30- 18.00" is 18- 9= 9 hours and 30 minutes. You array of hours will be "4, 5, 4, 9" and your array of minutes will be "30, 30, 30, 30".
Thanks from DecoratorFawn82
Country Boy is offline  
May 3rd, 2018, 05:38 AM   #3
Global Moderator
 
Joined: Dec 2006

Posts: 19,865
Thanks: 1833

Quote:
Originally Posted by DecoratorFawn82 View Post
So how do you describe these arrays mathematically?
Your arrays are lists of integers. Use a letter to name each list and, if necessary, another letter to specify the length of the lists. Your lists should be equally long (because for each number of hours there is an associated number of minutes), so one letter will suffice to specify their length.

Your program may need to decide what to do if an odd number of times is found for some day. For example, this could be treated as an error in the data. This type of program typically calculates the totals in hours and minutes, so as to avoid the possibility of rounding errors.
Thanks from DecoratorFawn82
skipjack is offline  
June 10th, 2018, 01:46 PM   #4
Member
 
Joined: Sep 2014
From: Sweden

Posts: 94
Thanks: 0

Quote:
Originally Posted by Country Boy View Post
Does "09.30-14.00" mean that a person worked form 9:30 am to 2:00 pm? That is 4 hours and 30 minutes. I "rounded" 9.30 up to 10.00 to get 14.00- 10.00= 4 hours.

Similarly "9.30- 15.00" is 15- 10= 5 hours and 30 minutes, "9.30-14.00" is again 14- 10= 4 hours and 30 minutes, and "8.30- 18.00" is 18- 9= 9 hours and 30 minutes. You array of hours will be "4, 5, 4, 9" and your array of minutes will be "30, 30, 30, 30".
Yeah, that is absolutely correct. I live in Europe so 24-format is used in my program.
DecoratorFawn82 is offline  
June 10th, 2018, 03:54 PM   #5
Math Team
 
Joined: Oct 2011
From: Ottawa Ontario, Canada

Posts: 13,447
Thanks: 946

Quote:
Originally Posted by DecoratorFawn82 View Post
So how do you describe these arrays mathematically?
Describe?
Why isn't your question:
"how is time worked calculated using these 2 arrays"?
Denis is online now  
June 10th, 2018, 04:24 PM   #6
Senior Member
 
Joined: Aug 2012

Posts: 2,076
Thanks: 593

Quote:
Originally Posted by DecoratorFawn82 View Post
So how do you describe these arrays mathematically?
Mathematically, an array is just a function from some set of natural numbers to some set. f(1) = 47, f(2) = 12, f(3) = 87.5, etc. It's just a list of elements. In some programming languages you can index arrays starting from arbitrary values like f(-5). The main thing is that you have a finite index set and a mapping that associates some value to each index. Not very useful in practice, it's mostly useful to build up further abstractions.
Maschke is online now  
June 11th, 2018, 02:17 AM   #7
Senior Member
 
Joined: Apr 2014
From: Glasgow

Posts: 2,132
Thanks: 717

Math Focus: Physics, mathematical modelling, numerical and computational solutions
Quote:
Originally Posted by DecoratorFawn82 View Post
Hi! This post is mostly out of curiosity. I have a program that you give a text file with hours and minutes you have worked. Like this:

workedHours.txt
09.30-14.00
09.30-15.00
09.30-14.00
08.30-18.00

And the program automatically calculates the hours and minutes worked.
It does that by putting the hours into one array and minutes into an array.
That's an odd way of doing it. Most programming languages come with their own Datetime classes for just this sort of problem which are nice to use.

Quote:
So how do you describe these arrays mathematically?

Here is a picture to make it clearer:
File sharing and storage made simple
Let vector of hours be h and vector of minutes be m and specify an index of 2 for a later time than an index of 1, then the duration in minutes is

$\displaystyle \Delta m = 60h_2 + m_2 - (60h_1 + m_1)$

If you want, you can divide the result by 60 and take the floor to get the number of hours worked and the remainder to get the left over minutes.

Last edited by Benit13; June 11th, 2018 at 02:19 AM.
Benit13 is offline  
June 11th, 2018, 09:50 AM   #8
Global Moderator
 
Joined: Dec 2006

Posts: 19,865
Thanks: 1833

Quote:
Originally Posted by DecoratorFawn82 View Post
. . . the program automatically calculates the hours and minutes worked.
Why? Just as a programming exercise?
skipjack is offline  
Reply

  My Math Forum > Math Forums > Math

Tags
array, describe, mathematically, programming



Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Probability of one array containing all numbers of another array. LordLoki Probability and Statistics 2 May 12th, 2016 07:31 AM
Question regarding python programming, specifically Object Oriented Programming mitch08 Computer Science 2 November 28th, 2015 06:51 AM
How to phrase a debt equation mathematically philblakeman Economics 0 October 20th, 2015 05:02 AM
how to support this step mathematically turtlejohn Complex Analysis 0 January 20th, 2010 09:49 PM
mathematically related essay topic gaussrelatz New Users 1 December 31st, 1969 04:00 PM





Copyright © 2018 My Math Forum. All rights reserved.