Showing posts with label projects. Show all posts
Showing posts with label projects. Show all posts

Saturday, January 24, 2026

Dice As a Design Problem

The other day I ran into an interesting programming exercise on BlueSky.

The project description is at 2D Dice Grid Scoring Algorithm - 101 Computing It’s a cool project. I decided to code up a solution myself. Now there is sample starter code at that link in Python. I do my fun programming in C# so I started from scratch.

The first thing I had to do was to think about a Die class. I’ve written classes for dice projects many times before. It was a favorite item for me to use when teaching students about designing classes. Just about everyone is familiar with dice. I also brought in some samples to use as visual aids. I had some binary dice with only ones and zeros and some role playing dice in a variety of shapes and numbers of sides.

Students generally come up with the idea that they need to have a face value for the die. They generally also easily come up with the need to display that value and methods to change it to a random value. What they don’t always remember right away is that no all dice have six sides. Some dice have many more than six sides. Eventually they come up with two sided dice which we sometimes call coins.

I had a couple of example Die classes from other projects but I decided I wanted to be a bit more visual. So I created an object with the ability to display images. For this particular project I also added an extra method. I added a method to return if the face value was even – a Boolean value – true for even, false for odd. You know, just to make things interesting. Right now it is a method but I want to change it to a property to avoid unneeded parentheses.  I am not a fan of parentheses.

I did cheat a little. I had Copilot create some of the initial work on the code. Copilot, like my students, assumed a six sided die with values from one to six. I didn’t specify much so that’s understandable. It’s not really satisfying for me though so I will be putting some extra work into things to make the class more flexible. I will add constructors that let a program use different images and numbers of images. After all, just as not all die have six sides not all die have numbers or pips on them.

What would/do you add to die objects to make them more interesting or useful?

My project looks like this BTW.

Wednesday, November 26, 2025

Monty Hall Problem and the Problem of Artificial Intelligence

I’m always looking for interesting projects. The other day I ran into the story of the Monty Hall Problem. The brief version of this logic/probability problem is based on a famous game show. In the hypothetical, a player is trying to win a car. Behind two doors are goats with a car behind the third. The player picks one of the doors. Before opening the door the show host opens a door, a different door, and shows that there is a goat behind it.

The player is then given a choice – stay with their first guess or switch to the different door. What’s the best option? The answer from Marilyn vos Savant who has the highest recorded IQ was that the player should change their guess.

This answer was highly controversial with many experts in probability and math saying she was wrong. Computer simulations showed that she was right though. There is an explanation for this in the Wikipedia article linked to at the top of this post.

If you know me at all, you can probably guess that I had to write a simulation myself. Trust but verify! I think it makes a good project to assign students as well.

There is a little fly in the ointment for me though. I crated a project with the name “Monty Hall” and with almost no other hint than that and Copilot in Visual Studio started writing code for the simulation!  Well, that was a surprise.  I have mixed feelings about the help. It made writing the simulation easier for me but it kind of took some of the fun away from it as well.

Copilot’s code assumed form objects that I had not created as well. It didn’t create those objects automatically. Fortunately for me, I know enough about Visual Studio and Windows Forms that I could add them easily enough. I am also experienced enough that I added other code and objects to make the project more me.

Also, as an experienced programmer, I was able to easily understand the generated code. The code generated is a little different than what I would have generated. Better? Worse? Really, just different. No big deal for an experienced programmer.

What about students? As teachers, we probably don’t want students having AI write 90% of their code for them. Copilot can be turned off and doing so is a very good idea in classroom and school lab situations.

Will students understand the generated code? In many cases, probably not. In this case, the generated code used the the ternary conditional operator. This is a perfectly valid operator in C#, Java, C++, and several other languages. It’s not often taught to beginners however. It also used a break statement which a lot of software purists do not approve of and strongly teach against.

So determining if a student used AI to write their code may, in some cases, be easy to determine. Not something you want to bet on though.

Circling back to the assumptions that Copilot makes – like objects and variables not defined automatically – students may struggle with adding the missing pieces. I would expect that in some cases trying to add what AI leaves out may be more problematic than writing code on ones own. Frustration is a common problem for students already. Artificial Intelligence may, in some cases, exacerbate the problem.

As I have noted in several blog posts, AI often creates solutions different from how I would code them. That has been a learning experience for me. I love seeing different solutions, different language features, or features used differently.

It is potentially a learning experience for students as well. My concern is that without a solid knowledge base will students be able to really understand and learn from AI generated code? Some will. Many will not.

We’re all trying to figure out what artificial intelligence means for software development and especially for teaching software development. It’s going to be a wild ride for a while.

Monday, November 03, 2025

Flag on the Play AI Let Me Down

