Open Side Menu Go to the Top
Register
Programming homework and newbie help thread Programming homework and newbie help thread

12-13-2016 , 06:48 AM
Quote:
Originally Posted by Mr.mmmKay
NUMYEARS is just an integer which is equal to 5, so of course you can't do NUMYEARS[5], you can only do that to arrays pointers and vectors, as the compiler tells you.

It's not clear what you want to do in the sumit function, are you trying to compute the sum 2011 + 2012 + 2013 + 2014+ 2015?
Yeah i caught on to that mistake post mortem. still stuck tho.

Im trying to sum up all of the integers input. so adding the sum of 2011-2015 would work.
Programming homework and newbie help thread Quote
12-13-2016 , 06:54 AM
I don't see any integer input in your code, you only have float input for Raindata, are you trying to sum all those?

Or are you trying to sum up all values in years[NUMYEARS][5]? That requires some more work because all the values in there are character arrays.
Programming homework and newbie help thread Quote
12-13-2016 , 07:01 AM
Quote:
Originally Posted by Mr.mmmKay
I don't see any integer input in your code, you only have float input for Raindata, are you trying to sum all those?

Or are you trying to sum up all values in years[NUMYEARS][5]? That requires some more work because all the values in there are character arrays.
sorry, let me clean up my language.

I want to sum the floats.
Programming homework and newbie help thread Quote
12-13-2016 , 07:13 AM
In that case you should just loop through all values in Raindata and add them. This isn't really any harder than what you did for the printdata and inputdata functions so I don't really see why that's a proplem.
Programming homework and newbie help thread Quote
12-13-2016 , 07:39 AM
I feel like the biggest doof.

but Im blanking.

im new
Programming homework and newbie help thread Quote
12-13-2016 , 08:05 AM
Adding up all the values in Raindata is done as follows

Code:
float sum = 0;

for (int year = 0; year < NUMYEARS; year++) {
 for (int month = 0; month < NUMMONTHS; month++) {
   sum += Raindata[year][month];
  }
}
And if it isn't clear how this works you might want to refresh your knowledge on arrays and arrays of arrays

Last edited by Mr.mmmKay; 12-13-2016 at 08:15 AM.
Programming homework and newbie help thread Quote
12-13-2016 , 08:11 AM
Quote:
Originally Posted by Mr.mmmKay
Adding up all the values in Raindata is done as follows

Code:
float sum = 0;

for (int year = 0; year < NUMYEARS; year++) {
 for (int month = 0; month < NUMMONTHS; month++) {
   sum += Raindata[i][j];
  }
}
And if it isn't clear how this works you might want to refresh your knowledge on arrays and arrays of arrays
this is my first experience with arrays.

im essentially taking CS101 in an online format which has been OK up until this point.

what are i and j?
Programming homework and newbie help thread Quote
12-13-2016 , 08:15 AM
oops, replace i and j with year and month, respectively.

Force of habit

You should be familiar with the information in the following two links about arrays to do these kind of exercises:
https://www.tutorialspoint.com/cprog...g/c_arrays.htm
https://www.tutorialspoint.com/cprog...nal_arrays.htm

Last edited by Mr.mmmKay; 12-13-2016 at 08:20 AM.
Programming homework and newbie help thread Quote
12-13-2016 , 08:23 AM
Quote:
Originally Posted by Mr.mmmKay
oops, replace i and j with year and month, respectively.

Force of habit

You should be familiar with the information in the following two links about arrays to do these kind of exercises:
https://www.tutorialspoint.com/cprog...g/c_arrays.htm
https://www.tutorialspoint.com/cprog...nal_arrays.htm
super thanks

I was just about to ask you if you could point me in the right direction.

honestly this class the last few weeks has been a nightmare.

horrible structure for a beginners programming class.
Programming homework and newbie help thread Quote
12-14-2016 , 01:34 PM
So for some reason they asked a data scientist to do this, but it sure seems like a traditional software engineer problem. I feel in over my head. Here is the problem:

I have various healthcare metrics in categories. So for Diabetes, I'll have weight, glucose, steps, etc for several users. Not every user will have a value for every metric.

So for User A who has a 10/10 score in each metric, they should receive a Diabetes score of 30/30. But for User B who has no value for glucose, but 10/10 elsewhere, they should receive a Diabetes score of 20/20.

I'm just totally lost as to how I can create a custom denominator for each user. I program in R. The algorithms were easy to create using mostly ifelse logic when I assumed each user would have a value for each metric. But now I'm told that won't be the case.

I think I can create a percentage variable based on their score and their denominator and that percentage variable can be used to even things out between users. But getting to that point seems baffling to me right now.

How can I get started? Any suggestions? I'm not sure how to Google this problem. Thanks for any help you can offer.

Last edited by cannabusto; 12-14-2016 at 01:48 PM.
Programming homework and newbie help thread Quote
12-14-2016 , 02:12 PM
You just want to know the number of non-NA values as denominator?

As an example, if you have your data as a matrix with one row per user and columns 3-5 containing the scores:
dummydata = matrix(nrow=150, ncol=5)

You can get the number of non-NA values per user as:
valuesperuser = rowSums(!is.na(dummydata[,3:5]))

If you need some more customized logic for creating the denominator, check the lapply function.
Programming homework and newbie help thread Quote
12-14-2016 , 03:04 PM
Quote:
Originally Posted by plexiq
You just want to know the number of non-NA values as denominator?

As an example, if you have your data as a matrix with one row per user and columns 3-5 containing the scores:
dummydata = matrix(nrow=150, ncol=5)

You can get the number of non-NA values per user as:
valuesperuser = rowSums(!is.na(dummydata[,3:5]))

