Problem 1-1 Binary Bulbs

Table of Contents

Objectives

  • Continue experimenting with Scratch.
  • Get a taste of remixing and working with distribution code.
  • Start thinking about what constitutes good design.
  • Creatively extend the work of others.

Academic Honesty

This course’s philosophy on academic honesty is best stated as “be reasonable.” The course recognizes that interactions with classmates and others can facilitate mastery of the course’s material. However, there remains a line between enlisting the help of another and submitting the work of another. This policy characterizes both sides of that line.

The essence of all work that you submit to this course must be your own. Collaboration on problems is not permitted (unless explicitly stated otherwise) except to the extent that you may ask classmates and others for help so long as that help does not reduce to another doing your work for you. Generally speaking, when asking for help, you may show your code or writing to others, but you may not view theirs, so long as you and they respect this policy’s other constraints. Collaboration on quizzes and tests is not permitted at all. Collaboration on the final project is permitted to the extent prescribed by its specification.

Below are rules of thumb that (inexhaustively) characterize acts that the course considers reasonable and not reasonable. If in doubt as to whether some act is reasonable, do not commit it until you solicit and receive approval in writing from your instructor. If a violation of this policy is suspected and confirmed, your instructor reserves the right to impose local sanctions on top of any disciplinary outcome that may include an unsatisfactory or failing grade for work submitted or for the course itself.

Reasonable

  • Communicating with classmates about problems in English (or some other spoken language).
  • Discussing the course’s material with others in order to understand it better.
  • Helping a classmate identify a bug in his or her code, such as by viewing, compiling, or running his or her code, even on your own computer.
  • Incorporating snippets of code that you find online or elsewhere into your own code, provided that those snippets are not themselves solutions to assigned problems and that you cite the snippets’ origins.
  • Reviewing past years’ quizzes, tests, and solutions thereto.
  • Sending or showing code that you’ve written to someone, possibly a classmate, so that he or she might help you identify and fix a bug.
  • Sharing snippets of your own solutions to problems online so that others might help you identify and fix a bug or other issue.
  • Turning to the web or elsewhere for instruction beyond the course’s own, for references, and for solutions to technical difficulties, but not for outright solutions to problems or your own final project.
  • Whiteboarding solutions to problems with others using diagrams or pseudocode but not actual code.
  • Working with (and even paying) a tutor to help you with the course, provided the tutor does not do your work for you.

Not Reasonable

  • Accessing a solution to some problem prior to (re-)submitting your own.
  • Asking a classmate to see his or her solution to a problem before (re-)submitting your own.
  • Decompiling, deobfuscating, or disassembling the staff’s solutions to problems.
  • Failing to cite (as with comments) the origins of code, writing, or techniques that you discover outside of the course’s own lessons and integrate into your own work, even while respecting this policy’s other constraints.
  • Giving or showing to a classmate a solution to a problem when it is he or she, and not you, who is struggling to solve it.
  • Looking at another individual’s work during a quiz or test.
  • Paying or offering to pay an individual for work that you may submit as (part of) your own.
  • Providing or making available solutions to problems to individuals who might take this course in the future.
  • Searching for, soliciting, or viewing a quiz’s questions or answers prior to taking the quiz.
  • Searching for or soliciting outright solutions to problems online or elsewhere.
  • Splitting a problem’s workload with another individual and combining your work (unless explicitly authorized by the problem itself).
  • Submitting (after possibly modifying) the work of another individual beyond allowed snippets.
  • Submitting the same or similar work to this course that you have submitted or will submit to another.
  • Using resources during a quiz beyond those explicitly allowed in the quiz’s instructions.
  • Viewing another’s solution to a problem and basing your own solution on it.

Assessment

Your work on this problem will be evaluated along two axes primarily.

Scope
To what extent does your code implement the features required by our specification?

Correctness
To what extent is your code free of bugs?

To obtain a passing grade in this course, all students must ordinarily submit all assigned problems unless granted an exception in writing by the instructor.

Light Bright

Recently, you may have watched Nate’s short on binary numbers. If you haven’t seen it (or don’t recall having done so) or you wish to have another peek at it, we’ve put it here below. If you remember all of the information in that video, feel free to skip past it.

Not long ago, we thought it would be a fun idea to create a more interesting demonstration for binary numbers, and two members of our staff, Ansel and Dan, put together a rig made up of Hue light bulbs (a type of LED, color-changing lightbulb with an application programming interface—API—that allows them to be controlled wirelessly over the Internet) and an associated iPad app. After all, since the 0s and 1s of binary are implement on some machines with transistors (very small pieces of electronic equipment), we thought it would be particularly appropriate to create a demonstration that relied heavily on electricity as a means of representing binary.

How did it go over? Have a peek at two recent CS50 students having a turn playing a game with the binary bulbs rig both in standard mode and in a more challenging mode, with the place value hints removed.

Another member of our staff, Michael, also built a version of the binary bulbs came for online play. Turn on Game Mode a few times and challenge yourself with these inputs, one game at a time:

  • 50
  • 127
  • 42
  • 256

If you’d like, turn the bulbs off to see the underlying bits that they represent. Better yet, turn the labels off to challenge yourself all the more.

Play Michael’s online version of binary bulbs here.

No pressure of course, but it’s worth noting that by the end of your time in this course, you might very well be ready to design and program an iPad app just like the one Dan wrote for controlling the binary bulbs rig, or to write an online widget like the one Michael wrote!

We’ve Just Scratched the Surface

In Problem 1-0, your charge was to explore Scratch, tinkering around with puzzle pieces as you saw fit and creating a project entirely of your own design. To that end, you may not have had the chance to explore all facets of Scratch, including one of the features that makes it such a fun language to play with—remixing.

