Web16 Apr 2013 · Kai on CodingBat: Java. Map-1; Geelvis on A Critical View on Coursera’s Peer Review Process; Gregor Ulm on CodingBat: Java. Map-2; Gregor Ulm on CodingBat: Java. Logic-2; Gregor Ulm on Poor Treatment of Recursion in Introductory Textbooks, and a Counterexample; Archives. December 2024 (1) January 2024 (1) December 2024 (1) … WebHello. I would like help in understanding the solutions to the problem: Return the sum of the numbers in the array, returning 0 for an empty array. Except the number 13 is very unlucky, so it does not count and numbers that come immediately after a 13 also do not count. Examples: sum13([1, 2, 2, 1]) → 6. sum13([1, 1]) → 2. sum13([1, 2, 2, 1 ...
Java > Array-2 > sum13 (CodingBat Solution) - java problems
Websum13 ( [1, 2, 2, 1, 13]) → 6. Solution 1: def sum13 (nums): total = 0 i = 0 while i < len (nums): if nums [i] == 13: i += 2 continue total += nums [i] i += 1 return total. Solution 2: def sum13 … WebBasically similar except you shouldn't calculate rest = sum13(nums[1:])before you checked for current number, that gave you unnecessary recursive runs. def sum13(nums): if len(nums) == 0: return 0 if nums[0] != 13: return nums[0] + sum13(nums[1:]) else: return sum13(nums[2:]) 2 Share ReportSave level 2 agarbatti hsn code 5
Northeastern University
WebThe solution can be a little shorter using splices: for i in range (len (str)-3): if str [i:i+1) == 'co' and str [i+3] == 'e': Python > String-2 > count_hi One-liner using the 'count' method for strings: python>> help (str) return str.count ('hi') Python > String-2 > end_other Use: a = a.lower () , and similarly for b, to ignore case Then use … Websum13([1, 2, 2, 1]) → 6 sum13([1, 1]) → 2 sum13([1, 2, 2, 1, 13]) → 6 My solution: def sum13(nums): sum = 0 for i in range(0, nums.count(13)): if nums.count(13): after = nums.index(13) nums.remove(13) if after < … WebSolution for CodingBat sum67. Raw sum67.py def sum67 (nums): s=i=0 while i < len (nums): if nums [i]!=6: s+=nums [i] i+=1 else: while (nums [i]!=7): i+=1 i+=1 return s print "sum67 ( … agarbatti clipart