Courses‎ > ‎Intro to CS - Full Year‎ > ‎Spring‎ > ‎Dyrland-Weaver‎ > ‎Work‎ > ‎

### Work 29: 4/17

posted Apr 17, 2019, 9:42 AM by JonAlf Dyrland-Weaver
 count_hopsImagine a frog sitting in a circle of 5 lilypads.Assign each pad a number in the range [0, 4]Assume the frog stars on pad 0The frog can hop either 2 pads forward or 1 pad backward.If the frog goes off either end, it wraps around (one hop backward from 0 is 4)Write a function that will return the number of times the frog will end up at a particular pad, given all combinations of a set number of hops.`count_hops(position, target, hops)`Here are lists representing the total times the frog, starting at position 0, would end up on a specific pad given some number of hops1 hop: [0, 0, 1, 0, 1]2 hops: [0, 2, 0, 1, 1]3 hops: [3, 1, 1, 3, 0]5 hops: [2, 10, 5, 5, 10]Examples`count_hops(0, 1, 2) ==> 2``count_hops(0, 2, 2) ==> 0``count_hops(0, 0, 5) ==> 2`random_sliceTakes a list as a parameterReturns a randomly created slice of the parameter list.The start and end of the slice should be randomly selected valid indices of the list.The slice could be a forwards or backwards slice of the list.averageTakes a single list containing only numbers as a parameter.Returns the average of all the elements of the list.Example`average( [8, 4.5, -83, 98.2, 100] ) ==> 25.54`list_minTakes a single list as a parameter.Returns the smallest element in the list.Examples:`list_min([8, 4.5, -83, 98.2, 100]) ==> -83``list_min(['cat', 'dog', 'avocado', 'bacon']) ==> 'avocado'`Submit this as test4_review