We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Day 19: Interfaces
Day 19: Interfaces
+ 0 comments class Calculator(AdvancedArithmetic): def divisorSum(self, n): divisors=[] for num in range(1,n+1): if n%num==0: divisors.append(num) return sum(divisors)
+ 0 comments interfaces solution using Typescript or JavaScript and All solution of HackerRank https://github.com/deepak14ri/Hackerrank-30-Day-Challenge
function main() { // Enter your code here var n = Number(inputLines[0]); var sum = 0; for(let i=1;i<=n;i++){ if(n%i==0){ sum+=i; } } console.log('I implemented: AdvancedArithmetic'+'\n'+sum);
}
+ 0 comments My solution
int divisors_sum = n; for(int i = 1 ; i <= n/2 ; i++){ if(n % i == 0) divisors_sum += i; } return divisors_sum;
+ 0 comments I am a little bit confused. I "solved" the challenge, but it doesn't seem like they even needed/wanted to specifically implement an interface. Even the linked tutorial uses interface and implements the way I was taught, but the stub code forces different syntax becasue you can't redesign AdvancedArithmetic to be an interface. Which Cacluate would then implement. Can someone explain? BTW I am solving the challenges in python.
+ 1 comment Python 3
def divisorSum(self, n): divisor = [x for x in range(1, n+1) if n % x == 0] return sum(divisor)
Load more conversations
Sort 757 Discussions, By:
Please Login in order to post a comment