My latest coding involves an attempt to memorize nautical signal flags. I’ve played with this idea in the past but never had the time to really dig into it. I’ve had images of the flags for years. I’d even started created a class to hold the data.

Image _flag;
String _mnemonic;
String _shortName;
String _morseCode;

Yes, at some point I want to learn Morse Code as well. Always plan for additions. Semaphore is in my thinking as well.

Once again, Copilot, the AI in Visual Studio, has jumped in to help. Or to try to help. It was pretty helpful with some tedious coding. Specifically, with a couple of lines entered it figured out how I wanted to add images and what not to the individual flag objects I wanted to create. Hitting tab and return was pretty easy compared to typing whole lines in.

A = new Flag(Flag_Host.Resource1.alpha, "Alpha", "A", ".-");

I had already added the image files to the project of course. Copilot was not always so helpful though. I created a couple of additional forms for the project and wanted to pass the array for flags objects to the new forms. Copilot struggled to code that properly and there were several false starts.  I used to do that sort of thing regularly but it’s been a few years. I guess my memory isn’t what it used to be. I finally figured it out. Honestly, this should have been easy for Copilot and for me.

I have heard from a number of teachers about how Copilot is showing up in their classes. One teacher uses MonoGame and tells me that Copilot is so unreliable with MonoGame that his students turn it off. My suspicion is that there is not enough good MonoGame code loose on the internet to properly train Copilot.

That leads to a major concern I have about using AI for coding. It’s usability and reliability depends on the quality and quantity of the code used to train it. Programmers love to reinvent the wheel so there is a lot of code available for doing common things in coding. I would expect AI to handle most common data structures pretty well. Some things that are not as common may not have as much code to study. I wonder how well AI will handle new programming languages?

I also wonder how well AI will handle new and unique problems. Will the AI be dependent on very detailed prompts from user developers? I think that is likely. I also think that some person is going to have to do a lot of verification of said code. We are still going to need people who can read and write code.

In a related note, several times while writing this post, I have dipped into raw HTML because I didn’t like how the program I use, Windows Live Writer, was formatting the text.

Friday, October 31, 2025

Unexpected Help With Coding Projects

Fair warning, this is a post in two parts. First a project idea and second musings on the tools I used to create it.

I really do like to write code for fun. Nothing complicated (been there, done that, got the T-shirt - literally) but just little things to "scratch an itch" as they say.

Lately as I played Wordle I was wondering which letters appeared most in each place in the five letter words in my word list. A couple of nights ago, I wrote some code to find out. I had my code output a comma delimited file so I could use Excel to look at the results. That’s what the image to the side shows.

Now this sort of thing is highly dependent on the word list of course. But for my list, S is the most common letter in the first and fifth location. Not surprising as S is used to make plurals. Wordle doesn’t use plurals so I note that the second most common fifth letter is E with Y a close second.

The letter A is the most common second and third letter. The letter E is the most common fourth letter.

If I were ambitious, I could probably use this information to make a smarter Wordle solver. I’m not quite that ambitious though. I am toying with gathering some other statistics though.

I develop using Visual Studio – the full blown version. That means that Copilot jumps in to help. That’s not something I anticipated when I started but I confess that I found it surprisingly helpful. I did specifically ask Copilot to write one specific method – generate a string array of two character combinations – but it jumped in on its own with a couple of small bits of code. I was surprised at how well it anticipated what I wanted.

The implications for teaching programming are something to think about. On one hand it’s scary that AI tools can so easily write coding solutions to simple programming assignments. That turns our process of evaluating learning on its head a bit. At the same time, I am not ready to blindly trust AI generated code. I do not want students to blindly trust it either. So asking students to test generated code seems like a reasonable thing to assign. Yes, I suppose some students will ask AI to generate test cases but if we can’t trust AI to write the code in the first place we can’t trust the generated test cases.

We could ask students to explain the test and related tests. Could be quite a recursive rat hole.

We can also ask students to explain the generated code. We should probably ask them to do that either verbally or by writing manual in class so they can’t ask AI to do it for them.

What I keep coming back to in my own thinking is a focus on abstraction and top down design. Can we ask students to break the problem down to component parts and have them prompt the AI to implement various methods and code pieces. A focus on design rather than writing code. We could have students submit the design document and the various prompts that they use. Add to that some serious examination of testing and verification.

Students are going to have to work with artificial intelligence. They can’t let it do all the work for them because AI is not I enough yet. I don’t think it ever will be either.

Sunday, October 26, 2025

User Interfaces and Microwaves and Artificial Intelligence

It seems like just about everything has a user interface these days. It is sometimes hard for me to question them. What sort of decisions go into their design? Microwaves are one such thing that I keep thinking about. My current microwave defaults to pushing a number button running that many minutes. That’s great when you want it to run in whole numbers of minutes. What about fractions of minutes?

