Simple programming training puzzle (repeat)

In summary, this is a repost of an old thread discussing a programming puzzle from 1969 involving an imaginary machine with limited instructions and memory locations. The task is to write programs to duplicate paper tape and read it until a specific sequence is reached. The simplicity of the language allows for trial and error when writing the programs.
  • #1
rcgldr
Homework Helper
8,855
632
This is a repost of an old thread, maybe some new members can give it a shot. This puzzle was included at the start of a casual IBM Fortran programming class for high school students back in 1969. (Yes, I'm that old). I don't know the origin of this puzzle.

An extremely simple and old (1960's) programming language based on an imaginary machine. The machine has two peripherals, at paper tape reader, and a paper tape punch. The character set only includes two characters, Asterisk and Hypen. The CPU has 20 memory locations, which hold instructions, but only the first 10 locations, 0 through 9 are addressable via the branch instruction.

There are only 13 instructions, and 4 basic types of instruction:

T - Read a character from the tape reader. If the character read is a hyphen, execute next instruction. If the character read is an asterisk, skip the next instruction, and execute the instruction following the next instruction. If no character is read because the paper tape is past the end, then the machine will stop.

H - Punch a hypen, then execute next instruction.

A - Punch an asterisk, then execute next instruction.

0 - branch to location 0 and continue execution there.
1 - branch to location 1 and continue execution there.
2 - branch to location 2 and continue execution there.
...
9 - branch to location 9 and continue execution there.

Instruction execution can continue past memory location 9, but these memory locations can't be the target of a branch instruction.

Programming tasks:

1. Write a program to duplicate the paper tape in the reader using the paper tape punch.

2. Write a program to read the paper tape until 3 asterisks in a row are read, then start duplicating the paper tape as in program 1.

3. Write a program to read the paper tape until 3 asterisks in a row are read, then start duplicating the paper tape, but stop all I/O once 3 asterisks in a row are punched during the copy process.

Note that since there are only 13 instructions, trial and error will be good enough to write any of these programs.

To avoid spoilers, please white out your repsonse using
and
tags , or merely indicate that you've solved how to create programs 1, 2, and/or 3.

Example of a failed attempt at a copy program:

Code:
0 1 2 3 4 5 6 7 8 9 X X X X X X X X X X
T H A 0

This program will punch a hyphen and asterisk for every hyphen read, and punch an asterisk for every asterisk read. It's a broken copy program that you'll fix with program assignment 1.
 
Technology news on Phys.org
  • #2
I never saw this question before, but I've seen WAY too much fortran code written in the same style as the solutions :devil:
 

1. What is a simple programming training puzzle?

A simple programming training puzzle is a coding exercise or problem that is designed to help individuals practice and improve their programming skills. These puzzles often involve repeating a specific action or solving a problem using a particular programming language.

2. Why are simple programming training puzzles important?

Simple programming training puzzles are important because they allow individuals to practice and improve their coding skills in a low-pressure environment. They also help individuals develop problem-solving skills and gain a better understanding of different programming concepts.

3. How can I find simple programming training puzzles?

There are many online resources and platforms that offer simple programming training puzzles for different programming languages. Some popular options include HackerRank, CodeWars, and Codecademy. You can also find puzzles in coding books or by attending coding workshops and events.

4. What are the benefits of solving simple programming training puzzles?

Solving simple programming training puzzles has numerous benefits, including improving your coding skills, boosting your problem-solving abilities, and helping you think creatively. They can also be a fun and challenging way to learn new programming concepts and techniques.

5. How can I improve my performance in simple programming training puzzles?

To improve your performance in simple programming training puzzles, it is essential to practice regularly and challenge yourself with new and more difficult puzzles. You can also seek feedback from others, read coding blogs and tutorials, and join coding communities to learn from others and get support.

Similar threads

  • Programming and Computer Science
Replies
10
Views
3K
  • Programming and Computer Science
Replies
7
Views
4K
  • Programming and Computer Science
Replies
6
Views
3K
  • Programming and Computer Science
Replies
15
Views
3K
  • Programming and Computer Science
Replies
29
Views
3K
  • Programming and Computer Science
2
Replies
37
Views
3K
  • Programming and Computer Science
Replies
15
Views
3K
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
23
Views
2K
  • Sticky
  • Programming and Computer Science
Replies
13
Views
4K
Back
Top