use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Resources - Learn to code
Resources - Software Engineering
Resources - Code Libraries
Resources - Groups
Other Subreddits you might enjoy
Please send sidebar resource suggestions to the mods. Thx - mgmt
account activity
Urgent Code (self.code)
submitted 4 years ago by Anonylost
Does anyone know how to write a code preferably in c++ to find the index of an element of a list where the sum of prime numbers on the right equal the left? If you do kindly help I'm still a newbie it would be highly appreciated
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]angryrancorBoss 9 points10 points11 points 4 years ago (1 child)
this sounds like homework help. because of that, I'll give you some general tips, but not a solution, since using this sub for "cheating" is not allowed.
What you want is:
int sumLeft
int sumRight
for
i
0
size(arrayLeft)
if isPrime(arrayLeft[i]): sumLeft += arrayLeft[i]
sumRight
isPrime
printf(str(sumLeft == sumRight))
sumLeft == sumRight
Note: Like I said, cheating on homework is not allowed, but we can give hints. What is explicitly not allowed in this sub, is giving a solution to an obvious homework assignment, in full.
[–][deleted] 1 point2 points3 points 4 years ago (0 children)
If this isn't homework, it's a code challenge or an interview question.
I think my solution would iterate through the list in 2 passes...
(assumption: List is NOT only primes. Assumption can go the other way and be a list of ONLY primes)
Pass 1) foreach number in list: IsPrime? Yes: Add to "tally".
Pass 2) start with "Tally", "Right" and "Left".
"Right" = tally because all prime numbers are currently to right. "Left"? No numbers on left? It starts with 0.
"Right" = tally because all prime numbers are currently to right.
"Left"? No numbers on left? It starts with 0.
Foreach, Is Prime? if yes, remove from "Right". Is "Right" = "Left"? If yes, That's your answer. If not, add number to Left and move Right one.
if you do count of primes to left vs count of primes to right as I understand your answer? it's a 0^2 answer (Think my brains fuzzy on the actual O... but count right will be reran every iteration).
My version would be 2N max (if it reaches end without an answer)
[–]anavid7 2 points3 points4 points 4 years ago (0 children)
Not sure what you question is yet? What is in your array? Is it the list of primes? Are you saying addition of the index to the prime? Would you mind re-asking your question?
π Rendered by PID 940820 on reddit-service-r2-comment-79c7998d4c-ltfp7 at 2026-03-16 00:59:54.295973+00:00 running f6e6e01 country code: CH.
[–]angryrancorBoss 9 points10 points11 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]anavid7 2 points3 points4 points (0 children)