473,394 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to calculate the missing number from an array?

Suppose I have an array
my @arr = ( 1,4);

I need to have the missing numbers:
my @res = ( 2,3,5);

How to calculate this easy from @arr ?

Best Regards,
Ton
Oct 9 '05 #1
2 5367
bdj
Hi Ton!
Write an function that convert your array to an hash and compare the hashes.
/Greetings
Bjørn

"Ton 't Lam" <to**@nospam.nl> skrev i en meddelelse
news:vM********************@casema.nl...
Suppose I have an array
my @arr = ( 1,4);

I need to have the missing numbers:
my @res = ( 2,3,5);

How to calculate this easy from @arr ?

Best Regards,
Ton

Oct 10 '05 #2
Thanks for the pointer.

my @tmp = ( 1, 3, 4);
my %hash = map { $_ => 1 } @tmp;
foreach $i ( 1..5) {
if ( ! defined @hash{$i} ) {
# print $i,"\n";
push @res, $i;
}
}
print @res,"\n";

Best Regards,
Ton

bdj wrote:
Hi Ton!
Write an function that convert your array to an hash and compare the hashes.
/Greetings
Bjørn

"Ton 't Lam" <to**@nospam.nl> skrev i en meddelelse
news:vM********************@casema.nl...
Suppose I have an array
my @arr = ( 1,4);

I need to have the missing numbers:
my @res = ( 2,3,5);

How to calculate this easy from @arr ?

Best Regards,
Ton


Oct 11 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Phil Powell | last post by:
Relevancy scores are normally defined by a MySQL query on a table that has a fulltext index. The rules for relevancy scoring will exclude certain words due to their being too short (minimum...
11
by: David | last post by:
I am learning plsql. I would like to run a stored procedure to calculate my bank account value by predicted 10% annual growth rate. Below is my plsql that is having problems. Your help is highly...
53
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is...
4
by: Jan Szymczuk | last post by:
I'm creating an MS Access 2000 database where I have a number of people entered using simple basic fields, Surname: SMITH Forenames: John DoB: 09/09/1958 Age:...
4
by: Angus Comber | last post by:
Hello If I do this: struct mystruct { long nKey; char szItem; };
6
by: Herrcho | last post by:
in K&R Chapter 6.3 it mentions two methods to calculate NKEYS. and points out the first one which is to terminate the list of initializers with a null pointer, then loop along keytab until the...
9
by: Harsha Srinath | last post by:
Athough this might not be directly relayed to C syntax, I thought some of you may find this an interesting problem :- 1.One number, in an array integers from 1 to 1,000,000 is present twice. How...
8
by: khosrow | last post by:
I want to calculate the nth root of an integer which is so big that can not even saved in unsigned long long. I've found a way to calculate the 2nd root but it can not be used for other. (I can read...
3
by: supperham | last post by:
hi: can sone one tell me how to use fedex web service in php to calculate shipping fee? i already have fedex account and 4 keys used to test application Test...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.