follow
touchdevelop challenge
  • Home
  • TD Challenge
    • Scheme of Work
    • Project Ideas
  • Resources
    • Rubrics >
      • Windows 8 App assessment rubric
    • Tutorials
    • Resources >
      • Guide to making great Windows Store apps
      • Badges
      • App Development Assignment
      • Evaluating existing apps - template
      • TouchDevelop Programming on the Go - EBook
      • Videos
    • Posters
    • Example Apps
  • Showcase
    • Staff Showcase
    • Student Showcase >
      • Turtle Art Showcase
      • Pixel Art Showcase
      • App Showcase
      • Hour of Code Showcase
      • UK HoC Showcase
    • Staff Picks
    • Submit
  • Lessons
    • Turing Test
    • Turtle Power
    • Create an eBook
    • Magic 8-Ball
    • 8-Bit Challenge
    • Coding Golf Challenge
    • Tutorials
  • HoC
    • Hour of Code >
      • HoC Showcase
      • Festive 8-bit Showcase
    • Hour of Code 2 >
      • UK HoC Showcase
  • About
    • Who are we
    • What is TouchDevelop
    • News
  • Blog

Coding Golf Challenge

Background

Anyone who has taught Computing / Computer Science will know that the 'coding and programming' strand can sometimes feel like a very dry topic, especially for young children. One way to inject some fun into your coding lessons is to gamify them!


For those new to the concept, gamification is the process of introducing game-like elements into a traditionally non-gaming contexts to make them more fun and engaging. Gamification strategies include elements such as gamifying grading, incentivizing students with rewards and adding competitive elements such as leaderboards.

One strategy that exemplifies the concept of gamification in the teaching of coding is a game called 'Code Golf'.


What is 'Code Golf'?


I came across the idea of Code Golf at a Computing At School (CAS) conference last summer and have been experimenting with it ever since. The idea is simple, participants are given a problem (or working solution) and are challenged to solve it using the fewest lines of code.

The term Code Golf is derived from the similarity of its scoring system to that of conventional golf, where participants aim to achieve the lowest score possible.


Why Code Golf?

The idea behind Code Golf is to encourage efficient use of code. At GCSE / A-Level, students are required to make efficient use of code in order to access higher grades / mark bands. Efficient code also uses less RAM, compiles quicker and uses up less storage space. Students can use a combination of features such as loops (For, While, Repeat) or sub-routines to achieve their optimised code however, readability and usability must not be sacrificed at the expense of code optimisation therefore, white space and comments do not count as lines; we still want to encourage students to break up and comment their code so that it is comprehensible to others, easier to debug and easy for others to re-use.


Types of Code Golf

There are two main ways to play Code Golf. The first way requires students to solve a given problem using the fewest lines of code. The second method, which requires a little more preparation from the teacher, requires the students to optimise a given working solution. In both methods, the challenge is for the students to create a solution using the least amount of code. To add a little extra challenge, the teacher can add a Par value (or target number), with the Par being the optimal number of lines of code. This Par value can be altered for different levels of ability (similar to the 'handicap' system in conventional golf) thus allowing the teacher to differentiate the lesson.


Example: 

The following is an example of a simple 'Par Challenge'. In this example, students are challenged to create a square using the TouchDevelop turtle library using 6 lines of code (Par 6).
Picture
Working, but inefficient, solution for creating a square in TouchDevelop using 10 lines of code.
Picture
More efficient solution for creating a square using 6 lines of code (or Par 6).
Lesson

Learning Objectives:

  • Understand and use sequence in an algorithm
  • Understand and use iteration in an algorithm (FOR and WHILE loops)


Curriculum Mapping:

KS2:
  • Design, write and debug programs that accomplish specific goals; solve problems by breaking them into smaller parts. Select, use and combine a variety of software on a range of digital devices to design and create a range of programs.
  • Use sequence, selection and repetition in programs; work with variables and various forms of input and output
  • Use logical reasoning to explain how some simple algorithms work; detect and correct errors in algorithms and programs


KS3:
  • Use two or more programming languages, at least one of which is textual, to solve a variety of computational problems.


What you will need:

  • Web enabled device (PC, Tablet, Phone) with an up-to-date browser (Internet Explorer, Safari, Chrome)
  • TouchDevelop Web App (www.touchdevelop.com)


Challenge

Instruct students to follow the TouchDevelop step-by-step tutorial, below. 

TouchDevelop Turtle (Step-By-Step Tutorial)

Once the students have got the hang of turtle, explain to them that they are going to compete in a game of 'Coding Golf'. Hand out the challenge (See PowerPoint below) and explain to students that challenge is to solve each of the tasks using the fewest of lines of code possible.


Instructions

To create a new blank turtle script:

1. Launch TouchDevelop and click on 'Create Script'

2. Click on 'blank turtle'.
Picture


Resources



Click on the link below to download the PowerPoint.
coding_golf.pptx
File Size: 587 kb
File Type: pptx
Download File

Scorecard:
scorecard.xlsx
File Size: 11 kb
File Type: xlsx
Download File


Tutorials

  • Turtle Shapes - Step-by-step tutorial for creating geometric shapes in TouchDevelop.
  • Turtle Fractals - Learn how to draw incredible drawings with recursion and the turtle!

Rules

To make the challenge fair and consistent, I recommend that you set some competition rules. Here are the rules I use:

  1. Blank lines don't count as lines of code.
  2. Comments don't count as lines of code. (We want to encourage the students to comment their code).
  3. Changing the turtle speed or pen colour doesn't count as lines of code.
  4. Everything else counts.

Obviously, you can make up your own rules - just as long as they are the same for everybody.


Useful Links
  • Stack Exchange (Code Golf) - Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required. 
  • Book of Programming Challenges - Book of programming challenges, ideal for Code Golf , courtesy of Stuart Lucas (Requires sign up to Computing At School - FREE)
  • Turtle Confusion - 40 shape challenges designed for turtle based on the book by Barry Newell "Turtle Confusion: Logo Puzzles and Riddles."
Powered by Create your own unique website with customizable templates.