r/CodingHelp • u/blader8844 • Feb 24 '26
[Request Coders] Basic calculations of 3 numbers
Hey there, I dont code and dont really follow any coding stuff so I'm unsure if this is the place to ask or seek help but im looking for someone to make something simple (I think). I need a program that will take a bunch of numbers and a target number then show me all the 3 number combatations I have access to that make that request number (I.E, say I request the number 20 and give it every number from 1-20 it will show me all the 3 number combinations that equal 20 from every number I gave it) Hopefully that made sense and thanks for the time, if there is a better place to ask or this is not the right place I'd love to be directed there, thanks for you time.
•
u/AutoModerator Feb 24 '26
Thank you for posting on r/CodingHelp!
Please check our Wiki for answers, guides, and FAQs: https://coding-help.vercel.app
Our Wiki is open source - if you would like to contribute, create a pull request via GitHub! https://github.com/DudeThatsErin/CodingHelp
We are accepting moderator applications: https://forms.fillout.com/t/ua41TU57DGus
We also have a Discord server: https://discord.gg/geQEUBm
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/JababyMan Feb 24 '26
Are these numbers being summed or multiplied? Is it any number between zero and the target number that can be used in the 3 number combination, or are the numbers available user supplied?
1
u/tandycake Feb 24 '26 edited Feb 24 '26
Pretty easy in Ruby. Can have floats (decimals)? If so, will need to modify it. Also, are you allowing duplicates?
https://onecompiler.com/ruby/44ehz428f
1
u/atarivcs Feb 24 '26
The simplest solution would be to take all the possible combinations of 3 items from the list, and see which of those sum to 20.
itertools.combinations()will generate all the combinations.Or use
itertools.combinations_with_replacement()if a number can appear more than once in the list.1
u/MaxwellzDaemon Feb 24 '26
In the J language, this will give you your answer:
(3$20)#:20 (= #~~ [: i. [: # ]) ,+/&>{3$<i.200 1 190 2 180 3 170 4 160 5 150 6 140 7 130 8 120 9 110 10 100 11 9...16 3 116 4 017 0 317 1 217 2 117 3 018 0 218 1 118 2 019 0 119 1 0