Simple programming training puzzle (repeat)

AI Thread Summary
The discussion revolves around a vintage programming puzzle from a 1969 IBM Fortran class, featuring a simple programming language based on an imaginary machine with limited instructions and memory. The machine operates with two peripherals: a paper tape reader and a punch, using only asterisks and hyphens as its character set. It has 20 memory locations, but only the first 10 are addressable for branching. The language includes 13 instructions, allowing for basic operations like reading characters, punching output, and branching to specific memory locations.Participants are tasked with writing programs to manipulate the paper tape based on specific conditions, such as duplicating the tape or stopping I/O after reading three consecutive asterisks. The simplicity of the instruction set encourages trial and error as a method for developing solutions. The discussion emphasizes the nostalgic aspect of the puzzle and its relevance to early programming practices, with participants encouraged to share their solutions while avoiding spoilers.
rcgldr
Homework Helper
Messages
8,917
Reaction score
672
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
I never saw this question before, but I've seen WAY too much fortran code written in the same style as the solutions :devil:
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
10
Views
3K
Replies
7
Views
4K
Replies
15
Views
4K
Replies
15
Views
3K
Replies
3
Views
2K
Replies
37
Views
4K
Replies
23
Views
2K
Replies
13
Views
7K
Back
Top