LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-13-2022, 09:07 AM   #16
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,736
Blog Entries: 13

Rep: Reputation: 4784Reputation: 4784Reputation: 4784Reputation: 4784Reputation: 4784Reputation: 4784Reputation: 4784Reputation: 4784Reputation: 4784Reputation: 4784Reputation: 4784

The points people are trying to drive home are:
  • Debug techniques are important to learn, there are multiple methods and they each benefit you. The old printf() can only take you so far.
  • Actually read the code you've written. Consider that you may possibly be making assumptions about how certain sections and library calls work. Review your code to determine if you fully understand every line you wrote and every return from library calls as well as have called those functions properly.
  • There are several sources to check and confirm your interim work: valgrind, clang, compiler warnings and errors and increased scrutiny by optional compilation flags, and the ability to run, freeze execution, and examine variables.
 
Old 11-13-2022, 11:58 AM   #17
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 10,701

Rep: Reputation: 5062Reputation: 5062Reputation: 5062Reputation: 5062Reputation: 5062Reputation: 5062Reputation: 5062Reputation: 5062Reputation: 5062Reputation: 5062Reputation: 5062
Quote:
Originally Posted by AlinaC View Post
I didn't get what you intended to say with this phrase. Was it intentionally rude - or you just was asking to explain what this line of code was intended to do?
https://en.wikipedia.org/wiki/Rubber_duck_debugging
 
Old 11-13-2022, 12:22 PM   #18
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,387
Blog Entries: 1

Rep: Reputation: 1665Reputation: 1665Reputation: 1665Reputation: 1665Reputation: 1665Reputation: 1665Reputation: 1665Reputation: 1665Reputation: 1665Reputation: 1665Reputation: 1665
Off: now I think my idea to make elements positive by adding a constant value was wrong... So right now I think we have to calculate the n(n-1)/2 interval-sums, then perform a sort to find the duplications.
 
Old 11-13-2022, 02:37 PM   #19
GazL
LQ Veteran
 
Registered: May 2008
Distribution: CRUX 3.7
Posts: 6,568

Rep: Reputation: 4668Reputation: 4668Reputation: 4668Reputation: 4668Reputation: 4668Reputation: 4668Reputation: 4668Reputation: 4668Reputation: 4668Reputation: 4668Reputation: 4668
I find the exercise a little conceptually odd, and I don't fully get this concept of "pairs" rather than just reporting the number of duplicate results, but my first run using the input from the example gives the same results as described in OPs description, so I assume I've understood the goal correctly.
Code:
$ time -p (echo "1 5 2 4 2 2 2" | ./sum_range )
Input items: 7
Range:  0..1: sum = 6
Paired: 0..1 ~ 2..3: sum = 6
Paired: 0..1 ~ 3..4: sum = 6
Paired: 0..1 ~ 4..6: sum = 6
Range:  0..2: sum = 8
Paired: 0..2 ~ 2..4: sum = 8
Paired: 0..2 ~ 3..5: sum = 8
Range:  0..3: sum = 12
Paired: 0..3 ~ 2..6: sum = 12
Range:  0..4: sum = 14
Range:  0..5: sum = 16
Range:  0..6: sum = 18
Range:  1..2: sum = 7
Range:  1..3: sum = 11
Range:  1..4: sum = 13
Range:  1..5: sum = 15
Range:  1..6: sum = 17
Range:  2..3: sum = 6
Paired: 2..3 ~ 3..4: sum = 6
Paired: 2..3 ~ 4..6: sum = 6
Range:  2..4: sum = 8
Paired: 2..4 ~ 3..5: sum = 8
Range:  2..5: sum = 10
Paired: 2..5 ~ 3..6: sum = 10
Range:  2..6: sum = 12
Range:  3..4: sum = 6
Paired: 3..4 ~ 4..6: sum = 6
Range:  3..5: sum = 8
Range:  3..6: sum = 10
Range:  4..5: sum = 4
Paired: 4..5 ~ 5..6: sum = 4
Range:  4..6: sum = 6
Range:  5..6: sum = 4
Total Ranges: 21
Total Paired: 12
real 0.00
user 0.00
sys 0.00
However, my simple solution doesn't scale well:
Code:
$ time -p ( seq 1 100| ./sum_range | grep Total )
Total Ranges: 4950
Total Paired: 4342
real 0.02
user 0.02
sys 0.00
$ time -p ( seq 1 200| ./sum_range | grep Total )
Total Ranges: 19900
Total Paired: 21302
real 0.24
user 0.24
sys 0.00
$ time -p ( seq 1 400| ./sum_range | grep Total )
Total Ranges: 79800
Total Paired: 100903
real 3.50
user 3.49
sys 0.01
$
 
Old 11-13-2022, 07:09 PM   #20
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 10,701

Rep: Reputation: 5062Reputation: 5062Reputation: 5062Reputation: 5062Reputation: 5062Reputation: 5062Reputation: 5062Reputation: 5062Reputation: 5062Reputation: 5062Reputation: 5062
Quote:
Originally Posted by AlinaC View Post
I've read some articles on Internet and it looks like dictionary can be a better structure to use for this purpose. (I need to check every item in an array and create a list of unique numbers/sums that are present in this array; each number/sum to be associated with the frequency).

Do you think dictionary will be a good choice for that? I basically need to store pairs int->int, specifically sum(a number stored in an array item) -> frequency (how many times this sum was contained in different array items).
Yes Although you'd probably call your implementation a hash table (means the same thing).
 
Old 11-17-2022, 03:40 PM   #21
AlinaC
LQ Newbie
 
Registered: Nov 2022
Posts: 6

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by boughtonp View Post
It's a reference to a common debugging technique - instead of asking a colleague for help, you first describe the issue to a rubber duck and imagine it responding with questions as that co-worker might, which you then answer.

Frequently, the action of describing a problem and considering common questions is enough to resolve an issue, but even when it's not it means you've done some basic diagnostic steps that allow you to rule certain things out before taking the issue to someone who isn't a duck.

Thank you for explaining! However before posting a question, I've talked already to myself, my friends from the Uni, and even my mom so this condition was fulfilled )
 
Old 11-17-2022, 06:22 PM   #22
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 2,983

Rep: Reputation: 2120Reputation: 2120Reputation: 2120Reputation: 2120Reputation: 2120Reputation: 2120Reputation: 2120Reputation: 2120Reputation: 2120Reputation: 2120Reputation: 2120

Yeah, but how many of those are ducks?


Anyway, not clear on the current status of the thread... do you still have an outstanding memory leak, or a different issue, or is it solved now?

 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
why different signals send to programs that exceeded memory limit set by setrlimit()? lonelycorn Programming 2 09-02-2010 10:03 PM
Simple C++ Program: Program Compiles But Won't Run (Segmentation Fault) violagirl23 Programming 3 01-09-2008 01:09 AM
yast segmentation fault, system freezing - nvidia driver at fault? BaltikaTroika SUSE / openSUSE 2 12-02-2005 10:34 AM
Memory Leak when using memory debugging C program on SuSE SLES8 babalina Linux - Distributions 0 10-06-2003 10:39 AM
child pid xxxxx exit signal File size limit exceeded (25)" problem. bisbane Linux - General 1 10-31-2002 05:35 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration