I have a code snippet (see snippet below) that generates an array like this: [0, 3, 1, -2, 0, -1, 1, 1, -2]. The int numbers here represent movements from one position to another. I would like to have the numerical values translated into text that would represent directions starting from the 0. A Positive number represents the number of steps to the East--so the number 3 would be translated into "eee", the number two would be "ee" and so on. Negative values represents steps in the opposite direct West so that -2 would be displayed as ww, and so on. No movement should be represented as 0.
I'm pretty new to all this and am not sure how the take the values from the array and turn them into the instructions as described above.
The code below shows how the array of integers is generated--subtracting the next location from the previous to get the number of steps between them.
int [] differenceX = new int [noOfRecordsX];
differenceX [0] = 0;
for( int i=0; i < noOfRecordsX -1 ;i++)
{
differenceX [i+1]= inputX [i+1] - inputX[i];
}
From here I want to generate the text describing the steps in the respective direction so that this array:
[0, 3, 1, -2, 0, -1, 1, 1, -2]
would be transformed to this string:
0,eee,e,ww,0,w,e,e,ww
If you wish to get the string back instead of just writing to the console try this:
private void testMyMethod(){
String resultString = "";
int[] array = { 0, 3, 1, -2, 0, -1, 1, 1, -2 };
for(int step : array){
String direction = convertToDirection(step);
// Adding a comma -- as you requested
// just add this in case you what to indicate a start point ==> X
if(direction.isEmpty()){
resultString = resultString.concat("X");
}
else{
resultString = resultString.concat(direction);
}
resultString = resultString.concat(",");
}
resultString = resultString.subString(0, resultString.length()-1);
myTextView.setText(resultString);
}
private String convertToDirection(int step){
String direction = "";
if(step > 0){
direction = "e";
}
else if(step < 0){
direction = "w";
}
String result = "";
int len = Math.abs(step);
for(int i = 0; i < len; i++){
result = result.concat(direction);
}
return result;
}
Edit:
A less verbose solution:
private void testMyMethod(){
int[] array = { 0, 3, 1, -2, 0, -1, 1, 1, -2 };
StringBuilder sb = new StringBuilder();
for(int step : array){
sb.append(convertToDirection(step).concat(","));
}
// Remove the last ","
sb.deleteCharAt(sb.length()-1);
myTextView.setText(sb.toString());
}
private String convertToDirection(int step){
if(step == 0) return "0";
String direction = step > 0 ? "w" : "e";
int len = Math.abs(step);
return new String(new char[len]).replace("\0", direction);
}
Borrowing this: new String(new char[len]).replace("\0", direction); from this solution:
Repeat String
You can do so by using the following code :
int arr[] = { 0, 3, 1, -2, 0, -1, 1, 1, -2 };
for (int i = 0; i < arr.length; i++) {
if (arr[i] < 0) { // west
for (int j = arr[i]; j < 0; j++) {
System.out.println("w");
}
} else if (arr[i] > 0) { // east
for (int j = 0; j < arr[i]; j++) {
System.out.println("e");
}
}
}
If the number is negative then we iterate from that value upto 0.
If the number is positive then we iterate from 0 upto that value.
We should better use char repeating instead of loops. Look at Simple way to repeat a String in java for different ways.
int arr[] = { 0, 3, 1, -2, 0, -1, 1, 1, -2 };
StringBuilder output = new StringBuilder();
for(int step : array){
int length = Math.abs(step);
if (step < 0) { // west
output.append(new String(new char[length]).replace("\0", "w"));
}
else if (step > 0) { // east
output.append(new String(new char[length]).replace("\0", "e"));
}
else output.append("0");
}
}
Related
This question already has answers here:
What is the difference between Linear search and Binary search?
(11 answers)
Closed 2 years ago.
Given an array of elements of length N, ranging from 0 to N – 1. All elements may not be present in the array. If element is not present then there will be -1 present in the array. Rearrange the array such that A[i] = i and if i is not present, display -1 at that place
So that is the question, but my binarySearch is not working, why?
for(int i = 0; i < size; i++) {
int res = i;
// System.out.println(Arrays.binarySearch(arr,res));
int result = Arrays.binarySearch(arr,res);
if(result == -1)
arr[i] = -1;
else {
arr[i] = i;
}
}
for(int i = 0; i < size; i++) {
System.out.print(arr[i]+" ");
}
Binary search works only with sorted arrays. Try using a different search algorithm
If you can use additional array, the solution may be as follows:
Create resulting array
Fill resulting array with -1
Iterate over input array and fill appropriate numbers in the resulting array.
// input array
int[] arr = {-1, 2, 3, 0};
// prepare new resulting array
int[] res = new int[arr.length];
// fill with -1
// Arrays.fill(res, -1); // use this shortcut if you're allowed to use library
for (int i = 0; i < res.length; i++) {
res[i] = -1;
}
// rearrange
for (int i = 0; i < arr.length; i++) {
if (arr[i] != -1) {
res[arr[i]] = arr[i];
}
}
System.out.println("input data: " + Arrays.toString(arr));
System.out.println("rearranged: " + Arrays.toString(res));
Output:
input data: [-1, 2, 3, 0]
rearranged: [0, -1, 2, 3]
Update
Recursive solution without using extra array:
public static void test() {
int[] arr = {-1, 4, 2, 0, 1, 3};
System.out.println("input data: " + Arrays.toString(arr));
// rearrange
for (int i = 0; i < arr.length; i++) {
if (arr[i] != -1 && arr[i] != i) {
swapAtIndex(arr, i);
}
}
System.out.println("rearranged: " + Arrays.toString(arr));
}
private static void swapAtIndex(int[] arr, int i) {
int t = arr[i];
if (t != -1 && t != i) {
int t2 = arr[t];
arr[t] = t;
arr[i] = t2;
if (t2 != -1) {
swapAtIndex(arr, i); // continue swapping at the same index
}
}
}
output:
input data: [-1, 4, 2, 0, 1, 3]
rearranged: [0, 1, 2, 3, 4, -1]
For the input array without -1, you'll get a sorted array after rearrangement:
input data: [5, 4, 2, 0, 1, 3]
rearranged: [0, 1, 2, 3, 4, 5]
This code is just printing the last bits of an array of size (s[i].length()). for suppose string is HELLO WORLD! its just printing ! binary value left rotated by one bit. Can someone help..please
suppose a[i]={202,205} a[202]=11001010 and a[205]=11000011
After Circular left Shift Output should be like
a[202]=10010101 a[205]=10000111
for (i = 0; i < s[i].length(); i++) { //loop for computing binary value
System.out.print(" " + dt[i] + " = " );
int g=7;
while(dt[i]!=0)
{
bindt[g]=Math.abs((dt[i])%2);
dt[i]=(dt[i])/2;
g=g-1;
}
for(g=0;g<8;g++)
System.out.print(bindt[g]);
}
}
for(i=0;i<s[i].length();i++) //loop for circular shift on bits
{
var=bindt[0];
for(int index=0;index<8;index++)
{
di[index]=bindt[index+1];
if(index==7)
di[index]=var;
}
}
}
The actual code is:
int power = 0,temp;
int[] a= new int[1000];
int[] m=new int[1000];
int[] dt=new int[1000];
int[] bindt=new int[100];
int[] ds=new int[1000];
int[] di=new int[50];
int[] cov=new int[100];
int arr[]=new int[10];
int var;
String d = null;
String e= null;
int bin[]=new int[8];
int bink[]=new int[8];
JFileChooser chooser = new JFileChooser(); // Browse File
chooser.showOpenDialog(null);
File file = chooser.getSelectedFile();
fileName = file.getPath();
String fn= file.getName();
System.out.println("File name is :"+fn);
FileReader fileReader = new FileReader(fileName);
BufferedReader br = new BufferedReader(fileReader);
while ((line = br.readLine()) != null)
{
System.out.println(line);
l = line.length();
System.out.println("length is " + l);
System.out.print("Plain Text={");
while ((br.readLine() != null) || (i <= l)) //computing plain text
{
s[i] = line;
i++;
}
//counting no of vowels,consonants,special symbols and spaces
for (i = 0; i < s[i].length(); i++) {
char ch = line.charAt(i);
if (ch=='e'||ch=='a'||ch=='i'||ch=='o'||ch=='u'||ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')
vowels++;
else if (line.charAt(i)==' ')
spaces++;
else if (ch=='>'||ch=='+'||ch=='}'||ch=='/'||ch=='*'||ch=='!'||ch=='#'||ch=='#'||ch=='$'||ch=='%'||
ch=='^'||ch=='&'||ch=='('||ch==')'||ch=='"'||ch==':'||ch==';'||
ch=='{'||ch=='['||ch==']'||ch=='?'||ch==','||ch=='.'||ch=='<')
ss++;
else
consonants++;
ascii = (int) ch;
a[i] = ascii;
System.out.print(+a[i]+",");
}
System.out.print("}");
System.out.print("\n");
System.out.print("Static text={");
for (i = 0; i < s[i].length(); i++) {
m[i]=(254 - ((a[i]) - (14))); //Generating static text
System.out.print( + m[i]+",");
}
System.out.print("}");
System.out.print("\n");
System.out.println("X=number of vowels = "+vowels);
System.out.println("W=number of consonants = "+consonants);
System.out.println("Z=number of special symbols = "+ss);
System.out.println("Y=number of spaces = "+spaces);
System.out.println("N=Total number of characters = "+l);
Denominator = ((l-consonants)+(l-vowels)+(l-spaces)+(l-ss));
System.out.println("Denominator is :"+Denominator);
System.out.print("Binary Value is: ");
j=7;
//loop for finding binary number
while(l!=0) // binary number computation
{
bin[j]=Math.abs(l%2);
l=l/2;
j=j-1;
}
for(j=0;j<8;j++)
System.out.print(bin[j]);
// loop for obtaining 1's complement
for(j=0;j<8;j++)
{
if(bin[j]==1)
bin[j]=0;
else
bin[j]=1;
}
System.out.print("\n");
System.out.println("Complemented value:")
d=Arrays.toString(bin).trim().replace(",","").replace("[","").replace("]","").replace(" ","").trim();
System.out.println(d);
System.out.print("Numerator: ");
Numerator = Integer.parseInt(d,2); //Computing k value
System.out.println(Numerator);
k=((Numerator)/(Denominator));
System.out.println("K =" +k);
System.out.print("Dynamic Text:{"); //Generating dynamic text
for (i = 0; i < s[i].length(); i++)
{
dt[i]=((m[i])+(k));
System.out.print( + dt[i]+",");
}
z=7;
while(k!=0)
{
bink[z]=Math.abs(k%2);
k=k/2;
z=z-1;
}
System.out.println("}");
System.out.println("Binary Value of k is: ");
for(z=0;z<8;z++)
System.out.print(bink[z]);
}
System.out.println("ASCII Values of Dynamic Text is:");
for (int h = 0; h < s[i].length(); h++) //loop for computing binary value
{
System.out.print(" " + dt[h] + " = " );
int g=7;
while(dt[h]!=0) {
bindt[g]=(Math.abs((dt[h])%2));
dt[h]=(dt[h])/2;
g=g-1;
}
List item
}
for(g=0;g<8;g++)
System.out.print(bindt[g]);
}
}
for(int h=0;h<s[i].length();h++) //loop for circular shift
{
for(int index=0;index<8;index++)
{
di[index]=bindt[index+1];
if(index==7)
di[index]=bindt[0];
}
}
System.out.println("\n Circular shift:" ); //printing obtained circular shift values
for(int h=0;h
System.out. print(" “);
for(int index=0;index<8;index++)
System.out.print(di[index]);
}
}
}
I built a test application to create a Java method that would shift the bits in an int array of length 8 one bit to the left in a circular pattern.
Here are the test results.
[1, 1, 0, 0, 1, 0, 1, 0] -> [1, 0, 0, 1, 0, 1, 0, 1]
[1, 1, 0, 0, 0, 0, 1, 1] -> [1, 0, 0, 0, 0, 1, 1, 1]
[0, 0, 0, 0, 0, 0, 1, 1] -> [0, 0, 0, 0, 0, 1, 1, 0]
As you can see, the bits are shifted one bit to the left, and the left most bit is moved to the right.
And here's the test application code. It's short, self-contained, and most important, runnable.
package com.ggl.testing;
import java.util.Arrays;
public class BitShifting {
public static void main(String[] args) {
BitShifting bitShifting = new BitShifting();
int[] bits1 = { 1, 1, 0, 0, 1, 0, 1, 0 };
shiftAndDisplay(bitShifting, bits1);
int[] bits2 = { 1, 1, 0, 0, 0, 0, 1, 1 };
shiftAndDisplay(bitShifting, bits2);
int[] bits3 = { 0, 0, 0, 0, 0, 0, 1, 1 };
shiftAndDisplay(bitShifting, bits3);
}
private static void shiftAndDisplay(BitShifting bitShifting, int[] bits) {
int[] shifted = bitShifting.shiftLeft(bits);
System.out.print(Arrays.toString(bits));
System.out.print(" -> ");
System.out.println(Arrays.toString(shifted));
}
public int[] shiftLeft(int[] bits) {
int bit = bits[0];
int length = bits.length - 1;
int[] output = new int[bits.length];
for (int i = 0; i < length; i++) {
output[i] = bits[i + 1];
}
output[length] = bit;
return output;
}
}
A circular shift left on 8 bits:
byte rotateLeft(byte b) {
boolean highBit = b < 0;
b <<= 1;
if (highBit) {
b |= 1;
}
return b;
}
This utilizes that byte is in two-complements -128 .. 127, and only negative bytes have their high bit set. For an int n one must cast to (byte)n.
I keep getting an out of bounds error whenever i try to run my code. Does anyone know what is wrong with it? I can't seem to figure it out.
public class Swapper{
/**
This method swaps the first and second half of the given array.
#param values an array
*/
public void swapFirstAndSecondHalf(int[] values) {
// your work here
int[] first = new int[values.length/2];
int[] second = new int[values.length/2];
for(int i = 0; i < values.length / 2; i++) {
second[i] = values[i];
}
for (int j = values.length / 2; j < values.length; j++) {
first[j] = values[j];
}
for(int k = 0; k < values.length / 2; k++) {
values[k] = first[k];
}
for(int l = values.length / 2; l < values.length; l++) {
values[l] = second[l];
}
}
// This method is used to check your work
public int[] check(int[] values) {
swapFirstAndSecondHalf(values);
return values;
}
}
int[] first = new int[values.length/2];
So indexes [0..values.length/2 - 1] are valid for first.
for (int j=values.length/2; j<values.length; j++)
{
first[j] = values[j];
}
So with the first value of j being values.length/2, it's already out of bounds.
You need to practice debugging, placing a break point and tracing the code as it executes.
You could have used System.arraycopy() instead of all the for looping.
public static void main(String[] args) throws Exception {
int[] values = {1, 2, 3, 4, 5};
values = swapFirstAndSecondHalf(values);
System.out.println(Arrays.toString(values));
values = new int[]{1, 2, 3, 4, 5, 6};
values = swapFirstAndSecondHalf(values);
System.out.println(Arrays.toString(values));
}
public static int[] swapFirstAndSecondHalf(int[] values) {
boolean evenSize = values.length % 2 == 0;
int half = values.length / 2;
int[] swapper = new int[values.length];
System.arraycopy(values, evenSize ? half : half + 1, swapper, 0, half);
System.arraycopy(values, 0, swapper, evenSize ? half : half + 1, half);
// The middle number stays the middle number
if (!evenSize) {
swapper[half] = values[half];
}
return swapper;
}
Results:
[4, 5, 3, 1, 2]
[4, 5, 6, 1, 2, 3]
If you're wanting the middle number, for an odd sized array, to be part of the second half then the swapFirstAndSecondHalf() would look like this:
public static int[] swapFirstAndSecondHalf(int[] values) {
boolean evenSize = values.length % 2 == 0;
int half = values.length / 2;
int[] swapper = new int[values.length];
System.arraycopy(values, half, swapper, 0, evenSize ? half : half + 1);
System.arraycopy(values, 0, swapper, evenSize ? half : half + 1, half);
return swapper;
}
Results:
[4, 5, 3, 1, 2]
[4, 5, 6, 1, 2, 3]
Allocating new arrays is a waste of space. Just swap the halves in-place:
public static void swapFirstAndSecondHalf(int[] values) {
final int len = values.length / 2;
final int offset = values.length - len;
for (int i = 0; i < len; i++) {
int temp = values[i];
values[i] = values[offset + i];
values[offset + i] = temp;
}
}
The code allows odd length, and will leave center value alone.
Lets say array one [2/3, 0, -1, 0, 7/2] and array two [0, 0, -2/3, 1, 0, 0] so I want my result array to be [0, 2/3, -2/3, 0, 0, 7/2]. The result array length will be the max length between the two arrays. How can I do this in Java?
Pretty much I want the specific index locations to add each other however I don't know how to do this with unequal arrays.
Edit: It adds the locations and anything that is unmatched is left untouched in the largest array. [0, 0, -2/3, 1, 0, 0] has location 0, 1, 2, 3, 4, 5 and array [2/3, 0, -1, 0, 7/2] has locations that coincide with the larger array as 1, 2, 3, 4, 5 so I want the same location values to be added and placed into the resultant array. I created a new resultant array and set it equal to the largest array so all that has to be done is the adding of similar location values.
Here is an elaborate and easy to understand way that I've devised:
What it does it it adds the last elements of the arrays together and moves backwards from there; if one array ends before the other, it just substitutes the value of the non-existent element with zero, then adds them:
public class ArrayAddition
{
public static void main(String[] args)
{
double array1[] = {2./3, 0, -1, 0, 7./2}; // first array
double array2[] = {0, 0, -2./3, 1, 0, 0}; // second array
int length = Math.max(array1.length, array2.length); // length of longest array
double newArray[] = new double[length]; // result must be length of longest array
int index1 = array1.length - 1; // last element of first array
int index2 = array2.length - 1; // last element of second array
int indexRes = length - 1; // result will be placed in last spot of result
for (int i = length -1; i >= 0; i--) // adds elements of two arrays together bckwrd
{
double val1, val2; // value holders for array elements
try // try to get value of the array 1 at certain position
{
val1 = array1[index1];
}
catch(ArrayIndexOutOfBoundsException e) // if empty, make it zero
{
val1 = 0;
}
try // try to get value of array 2 at certain position
{
val2 = array2[index2];
}
catch(ArrayIndexOutOfBoundsException e) // if empty make it zero
{
val2 = 0;
}
newArray[indexRes] = val1 + val2; // array[?] result is val1 + val 2
index1--; // decrement to the next lower value
index2 --; // decrement to the next lower value
indexRes--; // go the next lower spot
}
for (int i = 0; i < newArray.length; i ++) // this loop prints out the results
System.out.println(newArray[i]);
}
}
You need to enter your values as doubles or the answers will be incorrect (2./3 instead of 2/3)
0.0
0.6666666666666666
-0.6666666666666666
0.0
0.0
3.5
Answers will be in decimal form, for obvious reasons (if answer is 2 / 3, it actually divides 2 by 3, still the correct answer, you can convert it back)
Hopefully this helps! :)
Go through your arrays starting at the end and add the 2 values putting them into a new array with the size of the largest array.
int a = arrayA.length-1;
int b = arrayB.length-1;
double [] result = new double[Math.max(arrayA.length, arrayB.length)];
double sum = 0;
while(a >= 0 || b >= 0) {
if(a>=0) sum+=arrayA[a];
if(b>=0) sum+=arrayB[b];
result[Math.max(a, b)] = sum;
sum = 0;
a--;
b--;
}
This should do it. Note that this code is missing the declarations of the array variables.
if (array1.length > array2.length)
array3 = addArrays(array1, array2);
else
array3 = addArrays(array2, array1);
int [] addArrays(longArray, shortArray) {
int index;
for (index = 0; index < longArray.length - shortArray.length; index++) {
array3[index] = longArray[index] + 0;
}
for (int i = 0; i < shortArray.length; i++, index++) {
array3[index] = longArray[index] + shortArray[i];
}
return array3;
}
import java.util.Scanner;
public class ArrayAdd {
public static void main(String args[]) {
Scanner a = new Scanner(System.in);
int m = a.nextInt();// First array's size
int n = a.nextInt();// Second array's size
int arr1[] = new int[m];
int arr2[] = new int[n];
for (int i = 0; i < m; i++) {
arr1[i] = a.nextInt();
}
for (int i = 0; i < n; i++) {
arr2[i] = a.nextInt();
}
a.close();
if (m < n) {
int difference = n - m;
int arr3[] = new int[n];
for (int i = 0; i < n; i++) {
if (i < difference) {
arr3[i] = arr2[i];
} else {
arr3[i] = arr1[i-difference] + arr2[i];
}
System.out.println(arr3[i]);
}
} else {
int difference = m - n;
int arr3[] = new int[m];
for (int i = 0; i < m; i++) {
if (i < difference) {
arr3[i] = arr1[i];
} else {
arr3[i] = arr1[i] + arr2[i-difference];
}
System.out.println(arr3[i]);
}
}
}
}
I have an array, say
int a[]={2,0,1,0,1,1,0,2,1,1,1,0,1,0,1};
I need to append each of the 5 neighboring elements and assign them to a new array b with length=(a.length/5); and i want to append the 5 neighboring elements so that I have:
int b[]={20101,10211,10101}; I need to do this for various length arrays, in most cases with length of a being greater than 15.
Any help would be greatly appreciated, I'm programming in Java.
Thanks in advance.
It's pretty straighforward:
// Assuming a.length % 5 == 0.
int[] b = new int[a.length / 5];
for (int i = 0; i < a.length; i += 5) {
b[i/5] = a[i]*10000 + a[i+1]*1000 + a[i+2]*100 + a[i+3]*10 + a[i+4];
}
This sounds like a homework question, so I won't give you the complete solution, but the basic rundown is:
Compute the length of b: len = a.length / 5
Construct b with that many elements.
Initialize an index variable to point to the first element in a
For each element in b:
Construct the value for that element from a[idx]...a[idx+4]
Advance the index into a by 5.
Also note that you may need to verify that the input a is actually a multiple of 5 in length.
This works with (a.length % 5) != 0, and keeps leading zeroes (by storing digits into String).
int a[]={2,0,1,0,1,1,0,2,1,1,1,0,1,0,1,0,0,7};
final int N = 5;
String b[] = new String[(a.length + N - 1)/ N];
StringBuilder sb = new StringBuilder(N);
int x = 0;
for (int i = 0; i < b.length; i++) {
sb.setLength(0);
for (int k = 0; k < N && x < a.length; k++) {
sb.append(a[x++]);
}
b[i] = sb.toString();
}
System.out.println(java.util.Arrays.toString(b));
// prints "[20101, 10211, 10101, 007]"
Alternately, you can also use regex:
String[] arr =
java.util.Arrays.toString(a)
.replaceAll("\\D", "")
.split("(?<=\\G.{5})");
System.out.println(java.util.Arrays.toString(arr));
// prints "[20101, 10211, 10101, 007]"
Basically this uses Arrays.toString(int[]) to append all digits into one long String, then removes all non-digits \D, then uses \G-anchored lookbehind to split every .{5}
Naive approach.
import java.util.ArrayList;
/* Naive approach */
public class j2728476 {
public static void main(String[] args) {
int a[] = {2,0,1,0,1,1,0,2,1,1,1,0,1,0,1};
ArrayList<String> al = new ArrayList<String>();
String s = "";
for (int i = 0; i < a.length; i++) {
if (i % 5 == 0 && i != 0) {
al.add(s);
s = "" + a[i];
} else {
s += a[i];
}
}
al.add(s);
for (String t : al) {
// convert values to ints ...
System.out.println(t);
}
}
}
Will print:
20101
10211
10101
import java.util.Arrays;
public class MainClass {
public static void main(String args[]) throws Exception {
int array[] = { 2, 5, -2, 6, -3, 8, 0, -7, -9, 4 };
Arrays.sort(array);
printArray("Sorted array", array);
int index = Arrays.binarySearch(array, 1);
System.out.println("Didn't find 1 # "
+ index);
int newIndex = -index - 1;
array = insertElement(array, 1, newIndex);
printArray("With 1 added", array);
}
private static void printArray(String message, int array[]) {
System.out.println(message
+ ": [length: " + array.length + "]");
for (int i = 0; i < array.length; i++) {
if (i != 0){
System.out.print(", ");
}
System.out.print(array[i]);
}
System.out.println();
}
private static int[] insertElement(int original[],
int element, int index) {
int length = original.length;
int destination[] = new int[length + 1];
System.arraycopy(original, 0, destination, 0, index);
destination[index] = element;
System.arraycopy(original, index, destination, index
+ 1, length - index);
return destination;
}
}
It will print
Sorted array: [length: 10]
-9, -7, -3, -2, 0, 2, 4, 5, 6, 8
Didn't find 1 # -6
With 1 added: [length: 11]
-9, -7, -3, -2, 0, 1, 2, 4, 5, 6, 8