Looking Ahead to Spring 2019

note jan 23, 2019note jan 23, 20192

The Separation of Screens and Mental States

I am exhausted from the cross-platform-ness of everything.

Once upon a time, my life, and maybe even yours, used to have a phone, an mp3 player, a desktop, a gaming console, and finally, a television.

We used a phone to text and call. We used an mp3 player to listen to music. We used a desktop for browsing the web for work, to keep in touch with friends. We used a gaming console for games. We used the television to get the news and weather, sports, and tuned in to primetime television shows together with friends and family.

Our everyday lives used to revolve around five distinct devices, but each served a different function.

Nowadays, I still have most of those devices, except what I am doing with them has changed.

I’m checking emails on my phone. I am checking that same email account of my laptop at the coffee shop, and then open up that same email account back at work on my work desktop.

I’m watching Netflix on my television, later I am watching that same Netflix show on my tablet, and if I am deeply committed to binge through the show, I can be found in a haze staring at my iPhone on my commute to and from work.

I am no longer getting a different experience from each of the devices. Instead, I find myself doing the same thing across different screens.

This has to stop.

I appreciate that companies have invested in making their applications available across any and all devices, but I am going to take the initiative to say, “thanks, but no thanks.”

The first decision I am making is that if I want to watch a show, or a movie, or more often the highlights from last night’s game, I must watch them on the television. The television has the SmartTV features built in, so whether its Netflix or YouTube, I must watch them on and only on my television screen.

Next, my laptop.

I want to use my laptop for reading, writing, and programming–browsing the web, reading blogs, writing emails, developing programs. The laptop will not be used for watching any form of video content unless they are the instructional sort and needed for work. What about social networks? I want to take care of all those interactions on my laptop. Which means that any and all video conferences must be done through my laptop’s webcam: Facetime, Messenger video calls, Skype video meetings, all of those activities must be on my laptop.

Finally, my iPhone, the most personal device in our lives.

The first decision I have made is to take away the ability to browse the web from my iPhone. What? Yes, I have uninstalled both Google Chrome as well as the Google search applications. What about Safari? I was never a fan of Safari, so that app is easy to hide away in an app folder.

Next, I removed any and all video streaming services from my phone: goodbye YouTube, Netflix. After that, I uninstalled all social media and messenger applications because from now on I must do those tasks on a laptop, thank you very much. Last but not least, I got rid of all my email applications: no Outlook, no Gmail (again, we have laptops for that sort of things).

What I do want from my iPhone is to give me my phone calls (voicemails since I never pick up on any phone calls) and texts. I then need it to hold my ebooks and music collections, because reading on an OLED screen is more enjoyable than on a Kindle, and of course I need my music. Finally, I need my iPhone to take and store great photos of my friends, family, and documents. This has never been an issue, and Google Photos’ unlimited storage supports to keep them backed up.

I love technology. If you had told my seven-year-old self that I would one day have all these cool devices, I would have been so much more excited to become a grown up. But then, if you had then met up with an adolescent version of me, and had told him that all those cool devices just did the same thing each and every day, over and over again, he would have asked about how our future society became enslaved to devices–Orwell was a big part of my teenage years. What about my twenty-year-old self? He would wonder if I was or wasn’t making content for all those devices.

Which brings us to now, where I am in the earliest days of my fourth decade, and I am exhausted from how overbearing these devices have become in my life. Now, through explicating my thoughts in this essay, I want to establish a new separation of screens and mental states in hopes to regain a focused, energized, and peace of mind.

Equivalent Arrays

If you’re taking Jerry Waxman’s 211 course on C++, a required course for anyone majoring in Computer Science at Queens College-CUNY, the following is the second homework problem.

Consider the two arrays a and b.

The problem here asks you to write out a function that will take two arrays of the same size and determine whether or not they are “shift equivalent,” which means if I moved one of the arrays a certain number of times clockwise, that array will transform into the first array.  Does that make sense, if not leave a comment below.

For example, array b can be transformed into array a by shifting members of array b 2 positions to the right:

b:  3 – 4 – 5 – 1 – 2

b: 2 – 3 – 4 – 5 – 1

b: 1 – 2 – 3 – 4 – 5


Write a function


Let’s get started on writing this program.  Let’s get the basic stuff typed into our file.

#include <iostream>
using namespace std;

Next, I am going to type in the function prototype before introducing the main function.

#include <iostream>
using namespace std;

bool equivalent(int a[ ], int b[ ], int n);

int main( ) 
{

     return 0;
}