For fractions of minutes there is a button that is pressed first to let the microwave know you want to enter the number of seconds. So far so good. It can get complicated though if you don’t have the default whole minutes option.

My previous microwave did not default to whole minutes. If you enter 100 is that one hundred seconds or 100% of a minute? i.e 60 seconds? How is the decision made on something like that? What is intuitive to the user? Actually, I don’t know what my current microwave would do if I asked to seconds and entered 100. I think it would do 100 seconds as 90 does run for a minute and a half. I should try it I suppose.

It’s a computer related question of course because there is a little microprocessor in there somewhere and someone has had to program answers to these questions. I wonder how artificial intelligence would make UI decisions about things like this. It largely depends on the instructions or prompts given to the AI. People are going to have to have some input there. Right?

Will AIs have access to research on things like that? Will they be able to design and run human factors research? Will they think research is necessary or even desirable or just assume they know what is best for us?

Sunday, August 24, 2025

Tiny Book of Simple Cryptography

For the last several years, I have been playing around with simple cryptography. I have made some of results of this available as a free PDF download as a book I call Tiny Book of Simple Cryptography. (TinyCrypto.pdf) I recently put some additional work into it and the latest version is available at the link above.

There are currently a baker’s dozen cryptographic methods described in the book. (List at the bottom of this post) Each write up includes a section on:

  • Introduction
  • Encrypting
  • Decrypting
  • Cryptography Issues
  • Project Suggestions

If a PDF is not to your liking and you would like an actual book, I have created a book you can order through Amazon.com. Maybe for a classroom or school library? Or maybe because you find books easier to browse through. It’s there. There is also a Kindle version available here.

 

Methods covered

  • Caesar Cipher
  • Vigenère cipher
  • Wheel Cipher
  • One Time Pad
  • Polybius Square
  • PigPen Cipher
  • Columnar Transposition Cipher
  • Keyword Columnar Transposition Cipher
  • Random Block Transposition Cipher
  • Steganography
  • Bacon’s Cipher
  • Book Ciphers
  • Playfair cipher

Thursday, August 14, 2025

Reading Code For Fun and Learning

For some time I have been writing up information about some historic, and simple compared to modern, cryptonymic algorithms. They are collected in book form (a PDF actually – new release coming soon) that I have made available on my website. One algorithm that I have struggled with has been the Playfair Cipher. I don’t know why but for some reason I’ve had trouble with the algorithm. Mostly, I have struggled with how to code it up. Recently, I decided that I should work on that.

First step was to use something called Notebook LM. More on that in a future post. It’s pretty amazing. In any case, that tool helped me find a coded implementation of the Playfair Cipher. Great! Maybe I can learn from that. It turns out that I can.

The code was in Python and I am not very experienced with Python. Still with well over a dozen languages under my belt, figuring out the code was not hard. After reading the code I feel like I have a better handle on things.

I also learned more than I expected about how Python does things. So double the win. I do believe that reading code is a great way to better understand a programming language. It’s especially valuable if it helps you learn the idiom of the language.

So I now had a console application that worked and that I could play with. Now to me, a console application is so late 20th century that my next step was to convert to C# so I could use Windows Forms. Since I was already using “artificial intelligence” (that’s in quotes because I don’t completely buy that these tools are actually intelligent.) I asked Copilot to convert the Python code into C#. It did so quickly and easily. It wasn’t the way I am used to doing things though. Maybe that is why I was struggling with my own code? It’s a possibility.

The old joke is/was that a good FORTRAN programmer can write a good FORTRAN program in any programming language. Apparently, Copilot can write a good Python program in C#. Yes, the code looked a lot more like the Python code than I had expected. More than I really wanted as well. But along the way I learned that C# could do some things in some ways that I didn’t realize. There have been a lot of changes and updates in the language and I have clearly not kept up with all of them. Well, more learning is a good thing I guess.

Once I had the converted code I built a nice Windows application and have had some fun with it.

I am toying with messing with the C# code to make it look more like what I am comfortable with but that may not be the best use of my time. I might be better off experimenting with the new (to me) features of the language. Either way, learning is a good thing.

Sunday, December 01, 2024

December Adventure–Write some Code Everyday

Eugene Wallingford let me in on A December Adventure  From the website “The December Adventure is low key. The goal is to write a little bit of code every day in December.”

It’s sort of like an Advent of Code but not as intense or competitive. I love the idea of the Advent of Code but it’s more work than I want to put into something. On the other hand, I like to idea of spending a bit of time on a new project every day.

Of course now I have to come up with and good project idea. I have been working on my Hexapawn game and it is tempting to just work on that a bit more. It still needs work.