If you need some more customized logic for creating the denominator, check the lapply function.
Thanks. This feels like it will help. Only issue is there are different weights for each metric. So, afaict, I want to multiply the values by their weights before doing what you suggest above.

I'll report back when I try this, but thanks again.
Programming homework and newbie help thread Quote
12-14-2016 , 03:22 PM
Hmm, actually that won't work. Not sure how to handle the weighting issue yet.
Programming homework and newbie help thread Quote
12-14-2016 , 03:38 PM
If you want to weight the attributes that would look something like this:
weights = c(0.5,0.3,0.2)
weightedperuser = rowSums(t(t(!is.na(dummydata[,3:5]))*weights))
Programming homework and newbie help thread Quote
12-14-2016 , 04:12 PM
Thanks a ton plexiq. Super helpful. The final solution looks like this:

test$Numerator <- rowSums(test[,2:3], na.rm = T)

weights = c(0.5,1.0)
test[2:3] <- test[2:3]*weights
weightedperuser = rowSums(t(t(!is.na(test[,2:3]))*weights))

test$Denominator <- weightedperuser*10

test$Category_Score <- test$Numerator/test$Denominator


Category score is a percentage that we can use to score users on the same scale even if they have different denominators. Thanks again. Saved me many headaches.
Programming homework and newbie help thread Quote
12-31-2016 , 10:52 PM
This might be an odd question as it's not fully formed in my mind but I'm going to ask any way. Is there a list of items that you like to be able to accomplish in a language when learning it for the first time?

I know different languages are geared towards different programming paradigms and some languages are designed to more easily accomplish some specialized task but is there a list that people like to go through when learning a new language to ensure they are proficient in the language or that allows them to learn all the essential functionality of a language? Like I said not sure if I'm asking the right question here just looking for some guidance to laser focus on learning a new language in the next couple of months.

Sent from my SM-G900R4 using Tapatalk
Programming homework and newbie help thread Quote
12-31-2016 , 11:41 PM
Clowntable linked this excellent site in a different thread not long ago, it seems quite appropriate in this regard:

https://learnxinyminutes.com/
Programming homework and newbie help thread Quote
01-01-2017 , 09:06 AM
Quote:
Originally Posted by _dave_
Clowntable linked this excellent site in a different thread not long ago, it seems quite appropriate in this regard:

https://learnxinyminutes.com/
Thanks! I had navigated to the site in the other thread but I guess I had only made it through the syntax and semantic stuff and not the further reading materials at the bottom of the page.
Programming homework and newbie help thread Quote
01-13-2017 , 03:33 PM
Hey all,

Just been messing around with coding on the side, pretty much solely through codeacademy and watching videos online of others coding things.

I've just downloaded Python as my first language and Sublime Text 3 as my text editor, and because everything has been through Codeacademy I have no idea how to actually get my Python to execute the code from my Text Editor. I've actually looked at a bunch of tutorials but they all seem to be doing it on Macs or just simply not explaining this part (probably meaning it's so obvious and basic that they don't think they need to).

Figured this would be the best place to ask such a basic question, so any help would be massively appreciated.

Cheers,
Jay
Programming homework and newbie help thread Quote
01-13-2017 , 04:13 PM
I don't know anything about sublime really, but you don't "need" to run your code from sublime. You can run it from the command line. How to do this varies a little bit from OS to OS but in general, from the directory that your source file is in, run

python myprogram.py

and provided that the python executable is in your path that should more or less do it.

If you don't have experience running stuff from the command line, I guess maybe now is a good time to start.
Programming homework and newbie help thread Quote
01-17-2017 , 07:51 PM
can anyone write a tail recursive inorder dfs traversal of a bst?

I keep tripping up and wonder if it's possible? I assume it is, I got it working with a single stack and an extra variable keeping track of whether I went left already but can't get it working with a recursive function for some reason.

Before I try adding a 'wentRight' variable thought I'd check here.
Programming homework and newbie help thread Quote
01-17-2017 , 07:55 PM
ha as soon as I hit submit I look again and realize all I need is a link to a node's parent either as an additional arg or from the node itself to get it working.
Programming homework and newbie help thread Quote
01-18-2017 , 03:13 PM
Hi Guys

I am signing up to my first programming course online and starting out with python on a few peoples recommendation.

I am not entirely sure which course is best for me and am a little clueless as to what would be good.

I have seen these two course online which look ok, which would be best do you think?

https://www.coursera.org/specializations/python

https://www.coursera.org/specializat...r-fundamentals

The one from RICE looks like it might be more fun maybe but I don't really know

Any advice/thoughts would be appreciated. Thanks in advance
Programming homework and newbie help thread Quote
01-18-2017 , 09:09 PM
What's your aim in taking the course?

Initial reaction is that the Rice one looks better. The Michigan one tries to cover web and database tooling as well and might be too shallow as a result. Those things also might not be useful to you depending on what you want to do with your new skills.
Programming homework and newbie help thread Quote
01-19-2017 , 06:01 AM
short term I just want to be able to program same basic little toy projects.
from what I have read/been told just building stuff and coding a lot is what you need to do.

medium term I would like to build bigger things probably would involve building a gui and maybe some app stuff as well or a basic game for my kids

long term as I move away from poker for a living in the next few years programming in some function might be an area I would want to move into. obv very far away at the moment

thanks for your advice the RICE looked more fun and involved quite a few mini projects which was appealing.
I guess if Web and database tooling is something I would need that would be quite far down the line for me anyway

Sent from my SM-G920F using Tapatalk
Programming homework and newbie help thread Quote

      
m