/* * Yet another version of summing a list * Another list summer. This time use an internal recursive function so * that you check base conditions before going into recursion. * This should, this be a little quicker than the previous version */ fun main() { println(bb(listOf(1,2,3,4,5,6))) } /* * Another list summer. This time use an internal recursive function so * that you check base conditions before going into recursion. * This should, this be a little quicker than the previous version * @param b3 -- a list of integers : default=null * @param summ -- the number to consider to be the sum of an empty or null list: default 0 * @param pos -- the positionof the next item in the list to put into the * sum : default=0 */ fun bb(b3: List?=null, pos:Int=0, summ:Int=0) : Int { if (b3==null) return summ if (pos<0) return summ tailrec fun funcc (p4:Int , s4:Int) : Int { if (p4 >= b3.count()) return s4 return funcc(p4+1, s4+b3.get(pos)) } return funcc(pos, summ) }