It may be time to try something new for the month though. Maybe something Christmas related. Any ideas?

Monday, November 25, 2024

Artificial Intelligence Machine Learning and Hexapawn

A presenter at the recent New England CSTA New England Conference mentioned the game Hexapawn.  Hexapawn is hardly new. It was first introduced in 1962. I first ran into it in the early 1970s and found it to be an interesting challenge. One I was to intimidated to try at the the time Be that as it may, the paper introducing Hexapawn used it as something that was open to what we call today machine learning. That is to say, the more one plays it the better the computer gets at playing. The term my professor uses was heuristic programming.. Machine learning is a more accurate term for programs that learn though.

When I think about it, we were learning about artificial intelligence 50 years ago. Progress has been slow. It seems like “true AI” has been ten years away for all of that time. I am skeptical that we are there yet though clearly we are getting closer.

Returning to Hexapawn. There are several ways one can build code to play against a person. One way, the way involving machine learning is for the program to save every move and evaluate if it leads two a win or a loss. Each game leads to moves that are clearly not going to win and others that are more likely to win. This information influences each new game.

An other way is to hard code in moves based on a set of rules. I confess to playing with this strategy a bit. For example, a rule might be as simple as “if there is a move that places a piece in the wining row – take it.” Or perhaps, “if a move prevents the human from moving – take it.”

Rule based AI had a period of popularity especially in the 1980s. OPS5 was a rules based programming language that was used to create an “expert system” to configure computers. Configuring computers back in the mini computer era was a complex process. I worked for one company that believed that configuring computers was to difficult a task for computers. Configuring computers was an important part of my job there. When I left there and went to work for Digital Equipment Corporation I found that they had solved that question.

Which method is better for a game like Hexapawn? Programming rules based seems a little easier. It probably works for a limited game like Hexapawn but I doubt it scales. A machine learning program probably takes more initial work. In the long run it probably results in a more reliable winning game.

Hexapawn is a small enough project that it probably makes a project for helping students write actual artificial intelligence code. Are you using it?

FWIW I blogged about Hexapawn several years ago at Hexapawn–An Interesting Programming Project

Wednesday, March 27, 2024

Pangrams Anyone?

Regular readers of this blog know that I have been doing the New York Times Spelling bee (Computer Science Teacher: Spelling Bee Solver Project). Actually, I do it with my wife who gets most of the words. Anyway, one of the special types of words in the puzzle is called a pangram. Now officially, a pangram is a sentence that includes all of the letters in the alphabet. Anyone who has taken a typing class is probably familiar with this famous pangram.

The quick brown fox jumps over the lazy dog

In the Spelling bee, a pangram is a single word that includes all of the letters in the puzzle for that day. This all suggested a couple of possible programming assignments.

The most obvious (to me) is a program that determines if a sentence is a pangram. The program would have to ignore things like spaces, punctuation, and other special characters.  A step up would be to determine if a sentence is a perfect pangram. A perfect pangram uses each letter only once. Also called a Heterogram

Another idea, which I actually coded myself, is to determine if a word is a pangram of a certain number of letters.That is to say, find words  that have a specific number of unique letters. I haven’t tried to find perfect word pangrams but I might do that next.

I had a program search a large data set of words looking for pangrams. Mostly I looked for seven letter ones as that is what the NY Times Spelling bee uses.There are a lot of them!

One could also determine if all the letters are in alphabetical order. There is probably a name for that as well. Anyone know?

Sunday, October 29, 2023

Spelling Bee Solver Project

My wife loves word puzzles. She is amazing at them. Me? Not so much. On the other hand I love programs and programming projects that involved string manipulation. So when my wife started playing a new (to her) word puzzle – the New York Times Spelling Bee – my thoughts went to solving it programmatically.

If you are not familiar with the game, it involves seven letters for the player to make words from. Anny of the letters may be used but only letters from the list can be used. Oh, and there is one letter, shown in the center of the letters, that must be used in every word. Words much be four letters long or longer BTW.

NY Times Spelling Bee image

I thought this would be a fun project to code up so I took a pass at it. I think it would be a fun project for use with students as well. It involves a number of interesting and important concepts.

For one thing, you’ll want to open and read through a text file. There are many word lists available on the interne BTW. So that part is easy. You want want to check through a list for any words that are not school appropriate (that suggests other interesting projects now that I think about it).

Looping is obvious of course. As is parsing strings to find if a given letter is or is not included in a word. One method I wrote for my solution was to build a string of letters that were not included in the list of allowed letters. I searched any possible word to make sure that no unallowed letters were part of it.

Have you tried this or a similar project? Would you use this one? If you do, let me know.

Edit: Should of known it had been done before. Useful information at Nifty Assignments.

Thursday, May 25, 2023

Coding With AIs Prompts Are Important

