If I have a list of numbers, is there a way to search the list for a potentially recurring number and find the corresponding position of each separate occurrence?

I’m designing a battleship game to help some of my struggling kiddos work on slopes and linear equations. Here’s my current plan (please feel free to let me know if there’s an easier way to do this!) Everyone positions a battleship occupying a single coordinate on a graph. I aggregate the points into two lists. Now students advance to firing on other ships. But first they have to “scan” for the other ships. They enter a point (scan) to see if there is a ship there. If there is not, they get a blue miss dot. If there is, they get a red dot indicating a classmate has a ship on that coordinate. (Every student is now basically playing their own game, we’re not aggregating scans or shots.) Students that found an enemy ship now enter a slope that will fire a shot from the origin (no ship is allowed to park on the origin). If the slope hits the target ship, they get a point.

I can figure out everything except for the part where the student enters the “scanning” point and CL checks it against the aggregated lists. Suppose other students had parked boats on the following points: (1, 5) (2, 7) (3, 6) (1, 2) (1, 3) Now suppose an enemy student scans the coordinate (1, 2). The two lists are x and y. So List X is [1, 2, 3, 1, 1] and List Y is [5, 7, 6, 2, 3]. My thought was that if I could search X for 1 and get the info that 1 occurs 1st, 4th, and 5th, I could then search Y for 2 at those positions. I know a way to search a list for the first occurrence/position of a number and how to get that position as a variable, but I don’t know how to search for multiple occurrences or how to get multiple positions for that same number.

Is this possible to do? Or is there a simpler way to check a student’s entered coordinate against an aggregated coordinate list?

It’s probably easiest to turn the lists back into a list of points and just check if the distance from each to the guess is 0. Here’s an example…

Yeah, that seems a lot easier than what I was trying to do. Thank you so much! Once I aggregated to a list, I kept doing everything while thinking of a list. Silly me. Thanks again!

1 Like