How to create a random integer array generator - java

I have created a method which takes generate random numbers with the condition that the next random number doesn't match with the previous one inside the array here's the code
// some code
int k=0;
//some code....
randomgenerator(k); // method call
public void randomgenerator(int j)
{
for(j=0; j<=99; j++){
if(j >= 1){
if (randomset.get(j) == randomset.get(j-1)){
randomset.add(0 + ( j , int)(Math.random() * ((99 - 0) + 1)));
}
else{
randomset.add(0 + (int)(Math.random() * ((99 - 0) + 1)));
}
}
}
}
The error I get is java.lang.IndexOutOfBoundsException: Invalid index 1, size is 1

Because initially randomset is empty therefore its size is 0 and returns exception at index 1. The best way to add randomset.add(0 + (int)(Math.random() * ((99 - 0) + 1))); if j < 1 (not >=1).
Correct code:
public void randomgenerator(int j)
{
for(j=0; j<=99; j++){
if(j >= 1){
if (randomset.get(j) == randomset.get(j-1)){
randomset.add(0 + ( j , int)(Math.random() * ((99 - 0) + 1)));
}
else{
randomset.add(0 + (int)(Math.random() * ((99 - 0) + 1)));
}
}
else {
randomset.add(0 + (int)(Math.random() * ((99 - 0) + 1)));
}
}
}