Last night, when I could not sleep, I got up and wrote some code. I added some features and data checking to my Wordle solver helper program. When I finished I felt good about my work and myself. I think that made it easier to get to sleep and I slept well.

It got me thinking this morning. When I was in university and still learning how to code I would occasionally get frustrated and feel less confident. So I would write some simple program to help me feel like I could actually code. I must have written code to display the multiplication table from 1 times 1 to 12 times 12 at least once a semester. It worked for me.

Now that is a trivial program but it involves nested loops (for me anyway) and I am not sure I would assign it to students today. It’s really a meaningless program in today’s world when everyone has a calculator app on the phone they don’t leave the house without.

I did wonder how an AI would write the code. So I opened the chat option in Bing and asked it “Write some C# code to display multiplication tables in a list box” It gave me some code that displayed this:






Not what I wanted at all. The problem is ambiguity! So I tried again with “Write some C# code to display the multiplication table from 1 times one to 12 times 12” and got this:

Not what I wanted either. So I specified at grid format “Write some C# code to display the multiplication table from 1 times one to 12 times 12 in a grid format”

This reply required a dataGridView object and the program did not work. Looks like I need to set up the dataGridView object in ways the AI did not explain. Now there is a problem worth thinking about. I asked Bing what settings I needed for the dataGridView and it gave me several. Program still did not work. At this point I gave up on the dataGridView option. It sort of feels like overkill anyway.

So I tried another prompt “Write some C# code to display the multiplication table from 1 times one to 12 times 12 in a grid format in a list box”

Finally I got what I wanted even though I am not thrilled with the formatting.

I’ve got a number of takeaways from this. Yes, students could use  these AI tools to get code for typical school assignments. On the  other hand, I think it would be fairly easy to tell when they do. The use of features that are not typically covered in class lectures or demos would be one clue.

It’s not always easy to provide the right prompts to the AI. Sometimes it takes some iteration. I think though, that teacher have to reduce ambiguity in assignment descriptions in many cases. Arguably some amount of ambiguity is helpful to allow for creativity. It can be a fine line,

As noted, I didn’t like to formatting so I did modify the code to get closer to what I wanted. I think programmers are going to be needed in a lot of cases to finish off what AIs generate. Both providing the right prompt and finishing off will be important skills for some time to come. Finishing off is going to require some serious skills in many cases BTW. Programming is not dead yet.

Saturday, March 18, 2023

Finding Words With All The Letters Programming project

Does anyone else lay in bed in the morning thinking about coding projects or is it just me? I’ve been playing around with a Wordle solver helper for a while now. It helps me find words based on what I know after each guess. One of the things I like to do is see how many possibilities there are based on different hints. Yesterday I had most of the letters but not in the right place. So this morning I was wondering about words that had the same letters but in different orders. Seemed like something I needed to write some code about.  

A key method is to compare all the letters in one string with the letters in a second string. At least the way I was thinking of handling it. It struck me that that is a great assignment for students. I don’t have any students handy so I asked ChatGPT to write that function. This is the prompt I gave it:

Write a C# function that accepts two strings and returns true if all of the letters in the first string are included, in any order, in the second string. Return false if any of the letters in the first string are not included in the second string.

That is a lot like what I would assign a student. ChatGPT gave me some very nice code. It wasn’t exactly like what I was writing in my head. It used foreach and ToCharArray which is probably the best and easiest way to do this. I was coding before either of those became common so my mind goes to for and while loops and the string SubString method. This was a good reminder for me.

I left the rest of the program, which wasn’t a lot of code, to myself.

Once written I had some fun with it. For example, the letters in Alfred also makeups the word flared. The letters in face are also used in café. Some groups of letters do not make up any words of course, This seems like it could be a fun project to give students. It was fun enough for me.

Monday, December 19, 2022

Thoughts on Optimization of Code

Donald E. Knuth famously said "Premature optimization is the root of all evil." The important word there is “premature.” Optimization is not a bad thing. It isn’t always required though.  The joke is that a programmer will spend hours coding a solution to a problem that can be solved in minutes manually. Is that a bad thing? It really depends on the circumstances. If one is getting paid by the hour one could easily argue that it is wrong. On the other hand if time is not really the issue and writing the code is fun – why not?

There have been times in my career when optimization has been very important. I helped spec a computer for high speed/bandwidth data collection. It was critical that the computer be able to take the data and place it in memory without losing data. We actually analyzed the speed of various machine language instructions for optimization purposes. That’s pretty exceptional of course.

I also remember writing a program of my own that took what seemed like a long time to process some data. I thought about trying to optimize it but as often as the program was to run it would not have been a good use of my time. Before I ran it again I got a new computer which made a bigger difference in execution time than I would probably have been able to get though “fixing” the code.