Now, I am going to take the requirements of the function given to me in the problem description and translate them into code.  

So, I’m going to be given two arrays and if one of the arrays can be shifted a certain amount of times to the right and becomes equivalent to the other, then the two arrays are “shift equivalent” arrays.  Ok, the first thing I need to determine is to find the shift.  To do this, I am going to pick one of the arrays and select the first element in the array, then, using a for loop, compare that element to the elements of array b until a[0] is equal to b[i].  When this is the case, we have found the shift.  

// Going to need a variable to store the shift
int shift = 0;

// To process through the elements of an array, I’m going to need a for loop
// For the conditional i < n, n is the size of the array
for (int i = 0; i < n; i++) {
     if (a[0] == b[i])  shift = i;
}

Now that we think we have the shift, we need to test it out.  We need to apply the shift to the second array, b, and see if it is equivalent to the first array, a.  I am also going to need a variable to hold the boolean true or false, which is why I am going to start out with initializing a variable called answer to false.  Then, once again, to process through any array we will be needing a for loop.  Now that we know of the shift, we won’t have to process i until it’s less than n, instead, our for loop will start at 0 and loop until i is less than n – shift.  Why?  Let’s think about that after the block of code.

bool answer = false;

for (int i = 0;  i < n – shift;  i++) {
  if  (a[i] == b[ i + shift ]) answer = true;
  else  return false;
}

The question now is, why is the array being processed until i is less than n – shift?  Let’s use the example of array a and array b from earlier above.  The shift was 3.  Now let’s see what happens when we process that for loop:

= n – shift 
= 5 – 3
= 2

a[i] == b[i+shift]

a[0] == b[0 + 3]
a[0] == b[3]
1 == 1 

a[1] == b[1 + 3]
a[1] == b[4]
2 == 2

a[2] == b[2 + 3]
a[2] == b[5]

3 =? b[5]?
b[5] doesn’t exit in this array

Arrays in C++ are zero-based indexed.  This means the first element is accessed in the 0th position, not in the 1st position.  With that in mind it makes sense why the conditional in our for loop has to be i < n – shift, because that will be where our second array’s index will fall off.  This situation requires us to include a second test for our function:

for (int j = n – shift; j < n; j++) {
  if ( a[j] == b[ (j+shift) % n] ) answer = true;
  else  return false; 
}

return answer;

In this second test, I am using the modulo operator.  This modulo operator works to move the last element of the array to the first element, moving it clockwise to the other side.  It’s sort of like in Pac Man, when you went through a gate on the right side of the screen, you reappeared on the left side of the screen. 

Another thing to recognize is that I am initializing j as equal to (n – shift), so that we can cycle through all five positions of the array.  On top of that, we make up for the subtraction by adding the j to the b array shift value.  

Finally, since we passed our arguments through two levels of testing, we can finally send back an answer to the function call from the main function.  Speaking of main, lets code that up now:

int main( ){

  // Going to need two arrays of size 5
  int a[5], b[5];

  // Let’s nicely ask the user to give us five integers
  cout << “Yo, enter five integers: “; 

  // Going to need for loops to plug the inputs into the array
  for (int i = 0; i < 5; i++)  cin >> a[i];

  // Ask for another 5
  cout << “5 mo: “;

  // Another for loop:
  for(int i = 0; i < 5; i++) cin >> b[i];
  
  // Flush the iostream buffer with an endl
  cout << endl;

  // Now let’s initialize a variable to hold the boolean value
  // from function call to equivalent
  bool answer = equivalent(a, b, 5);

  // If answer == true, then the shift equivalent exists!
 // Else, none

  if ( answer == true ) cout << “Shift Equivalent!” << endl;
  else cout << “Nope, not equivalent.” << endl;

  return 0;
}

Did all of that make sense?  Try it out on your computer and let me know if it works.  

If the code doesn’t work, leave a comment below detailing where the code failed.  Or, if you have suggestions on how to make this program more efficient, let me know kindly in a comment below.

Where’s The Struggle?

Honestly, you don’t learn without first struggling with what you want to learn.

I realized this the other day when I was wondering why I suck in my C++ class.  I have perfect scores on my projects, but my midterm scores say otherwise.   That’s when this epiphany came, I had perfect scores because I had ways of searching Google for ways of solving the problems.

Where was my struggle?  I wasn’t thinking.  I was Googling, which totally messed up the learning process.

I have two more weeks before the final exam.  To correct my ways, I am starting over and inviting the struggle and stress to enter my life.

Update: Two assignments in, the struggles have begun to teach me.