Use
for(j=0; j<randomset.size(); j++){

Don't use the same variable as your input parameter and your loop variable.
public void randomgenerator(int length)
{
for (int j = 0; j < length; j ++) ...
I'm not sure I follow the rest of the code, but that's a start.

You can't reference an element of ArrayList whose index is not in bounds [0, size() - 1]. Creating ArrayList via ArrayList() creates a list of size 0. To add elements to this array you must call one of the methods that adds an element, e.g. add(). Your first call is to get(), but the list has size 0, so even get(0) will cause an IndexOutOfBoundsException.
What to do depends on the expected contents of the list. In your case, I would recommend writing a helper function that generates a random number in range excluding specified number. You could use that function in a simple loop to generate the whole list, passing previous element to mentioned helper function.
Example:
public static int randomInRange(int a, int b) {
return (int)(Math.random() * (b - a + 1));
}
public static int randomInRangeExcluding(int a, int b, int excluding) {
int result = (int)(Math.random() * (b - a));
if (result == excluding) {
result++;
}
return result;
}
public static List<Integer> generateRandomList(int size) {
ArrayList<Integer> result = new ArrayList<Integer>();
for (int j = 0; j <= size; j++) {
if (j > 0) {
result.add(randomInRangeExcluding(0, size - 1, result.get(j - 1)));
} else {
result.add(randomInRange(0, size - 1));
}
}
return result;
}
and get the value using:
generateRandomList(100);
Calling this results in a list of random integers having no two consecutive elements equal:
[27, 34, 53, 92, 56, 93, 21, 22, 45, 95, 48, 25, 18, 26, 54, 1, 82, 26, 5, 62, 84, 23, 8, 84, 25, 0, 36, 37, 54, 95, 4, 26, 65, 53, 81, 16, 47, 56, 73, 46, 60, 50, 37, 89, 61, 84, 23, 79, 47, 87, 68, 49, 15, 17, 55, 71, 17, 55, 71, 51, 67, 33, 80, 47, 81, 24, 10, 41, 76, 60, 12, 17, 96, 43, 57, 55, 41, 56, 21, 85, 98, 40, 9, 39, 53, 28, 93, 70, 89, 80, 40, 41, 30, 81, 33, 53, 73, 28, 38, 87, 29]

What is with you're function? You receive a parameter named j and then you reassigned it?
randomset.get(j) == randomset.get(j-1) <- at this line you have a java.lang.IndexOutOfBoundsException because you call for the value from position 1 but in you're list you have only a value on position 0; so an error is thrown
and, what is this ? ((99 - 0) + 1)) ,you could white 100, it is easy, and more readable
by the way, at this line you have an error, randomset.add(0 + ( j , (int)(Math.random() * ((99 - 0) + 1)));
You should write a cleaner code.
I've prepared a solution for you: a function which generates a List with random numbers and respects you condition: two consecutive numbers are not the same.
You must call this method generateRandomList with the number of elements you want to generate.
public static final Integer MAX_RANDOM_NUMBER = 100;
public static List<Integer> generateRandomList(int randomNumbers) {
return generateRandomList(randomNumbers, -1);
}
private static List<Integer> generateRandomList(final int randomNumbers, final int previousNumber) {
if (randomNumbers == 1) {
return new ArrayList<Integer>() {
{
add(getNextNumber(previousNumber));
}
};
} else {
return new ArrayList<Integer>() {
{
int value = getNextNumber(previousNumber);
add(value);
addAll(generateRandomList(randomNumbers - 1, value));
}
};
}
}
private static int getNextNumber(int previousNumber) {
boolean generateNewValue = true;
int currentValue = 0;
while (generateNewValue) {
currentValue = (int) (Math.random() * MAX_RANDOM_NUMBER);
generateNewValue = currentValue == previousNumber;
}
return currentValue;
}

Related

code for generating none repeating random numbers. Looks fine to me but when i run it gives me the same number

import java.util.Random;
public class Practice_assignment {
public static void main(String[] args){
int[] winning_numbers = {0,0,0,0,0,0,0,0,0,0} ;
//The i++ for the first loop is in the second loop. I was trying to ensure it only goes to
the next value of the loop once a unique value has been gotten.
for (int i=0; i<10;){
int max = 99;
int min = 1;
Random rand = new Random();
int randomNum = rand.nextInt((max - min) + 1) + min;
for (int j=0;j<=i;j++){
if (j<i && winning_numbers[j]==randomNum){
break;
}
else if (j==i && i<10){
winning_numbers[i] = randomNum;
System.out.println(winning_numbers[i]+" ");
i++;
}
}
}
}
}
If I understood correctly what you are trying to achieve, I think you could use something like this:
public class RandomNumbers {
public static void main(String[] args) {
int[] winning_numbers = {0,0,0,0,0,0,0,0,0,0} ;
Random random = new Random();
for(int i = 0; i < winning_numbers.length; i++) {
OptionalInt generatedInt = random.ints(1, 0, 100).findFirst(); // generates a stream of 1 number between 0 and 99 and gets the first (and only) one generated
while (contains(winning_numbers, generatedInt)) {
generatedInt = random.ints(1, 0, 100).findFirst(); // while the generated number is already in the array, generate a new one
}
winning_numbers[i] = generatedInt.getAsInt();
}
System.out.println(Arrays.toString(winning_numbers));
}
// this method will check if the given array already contains the generated int
private static boolean contains(int[] arr, OptionalInt generatedInt) {
return Arrays.stream(arr).anyMatch(number -> generatedInt.getAsInt() == number);
}
}
I ran it a couple of times and here are some outputs I generated with this code:
[52, 54, 21, 62, 47, 13, 94, 36, 82, 25]
[35, 37, 16, 81, 22, 71, 17, 94, 56, 8]
[51, 50, 80, 62, 18, 88, 1, 53, 44, 79]
[16, 95, 18, 66, 31, 4, 1, 55, 52, 26]
[4, 11, 65, 68, 22, 76, 95, 67, 35, 92]
[49, 87, 34, 88, 71, 57, 12, 76, 70, 78]
It appears you want to generate an array of winning_numbers. Here is one ways to do it.
create a helper method to look for duplicate numbers and return true if a duplicate is found.
then iterate over the array checking for the current random number and adding it if unique.
note that min, max, and rand should be initialized outside the loop.
Random rand = new Random();
int[] winning_nummbers = new int[10];
int max = 99;
int min = 1;
for (int i = 0; i < 10;) {
int randomNum = rand.nextInt((max - min) + 1) + min;
// if does not contain a duplicate, then assign
if (!contains(winning_numbers, randomNum)) {
winning_numbers[i++] = randomNum;
}
}
System.out.println(Arrays.toString(winning_numbers));
Prints something like this.
[46, 91, 5, 2, 42, 58, 74, 24, 53, 36]
The helper method.
public static boolean contains(int[] array, int v) {
for (int i = 0; i < array.length; i++) {
if (array[i] == v) {
return true;
}
}
return false;
}
If you want to use streams you can do it like so using a Random instance.
stream values form min to max inclusive.
drop duplicates with distinct
limit(10) limits to 10 values.
put them in an array
int[] winning_numbers = rand.ints(min,max+1)
.distinct()
.limit(10)
.toArray();

using a java switch stament to determine what method to call and repeatedly calling that method

I'm writing a java program where the user can select a sorting algorithm from a list and specify the size of an array to be sorted. The program then generates an array of the specified size filled with random integers and uses a switch statement with a case for each sorting algorithm to call the method for the user's chosen algorithm using the generated array as a parameter.
I want to update my code to allow the user to specify how many arrays are to be sorted with their chosen algorithm. I want to use a for loop to randomly generate and sort the arrays however this doesn't seem ideal because I would have to either:
Place the switch block inside the for loop and check it every loop, even though the same sorting algorithm will be used each time.
Place a for loop in each case within the switch block and have a lot of repeated code in the form of for loops.
Is there a better implementation for this than using switch cases and for loops?
Define an interface (perhaps even a functional interface) named Sorter that has a method
int [] sort( final int [] values )
or
var sort( final int [] values )
if you sort the array in-place.
Implement that interface for each sorting algorithm.
Then you can have a variable Sorter sorter in your program that holds the implementation; it will be initialised in your switch/case statement, based on the user selection.
In your for loop, you will call sorter.sort() for each array to sort.
You can even avoid the switch/case statement by creating a Map<String,Sorter> data structure that is initialised with the name of the sort algorithm as the key and instances of the implementation of Sorter as the value. If Sorter is a functional interface, you can just assign a reference to the respective sort() methods to the Map.
However, this is known as the Strategy pattern …
I decided to try throwing together an example of how you could go about this based off of tquadrat's idea of using a functional interface. I hope it helps!
import java.util.ArrayList;
import java.util.Random;
public class Sorting {
#FunctionalInterface
interface SortType {
Integer[] sort(Integer[] array);
}
public static void main(String[] args) {
int numArrays = 5;
int numValues = 10;
ArrayList<Integer[]> unsortedArrays = generateArrays(numArrays, numValues);
System.out.println("Unsorted:");
print(unsortedArrays);
ArrayList<Integer[]> sortedArrays = sortArrays(unsortedArrays, Sorting::bubbleSort);
System.out.println("\nSorted:");
print(sortedArrays);
}
//Put together random values
private static ArrayList<Integer[]> generateArrays(int numArrays, int numValues) {
ArrayList<Integer[]> unsortedArrays = new ArrayList<>();
Random rand = new Random();
for (int i = 0; i < numArrays; i++) {
Integer[] array = new Integer[numValues];
for (int j = 0; j < numValues; j++) {
array[j] = rand.nextInt(100);
}
unsortedArrays.add(array);
}
return unsortedArrays;
}
//Loop through using the given sorting method on each array
private static ArrayList<Integer[]> sortArrays(ArrayList<Integer[]> arrays, SortType sortType) {
ArrayList<Integer[]> sortedArrays = new ArrayList<>();
for (Integer[] array : arrays) {
sortedArrays.add(sortType.sort(array));
}
return sortedArrays;
}
//Example sort to use with parameters and return matching the interface
private static Integer[] bubbleSort(Integer[] array) {
int n = array.length;
for (int i = 0; i < n - 1; i++)
for (int j = 0; j < n - i - 1; j++)
if (array[j] > array[j + 1]) {
int temp = array[j];
array[j] = array[j + 1];
array[j + 1] = temp;
}
return array;
}
//Method to print the results
private static void print(ArrayList<Integer[]> arrays) {
for (Integer[] array : arrays) {
for (Integer i : array)
System.out.print(i + ", ");
System.out.println();
}
}
}
Sample output:
Unsorted:
67, 54, 83, 67, 62, 96, 6, 24, 66, 19,
3, 37, 45, 36, 81, 45, 5, 46, 5, 84,
10, 8, 95, 50, 82, 38, 36, 18, 80, 98,
52, 27, 18, 17, 77, 51, 18, 72, 55, 76,
79, 84, 92, 85, 61, 74, 64, 29, 95, 64,
Sorted:
6, 19, 24, 54, 62, 66, 67, 67, 83, 96,
3, 5, 5, 36, 37, 45, 45, 46, 81, 84,
8, 10, 18, 36, 38, 50, 80, 82, 95, 98,
17, 18, 18, 27, 51, 52, 55, 72, 76, 77,
29, 61, 64, 64, 74, 79, 84, 85, 92, 95,

searching in 2d array as O(n) with unsorted rows

I need to write a method that takes 2d array 'int [][] m' and a value 'val' and check if val is in the array in the complexity of O(n) while n defined as the number of rows and m must be squared
The array that can use as a parameter for my method must return true for this method:
(if it returns true so the array is as requested)
public static boolean test(int[][] m) {
int n = m.length;
for (int r = 0; r < (n - 1); r++)
for (int c = 0; c < n; c++)
for (int i = 0; i < n; i++)
if (m[r][c] > m[r + 1][i]) return false;
return true;
}
This array returns TRUE:
int [][] arr3 = new int [][]{
{ 0, 2, 1, 2, 0, 5, 5, 5, },
{ 21, 21, 7, 7, 7, 21, 21, 21 ,},
{ 21, 21, 21, 21, 21, 21, 21 , 21, },
{ 21, 21, 23 , 42, 41, 23, 21, 21, },
{ 60 ,56, 57, 58, 53, 52, 47, 51 ,},
{ 61, 65, 70 , 72, 73, 78, 82, 98 ,},
{ 112, 121, 112, 134, 123, 100, 98, 111,},
{ 136, 136, 136, 134, 147, 150, 154, 134,},
};
My method should return true if val is in the array and looks like this:
public boolean findValTest(int [][] m, int val){...}
It is possible iff. the matrix m is a square matrix of size n x n. Core idea is inspired by oleg.cherednik's answer. As soon as we find a row in m, such that m[row][0] >= val, we know that val must be in either row row or row - 1(since the same comparison on row - 1 was false). Thus, we have to find our candidate rows (O(n)) and then analyze only those two rows (also O(n)). If m is not square, but rectangular, the algorithm has a complexity of O(n + k), where n is the number of rows and k is the number of colums in m. This leads to the following algorithm.
public class Test {
public static boolean contains(final int[][]m, final int value) {
int candidateRow = m.length;
for (int row = 1; row < m.length; ++row) {
if (m[row][0] == value) {
return true;
}
if (m[row][0] > value) {
candidateRow = row;
break;
}
}
for (int val : m[candidateRow - 1]) {
if (val == value) {
return true;
}
}
if (candidateRow < m.length) {
for (int val : m[candidateRow]) {
if (val == value) {
return true;
}
}
}
return false;
}
public static void main(String[] args) {
int [][] testArray = new int [][]{
{ 0, 2, 1, 2, 0, 5, 5, 5 },
{ 21, 21, 7, 7, 7, 21, 21, 21 },
{ 21, 21, 21, 21, 21, 21, 21, 21 },
{ 21, 21, 23, 42, 41, 23, 21, 21 },
{ 60, 56, 57, 58, 53, 52, 47, 51 },
{ 61, 65, 70, 72, 73, 78, 82, 98 },
{ 112, 121, 112, 134, 123, 100, 98, 111 },
{ 136, 136, 136, 134, 147, 150, 154, 134 }
};
for (int[] row : testArray) {
for (int val : row) {
System.out.print(contains(testArray, val) + " ");
}
System.out.println();
}
System.out.println();
System.out.println();
final int[] notInMatrix = { -1, 3, 4, 6, 8, 22, 30, 59, 71, 113, 135 };
for (int val : notInMatrix) {
System.out.print(contains(testArray, val) + " ");
}
System.out.println();
}
}
We can improve the acutal runtime by determining the candidate lines through a binary search algorithm so that candidate lines are found in O(log(n)) instead of O(n). The asymptotical runtime will still be O(n) for square matrices and O(log(n) + k) for non-square n x k matrices. The idea for this was taken from Saeed Bolhasani's answer.
private static int findCandidateRow(final int[][] m, final int value) {
int lower = 0;
int upper = m.length;
int middle = (upper + 1) / 2;
while (middle != m.length
&& middle != 1
&& (m[middle][0] < value || m[middle - 1][0] > value)) {
if (m[middle][0] < value) {
lower = middle;
} else {
upper = middle;
}
middle = lower + (upper - lower + 1) / 2;
}
return middle;
}
your solution is here. i made a function that do binary search for first column. if the val find in the first column the function return true, else last period of 'l' and 'r' are benefit for us. 'r' and 'l' are always equal of have only one distance(r=l or abs(r-l)=1 ). lower bound of 'r' and 'l' are expected row that the val maybe exist in it. so we should search this row.
O(n) for binary search is Log(n) and for row search is n. so the final O(n) will be n.code is here:
static boolean binarySearch(int arr[][], int l, int r, int x)
{
if (r>=l)
{
int mid = l + (r - l)/2;
// If the element is present at the
// middle itself
if (arr[mid][0] == x)
return true;
// If element is smaller than mid, then
// it can only be present in left subarray
if (arr[mid][0] > x)
return binarySearch(arr, l, mid-1, x);
// Else the element can only be present
// in right subarray
return binarySearch(arr, mid+1, r, x);
}
// We reach here when element is not present
// in array
int row = Math.min(l,r);
for(int i=0; i<arr[0].length ;i++)
if(arr[row][i]==x)
return true;
return false;
}
Smth. like that. In case of Every number at row i is equals or smaller then every number on row i+1, than you can check only first element in each row to define a row, where required value could be. Element in unsorted row can be found only with full scan.
This algorithm have to scan 2 full rows only, which is O(n) where n - number of rows.
public static boolean findValTest(int[][] m, int val) {
for (int row = 0; row < m.length; row++) {
if (m[row][0] <= val && row != m.length - 1)
continue;
int r = row;
while (r >= row - 1 && r >= 0) {
for (int col = 0; col < m[r].length; col++)
if (m[r][col] == val)
return true;
r--;
}
return false;
}
return false;
}
Test cases:
System.out.println(findValTest(arr3, -1)); // false
System.out.println(findValTest(arr3, 5)); // true
System.out.println(findValTest(arr3, 7)); // true
System.out.println(findValTest(arr3, 55)); // false
System.out.println(findValTest(arr3, 47)); // true
System.out.println(findValTest(arr3, 147)); // true
System.out.println(findValTest(arr3, 200)); // false
System.out.println(findValTest(new int[][] { { 3, 4, 5 } }, 4)); // true

Recursive mergesort only sorts half of an array

I am attempting to implement a recursive merge sort algorithm to sort a simple array of integers but I am getting weird values for the indexes in the second half of my array. The first half seems to sort fine which is confusing given that its implemented recursively. The array of random integers is initialized in my main method.
public class MergeSort {
public static int Rounds = 1;
public static void MergeSort(Comparable[] ToSort, Comparable[] temp, int first, int last) {
if(first < last) {
int mid = (first + last) / 2;
//Test Block
System.out.print("For Round " + Rounds + ":\n");
System.out.print("first = " + first + " mid = " + mid + " last = " + last + "\n");
Rounds++;
System.out.print("Array in Round " + (Rounds - 1) + " = {");
for(int i = 0; i <= ToSort.length - 1; i++) {
System.out.print(ToSort[i]);
if(i < ToSort.length - 1)
System.out.print(", ");
else {
System.out.print("}\n\n");
}
}
MergeSort(ToSort, temp, first, mid);
MergeSort(ToSort, temp, mid + 1, last);
Merge(ToSort, temp, first, mid + 1, last);
}
}
public static void Merge(Comparable[] ToSort, Comparable[] temp, int first, int mid, int last) {
int beginHalf1 = first;
int endHalf1 = mid - 1;
int beginHalf2 = mid;
int endHalf2 = last;
int index = first;
int Elements = (last - first) + 1;
while(beginHalf1 <= endHalf1 && beginHalf2 <= endHalf2) {
if(ToSort[beginHalf1].compareTo(ToSort[beginHalf2]) < 0) temp[index++] = ToSort[beginHalf1++];
else temp[index++] = ToSort[beginHalf2++];
}
while(beginHalf1 <= endHalf1) temp[index++] = ToSort[beginHalf1++];
while(beginHalf2 <= endHalf2) temp[index++] = ToSort[beginHalf2++];
for(int i = 0; i < Elements; i++, last--) ToSort[last] = temp[last];
}
}
This produces the following output:
UNSORTED ARRAY = {15, 9, 12, 19, 49, 43, 57, 70, 78, 87}
For Round 1:
first = 0 mid = 4 last = 9
Array in Round 1 = {15, 9, 12, 19, 49, 43, 57, 70, 78, 87}
For Round 2:
first = 0 mid = 2 last = 4
Array in Round 2 = {15, 9, 12, 19, 49, 43, 57, 70, 78, 87}
For Round 3:
first = 0 mid = 1 last = 2
Array in Round 3 = {15, 9, 12, 19, 49, 43, 57, 70, 78, 87}
For Round 4:
first = 0 mid = 0 last = 1
Array in Round 4 = {15, 9, 12, 19, 49, 43, 57, 70, 78, 87}
For Round 5:
first = 3 mid = 3 last = 4
Array in Round 5 = {9, 12, 15, 19, 49, 43, 57, 70, 78, 87}
For Round 6:
first = 5 mid = 7 last = 9
Array in Round 6 = {9, 12, 15, 19, 49, 43, 57, 70, 78, 87}
For Round 7:
first = 5 mid = 6 last = 7
Array in Round 7 = {9, 12, 15, 19, 49, 43, 57, 70, 78, 87}
For Round 8:
first = 5 mid = 5 last = 6
Array in Round 8 = {9, 12, 15, 19, 49, 43, 57, 70, 78, 87}
For Round 9:
first = 8 mid = 8 last = 9
Array in Round 9 = {9, 12, 15, 19, 49, 43, 57, 70, 78, 87}
There is no mistake in your implementation. If you print your array after applying MergeSort method, it is sorted:
Comparable[] a = new Comparable[]{15, 9, 12, 19, 49, 43, 57, 70, 78, 87};
Comparable[] b = new Comparable[a.length];
MergeSort.MergeSort(a, b, 0, a.length - 1);
for (int i = 0; i <= a.length - 1; i++) {
System.out.print(a[i]);
if (i < a.length - 1)
System.out.print(", ");
else {
System.out.print("}\n\n");
}
}
will print 9, 12, 15, 19, 43, 49, 57, 70, 78, 87}

Array counting by 5's and 3's then adding the arrays

I have 3 arrays iX, iY, and iZ with each holding 20 integers.
iX goes up by 5, iY goes up by 3, and iZ is the sum of both.
for (int i=5; i <=iX.length; i+=5)
{
iX[i] = i;
System.out.print (i + "\n");
}
for (int j=3; j <iY.length; j+=3)
{
iY[j] = j;
}
for (int k=0; k < iZ.length; k++)
{
iZ[k] = iX[k]+iY[k];
}
When I run it I get:
"Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 20
at Quiz10RTN.main(Quiz10RTN.java:61)"
Line 61 is : iX[i] = i;
I can't seem to get it to even print out 20 numbers, because it seems to be treating my limit of 20 integers as a range to stop at. Any help would be great, Thanks.
Issue is here
for (int i=5; i <=iX.length; i+=5)
^
There is no index match with iX.length in your array.
index of array start with 0, So if size of array is n, then you only have indexes from 0 to n-1.
You can use following to avoid the exception. But you need to think some other way to archive your goal.
for (int i=5; i <iX.length; i+=5)
Edit: for your comment I was trying to print out "5, 10, 15, 20, 25...etc"
You can try something like following
for (int i=0; i <iX.length; i++) {
iX[i]=(i+1)*5; // now your array become 5,10,15,...
}
You are confusing your array indices with the values you are storing in the arrays.
So, for example, if you want your iX array to contain the 20 integers 5, 10, 15,...100, your first loop should look like:
for (int i=0; i < iX.length; ++i)
{
iX[i] = (i + 1) * 5;
System.out.print (iX[i] + "\n");
}
You aren't using the array indexes properly (they must be incremental). You might also use Arrays.toString(int[]) to print your arrays. I believe you wanted something like
int[] iX = new int[20];
int[] iY = new int[20];
int[] iZ = new int[20];
int valfive = 5; // <-- our five increments.
int valthree = 3; // <-- the three increments.
for (int i = 0; i < iX.length; i++) {
iX[i] = valfive;
iY[i] = valthree;
iZ[i] = valfive + valthree;
valfive += 5; // <-- add 5
valthree += 3; // <-- add 3
}
System.out.println("Multiples of five: " + Arrays.toString(iX));
System.out.println("Multiples of three: " + Arrays.toString(iY));
System.out.println("Sums of fives and threes: " + Arrays.toString(iZ));
Output is (formatted for SO)
Multiples of five: [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70,
75, 80, 85, 90, 95, 100]
Multiples of three: [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42,
45, 48, 51, 54, 57, 60]
Sums of fives and threes: [8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96,
104, 112, 120, 128, 136, 144, 152, 160]

Categories