Old habits from the days of slower computers stick with me though and I tend to think a lot about code execution. Recently I had ChatGPT write some code for me (Coding with ChatGPT–Armstrong Numbers) I looked at the code very closely since I was trying to come to some conclusions about how good the code was. I noticed that the C# version it gave me was highly dependent on modulus and division which are somewhat time consuming compared to addition and multiplication. The program I write didn’t use any modulus or division but a lot of multiplication and addition. Both used the same number of raising to a power of 3 so it doesn’t play an important role in performance differences.

Having some time on my hands, I added some timing code to see if there was a difference. My program turns on to be much faster. Yea me. Of course both execution times are very small fractions of a second. Does it make sense to optimize this code? Probably not in this case. In fact, I would argue that the most understandable code may be a better goal for this project. That is a very subjective goal. Different people might come to honest but different conclusions.

Another goal might be scalability – the ease of adapting the program for other Narcissistic numbers. The ChatGPT probably wins there.

SO much depends on what we want to optimize:

  • Speed of execution
  • Ease of understanding
  • Ease of enhancement/modification
  • Possible other considerations(?)

Getting all three may not always be possible. It’s an interesting question though and one developers do need to ask.

Saturday, December 17, 2022

Coding with ChatGPT–Armstrong Numbers

Trying out ChatGPT seems to be all the rage these days in certain geek circles. I may even be late to the game but I tried a few things over the last couple of days.

I started with one of my favorite little projects. Armstrong numbers are a form of narcissistic  number which is a number that is the sum of its own digits each raised to the power of the number of digits. I first wrote a program to calculated these as an undergraduate when I wrote programs for it in about a half dozen different languages.

I fed in the following prompt using C#, Visual Basic, and Python as the programming language.

Write a [programming language] program to calculate three digit numbers were the sum of the cube of each digit equals the original number.

The results for C# and VB were the same algorithm written in the specific syntax. The Python code was slightly different. You’ll probably not be surprised that the code ChatGPT showed me is very similar, if not identical, to code examples you can find with Google or Bing.

The C#/VB plan depends highly on integer division and the modulus operator to break down the number into its digits.

for (int I = 100; I < 1000; I++)
{
     int sum = 0;
     int temp = I;

    while (temp > 0)
     {
         int digit = temp % 10;
         sum += digit * digit * digit;
         temp /= 10;
     }

    if (sum == I)
     {
         Console.WriteLine(I);
     }
}

The Python sample changes the integer into a string and used that to address the individual digits.


for num in range(100, 1000):
   # Convert the number to a string so we can access each digit
   num_str = str(num)
   # Initialize a sum to store the sum of the cubes of the digits
   sum_of_cubes = 0
   # Iterate through each digit in the number
   for digit in num_str:
     # Convert the digit back to an integer and add the cube of it to the sum
     sum_of_cubes += int(digit) ** 3
   # If the sum of the cubes is equal to the original number, print it
   if sum_of_cubes == num:
     print(num)

Note that the Python example nicely includes comments. A dead giveaway that a student didn’t write it. All samples come with simple explanations of how the code works. The explanations tend not to be very deep so oral questioning of a student would probably still show if the student understood the code or not.

It looks like, for some simple, student exercises can be solved by ChatGPT. It is not much different from doing any other online search for the most part. How worried should teachers be about ChatGPT especially? I’m not sure. Cheating goes on all the time and there is a lot of sample code already out there for many common assignments. It’s going to be a bigger problem for educators who have very large numbers of students who can’t be familiar with the code their students write. Or who can’t ask them questions to make sure they understand what they turn in.

I think I would ask ChatGPT to solve some of my assignments before I assign them just so I know what sort of answers I might see.

Side note: Neither of the ways ChatGPT suggested is the way I solve this program. There are more than one ways to skin this cat.

Friday, December 02, 2022

Adventures in Taking Code From the Internet

Facebook memories remined me that ten years ago I was thinking about writing a program that would ring bells (nautical time) on the hour and half hour. I didn't write it back then. Probably because I was busy with my day job. It got me thinking about writing one now just for the fun of it.

Now I have written a fancy clock program before. It looks something like this.

That was written in Visual Basic and I really wanted to use C#. Besides that, that program is a bit busy for something as simple as I wanted to write. The Timer and DateTime classes in the .NET Framework make writing a simple clock application very easy. I thought I would take a look on the internet to see what code samples I could find. There are plenty of them. I found several interesting looking samples that also drew analog clock faces.

