Asharonapaul 276 Posted June 27, 2018 small correction, ans += ... not ans = otherwise you get the maximum value of j in f(j) and not the entire array of j Share this comment Link to comment
Kayzee 4,032 Posted June 28, 2018 (edited) Hmmm? You mean 'sigma' as in 'summation' right? There is a built in method for that. It think it's only for later Ruby versions though. You can also do it using inject/reduce. Also: Passing the function as a string to be evaluated? Tsk tsk... That's a bad practice ya know? There is a better way... Blocks are your friend! Another helpful message from Kayzee the programing snob! :3 Edited June 28, 2018 by Kayzee Share this comment Link to comment
Asharonapaul 276 Posted June 28, 2018 I could not find a sigma method. ya its sums. Share this comment Link to comment
Kayzee 4,032 Posted June 29, 2018 (edited) I am not sure I ever heard it be called a 'sigma method' before, though it makes a degree of sense I guess. But yeah, that's what inject is for more or less. Edited June 29, 2018 by Kayzee Share this comment Link to comment
Asharonapaul 276 Posted June 30, 2018 no clue what you're on about Share this comment Link to comment
Kayzee 4,032 Posted June 30, 2018 (edited) I mean that if you want to sum an array like that in ruby you usually do something like this: [1,2,3,4,5].inject(0) {|sum, n| sum+n } Unless what you really want to do are limits? Edited June 30, 2018 by Kayzee Share this comment Link to comment
Asharonapaul 276 Posted July 1, 2018 (edited) ok. so no. the f(j) = O(n^2) k so the sum series is not the array. Edited July 1, 2018 by Asharonapaul Share this comment Link to comment
Kayzee 4,032 Posted July 1, 2018 I honestly don't really understand what you are doing there then... I guess looking at it, it looks like you are just looking at the array's size and not it's contents. Huh... f(j) = O(n^2) you say? Are you perhaps doing a rough calculation of how a function's time/memory requirements scale with it's input? Actually... Isn't that a type of limit? Share this comment Link to comment
Asharonapaul 276 Posted July 1, 2018 basically all the algorithms I learned for first two chapters involve arrays, sorting, searching. And wanted to see how a particular method was compared to another, based on the book's array suggestions Share this comment Link to comment
Kayzee 4,032 Posted July 1, 2018 Hehe... Oh I see! I guess I was mistaken then. I am sorry if I was a bother. Though I still likely would have used blocks and not eval... But eh. Share this comment Link to comment
Asharonapaul 276 Posted July 1, 2018 ah, the function is also intended as internal use only, so there can't be chance of the player breaking it. Share this comment Link to comment
Recommended Comments
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now