In the context of Scratch, remixing a project means creating a copy of its sprites and scripts (which is saved online in your Scratch account), and then putting your own unique twist on those sprites and scripts to create a Scratch project that draws inspiration from the original but takes it one step further in some way.[1]

Computer scientists actually do this all the time. As we’ll soon see when we begin programming in C, we as programmers have access to a wonderful and wide-ranging suite of libraries and built-in functions that will make our ability to write programs that much easier. By standing on the shoulders of the giants who came before us, to paraphrase Isaac Newton[2], we’ll be empowered to write programs that use those building blocks and do so much more.

So let’s get to remixing. If you head to https://scratch.mit.edu/projects/75558248/, it looks as though Doug was in the middle of building a Scratch-based replica of the CS50 binary bulbs rig, but failed to complete it. Try it out yourself for a minute or two. In particular, what you may notice is that while the bulbs all turn on and off when clicked, and hints of functionality for a standard and Hacker mode exists (simulating the placement and removal of the place-value hinting magnets), there is no way to win this “game.” When you click Guess button, the sprite simply says “TODO” for a few moments. Even if all the correct light bulbs are lit up when the button is pressed, seems it’s impossible to win the game.

Let’s help Doug out and finish this game for him!

If you’re logged into your Scratch account, which you likely created in the last problem[3], head to Doug’s project, then click See Inside to have a peek at what underlies this Scratch project. Seems there are currently 46 scripts and 19 sprites, though many of those sprites share nearly identical scripts. For example, each of the eight light bulb sprites have the same scripts for turning on and off (switching costumes) when clicked, and similarly the eight sets of “magnets” for the place values simply appear or disappear depending on whether the button in the bottom-right corner says “Hints On” or “Hints Off” (again, two different costumes).

Click on the sprite for the Guess button. Ah! There’s the culprit. Right now there’s just a puzzle piece that for saying “TODO”—surely a note to Doug’s future self to eventually replace that with Scratch puzzle pieces that would be more meaningful. Your first task for this assignment is to replace that TODO. But to do that, you’ll first need to download Doug’s project, either by clicking the Remix button near the top of the page or by choosing File… Download to your computer if you’re planning on using Scratch’s offline editor for this problem.

When replacing the TODO, you need only provide the most basic of functionality in order to indicate whether the player has won the game. For example, you could have the button say “Congratulations” if the user has lit up the correct bulbs and “Try Again” otherwise. Be sure to poke around in the scripts Doug wrote for the light bulb sprites and see how he detected whether a bulb was turned on or off. While indeed there are many ways of solving this part of the problem, and indeed Doug’s means of doing so is not necessarily the optimal one, odds are you’ll be able to draw some inspiration from the “distribution code” you’re remixing.

Just one other note before you begin. It’s tempting when solving problems, but particularly when solving programming problems, to dive straight in and add lines of code (or, in this case, drag and drop puzzle pieces), but we’d encourage you to stop and explore the options available to you before doing so. What problem are you trying to solve, and how are you trying to solve it? How can you solve it most efficiently given the tools at your disposal? A program that adds two numbers correctly all the time is great… but if it takes an hour to do it, it might not be the best-designed adder out there. We’ll flesh out in more detail in the coming weeks and months these notions of design and separating a program that works from a program that works well, but for now just be sure to skim all of the puzzle pieces Scratch provides (which you may not have done the first time you wrote a Scratch program) and see if and how you might be able to use some of them to develop a more elegant solution; you won’t be graded on the strength of your design for this particular problem.

Standing on Our Shoulders

Neat, you’ve completed your first remix of a Scratch project and the game is telling users whether they’ve won or not! Congratulations!

Let’s try to kick things up a notch, now.

The rest of your task for this problem is, quite simply, to add two additional features to it. To be clear, these two features must be implemented in order to earn full Scope points for this problem, but the precise nature of these features are entirely up to you. If unsure of just how to further remix the game, allow us to give a few suggestions:

  • Add some sounds.
  • Have the light bulbs light up in green when the user wins the game, as the real binary bulbs rig does.
  • After the user wins the game, automatically generate a new target number for them instead of requiring the user to click the green flag to start over.
  • Tell the user how many bulbs they have correctly and/or incorrectly lit up.
  • Implement a new variable that displays to the user their guess, that adjusts based on what bulbs they’ve turned on or off.
  • Implement a countdown timer, giving the user a limited amount of time to win the game.

Of course, you needn’t choose any of these if you don’t want to, these are simply a jumping off point.

Incidentally, once finished with your project you should not share it publicly on the Scratch website. The reason for this is that many of your peers will all be remixing the same original project and if you were to share your solution that would take the fun out of solving the problem for everyone else (not to mention would run you afoul of the course’s academic honesty policy). 😦

Instead, what you should do once you’ve finished is download your completed project to your computer (as via File… Download to your computer), which should save your project as a .sb2 file in your Downloads folder; rename the file to something identifying the project as your own; and then follow your teacher’s instructions for collecting your downloaded Scratch projects.

This was Problem 1-1.


1. Alternatively, you could download all project’s assets and remix the project using the offline editor!
2. By the way, did you know that the whole “apple-falling-on-his-head” thing is at least partially a myth?http://www.todayifoundout.com/index.php/2013/10/origin-apple-falling-newtons-head-story/
3. If you didn’t, you can now by heading to http://scratch.mit.edu/ and signing up for an account (if you are 13 or older) on MIT’s website by clicking Join Scratch atop the page, then selecting a username and password of your choice
Advertisements