The first one I found (C# Analog Clock Program (thecrazyprogrammer.com)) looked simple enough so I created a project and copied the code into it. It was broken. Looking back at the comments on the original post I found a number of comments saying the codebase broken. None of them had answers.

That seems to be pretty common. No doubt that things worked fine for the original coder but something was lost in the posting. I suspect that most people who come across this sort of thing are beginners which would explain the questions. Having a bit more experience I quickly fixed the errors I had and got the program to work. It didn’t look quite like I wanted but again, having enough knowledge to understand the code without a lot of comments, I made some adjustments and got it looking the way I waned.  I suspect that many beginners would either life with it or try a whole lot of things until they stumbled on the right combination. Or maybe broke the program beyond fixing.

That highlights one of the big issues with beginners taking code from the internet. Without some real knowledge even minor issues will keep success away from the student.

I found a second project that was put on the internet some years after the first one I found. Interestingly enough, it appeared to be a refactoring and modest improvement over the first one I found. The code was nearly identical. No credit was given to a previous coder. In fact it was so close that I copied a snippet and pasted into the earlier project. With a tiny edit (a name change) it worked perfictly. This is what I wound up with.

The Code Project web site has a variety of analog clock code samples. I took at look at one - Analog clock control in C# – CodeProject that was pretty good. and worked more or less right off the bat. Except that is was written in a much older version of Visual Studio than I was using. (2003 compared to 2022). An upgrade was required with Visual Studio handled pretty well. That is not always the case if coders used depreciated or removed features or changed names. Yet another issue with taking code from the internet.

Well, now I have a couple of code samples to play with. Most of all I am more convinced that actually getting code from the internet to work can be more complicated than many would think it is.

Now to think about ringing bells. Which reminds me of one last story,

Back when I was in college during the mini-computer era we had a lab full of ASR-33s. They had actual bells that were hit with a little hammer. One student wrote a program that ran in the background of the computer and "grabbed" control of each terminal as it became available. Then it would start ringing all the bells at once. It so happens that when it ran the only one in the lab was the computer department secretary.

The department chair held a meeting with all the TAs and it never happened again.

Thursday, July 28, 2022

Jacdac and Micro:Bit 2.0–First Look

Learning about Jacdac devices was my incentive to buy a Micro:Bit 2.0 The Micro:Bit 2.0 has a number of upgrades and new features from the original. These include a microphone and a speaker among others. That is probably justification enough to get an upgrade but being curious about the Jacdac devices, which requires the newer model, was the deciding factor. I am really enjoying spending time with external devices and the Jacdac devices are really easy to use.

I purchased the Micro:Bit from AdaFruit (micro:bit v2 Go Bundle - Batteries and USB Cable Included) Actually I bought two  because, well, why not? I bought the Kittenbot Jacdac Kit for micro:bit V2 from KittenBot My hope is that more manufacturers and suppliers will be offering Jacdac over time.

The kit comes with:

  • Jacdac Adapter – connects with Micro:Bit
  • Slider
  • Rotary Button
  • RGB Ring
  • 2 Keycap buttons
  • Magnetic Sensor
  • Light Sensor
  • Hub – for connecting even more devices
  • 5 cables of different lengths

Each part is labeled and has a QR code that will take you to documentation for that device. I took full advantage of that. One thing I learned the hard way but would have learned if I read the documentation is that the adapter has a switch that determines if the Micro:Bit powers the Jacdac devices or if the Jacdac (and some external power supply TBD) powers the Micro:Bit. Things worked much better with the switch in the right direction.

Once I got everything out and read some documentation I had to try something out. I started with the RGB Ring and the Rotary Button.  I started with individual example programs and then created my own. I had the rotor determine which LEDs were lit. Going backwards (negative numbers) had some issues of course. I might leave solving that to students if I were doing this in class.

I recommend starting at MakeCode Integration before you get to far on your own. It will step you though adding the Jacdac extensions to MakeCode, connecting to your Micro:Bit, and  other helpful information.

BTW, from MakeCode you can program using blocks (very easy) as well as either JavaScript or Python. You can move back and forth between languages as well. A lot of potential for learners there.

Next up I will be trying to think of some larger projects as well as experimenting with other sensors and gadgets.  I may even cut some boxes with my laser engraver for some projects. Making boxes with 3D printers is also an obvious thing to do.

Sunday, July 17, 2022

My Day Four at #CSTA2022

It’s a short day today but with plenty to learn. Last night was a great party at the Museum of Science and Technology. I left early (age?) but I know that a lot of people stayed late and partied hardy. There may be some tired faces in sessions this morning. It was a great community building event so well worth it.

First session for me was “You CAN Teach Cyber Security with CYBER.ORG’s Cyber Learning Standards. CYBER.ORG is probably the premier Cybersecurity learning/teaching resources. CYBER.ORG is funded by the US Department of Homeland Security. We heard about a lot of their programs. It seems like they have something for almost everyone. I would start there for Cybersecurity resources for teaching.CYBER.ORG funded a large group of educators to write a set of Computer Science Learning Standards.

I had several good options for the last time slot but Nifty Assignments is a must see for me. The version at SIGCSE is always standing room only but apparently it is not as well known at CSTA yet. Baker Franke does a great job of putting this session together. For reference, CSTA Nifty Assignments are archived at CSTA Nifty Assignments SIGCSE Nifty Assignments are archived at Nifty Assignments. I was paying to much attention to take much in the way of notes but the archive should be updated soon. One of them can be played at Mind Reader - App Lab - Code.org The archive is updated and I can’t wait to try some of these when I get home.

That’s a wrap for me. I skipped the closing keynote to get to the airport early. I feel a little guilty but I’m also tired and my brain is kind of full. Some more general thoughts tomorrow.

Tuesday, July 05, 2022

Teaching Computer Science–Moving atoms not pixels

On my first visit to the Lifelong Kindergarten Group and the MIT Media Lab, I notices a message on the windows. “Some people would rather move atoms than pixels.” That has stuck with my for years now. And it is quite true. Robots, game controllers, Internet of Things, and more are ways that computer science interacts with physical objects and not just pixels on a screen. These are ways that teachers can bring more students to more interesting (to the student) to get involved with computer science. But where to start?

Recently I posted curriculum resources that are especially good for teaching traditional computing courses. Well, cyber security is a bit new but anyway. Read that post at Welcome New Computer Science Teachers Today I want to provide some resources to bringing physical computing into the classroom.

Starting with a couple of devices that operate as “brains” for deeper involvement.

Raspberry Pi and the Micro:Bit are two of the most popular. Arduino and the Lego ev3 have been around for longer and are in wide use as well. One could get lost exploring all that LEGO Education has to offer. The Arduino Online Shop has a lot of resources as well.

Personally, I am a fan of both the Raspberry Pi and the Micro:Bit. Both the Micro:bit Educational Foundation and the Raspberry Pi Foundation have a lot of resources. Those are great places to start your exploration.

Ok, let’s talk hardware. While the sites for the Pi, Micro:Bit, Arduino, and Lego EV3 have a lot of links to resources there are more places to go depending on your interests.

Two of my favorites are AdaFruit Industries and Kitronik Ltd. They have devices that work with a lot of "brains." They have devices for all sorts of robotics or Internet of Things projects. I can spend hours looking through both getting idees for projects.

Also for the Internet of Things, I have bought a bunch of devices from Phidgets Education. I have been using these sensors and controls with Raspberry Pi in Python but Scratch, MakeCode, and Java are among other language choices. Speaking of MakeCode, that is an awesome platform for programming Micro:Bits.

I recently discovered Jacdac from Microsoft Research. Right now these devices only work with Micro:Bit but Raspberry Pi and a USB connection for laptops/desktops are projected for the future.

I could, and probably should do a post just about robots and robotics. But here are a few places to get started.

I promise a more comprehensive post of robotics soon.

Monday, May 16, 2022

BINGO Inspired Projects

My son’s school, he’s principal of an elementary school, had a Bingo themed fundraiser yesterday. I can’t help but think about how things are done with any event like this. My first thought was about the Bingo cards themselves.

Typical Bingo cards consists of a five by five grid. The letters B I N G O label the columns and each column has a random number. The center square of the grid is a “free” square and doesn’t have a number. Obviously, generating Bingo grids is a logical project. The numbers in each column must be without a specific range and duplicates are not permitted.

The next obvious project is one to “call” the numbers. The numbers must be identified by number and column where the column is identified by the letter above the column. Drawing duplicate numbers is not permitted so keeping track of numbers drown is important. Keeping track of numbers drawn is also important for verifying Bingos. A program should have a way to do that . This becomes a user interface problem as well as a data storage problem. That may be the most interesting part of the project. At least it is for me.

Now if you really wanted to get complicated, one could design a system where Bingo cards are numbered and their contents stored. One might then be able to use that data with the data of numbers drawn to verify if a Bingo was on the card using only the number of the card. I see this as a group project where individual students would write parts of the program and have them work together. A lot of planning would have to go into this of course.

The Bingo at my son’s school used a traditional ball cag. That seems more fun somehow than drawing the numbers on a computer. That doesn’t mean that software would be a bad way to keep track of numbers drawn and used to verify a Bingo. Another project idea perhaps?

On the other hand, the whole idea opens a discussion of “just because something and be computerized does that mean is should be?” The human factor is an important one. I’d love to have student discuss the pros and cons of computerized Bingo and old fashioned ball cages and physical tracking of drawn balls. Which is more authentic? What does authentic even mean?  That discussion might be just as useful as discussion of what data structures should be used to track Bingo numbers.