Program that counts all the possible PARTS of a number [closed] - math

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Alright, so one of my friends challenged me to get this done, but I just can't get very far....
What he asked me to do is to make a program that shows and counts ALL the possible parts of an entered number.
Example for 5:
1+1+1+1+1
2+1+1+1
3+1+1
4+1
5
3+2
2+2+1
I would like the program to be written in either C++ or some pseudocode, I wouldn't mind for either.
Anticipated thanks to you all!
Edit: Not duplicate. I requested a solution in c++; and the other one is in Python. Also, my question asks for ALL possible parts that added return the initial number.

For non zero partitions ( imagine boolean separators in array of 1)
2 ** (n-1)
This list would include both 2 + 3 and 3 + 2.
If you allow 0 then infinite.

Related

I need a faster way of doing this instead of using for loops in R [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 12 months ago.
Improve this question
So what I'm trying to do is add a column of 0's to this data frame, but if any of the rows has the code "h353" within any of the columns in that row, then I want that row to have a 1 instead of a 0 in the new column. I'm not even sure if the code works as is, but I just know it's going to take forever to run in its current state since the file is pretty large. Any suggestions on how to fix this/make it more efficient?
current code
This should do the job:
dat<-data.frame(x=rep(0,30), y=rep(0,30), z=rep(0,30))
dat[2,2]<-"h353"
dat[15,3]<-"h353"
dat[20,1]<-"h353"
dat$md<-0
for (i in 1:length(dat[1,])) {if (i==1){mdrows<-as.character(dat[,i])=="h353"} else {mdrows<-mdrows|as.character(dat[,i])=="h353"}}
dat$md[mdrows]<-1

Why is 'DO LOOP' missing in 328eForth? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I’m trying to learning Forth directly in an embedded system and using Starting Forth by Leo Brodie as a text. The Forth version I’m using is 328eForth (a port of eforth to the ATmega328) which I’ve flashed into an Arduino Uno.
It appears that the DO LOOP words are not implemented in 328eForth - which puts a kink in my learning with Brodie. But looking at the dictionary using “WORDS” shows that a series of looping words exist e.g. BEGIN UNTIL WHILE FOR NEXT AFT EXIT AGAIN REPEAT amongst others.
My questions are as follows:
Q1 Why was DO LOOP omitted from 328eForth?
Q2 Can DO LOOP be implemented in other existing words? If so, how please and if not why? (I guess there must be a very good reason for the omission of DO LOOP...)
Q3 Can you give some commented examples of the 328eForth looping words?
Q1: A choice was made for a different loop construct.
Q2: The words FOR and NEXT perform a similar function that just counts down to 0 and runs exactly the specified number of times, including zero.
The ( n2 n1 -- ) DO ... LOOP always runs at least once, which requires additional (mental) bookkeeping. People have been complaining
about that as long back as I can remember.
Q3: The 382eforth documentation ForthArduino_1.pdf contains some examples.
Edit: Added some exposé to Q2

Fetch a column value depending on a row number [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have the following df
Case Points
A 2
B 3
C 8
I would the like to fetch the Points of a certain row. So lets say I have a list with rownumbers 2 and 3
rownumbers <- c(2,3)
Then I would like to the fetch the numbers 3 and 8. Could anybody tell me how to do this?
Try:
mydata[rownumbers,"Points"]
This answered in comments so I made it as community wiki

Maximum factorial that is formed by three digits? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Number of digits that are present in the maximum number that is formed using three digits?
Maximum factorial that is formed by three digits?
This was a question asked on a site.
I am not able to understand is there any thing tricky i am not getting?
i have tried 3 and 720 but it is incorrect
The maximum factorial which can be formed using 3 digits is 999!.
The answer can be easily obtained from wolfram alpha.
Number of digits in 999!.
999!=Answer

Why does data get altered while applying a function [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I loaded a RDS file. The file contains a numeric field. When I say
class(NEI$Emissions)
it returns
"numeric"
The data is in maximum 3 digits and contains 3 digits of decimal. However, when I issue the command
max(NEI$Emissions)
it returns a huge number.
646952
How can I use the numeric values as it is?
R doesn't lie. One of your data points is not what you expect.
Find which row has the problem with this command:
which.max(NEI$Emissions)
then examine that row of your original data. You will find the errant value.

Resources