6 kyu

Seven-segment display: how many switches?

Description:

Introduction

A seven-segment display is an electronic device used to show decimal numerals. It consists of seven segments arranged in a rectangular shape. There are two vertical segments on each side and one horizontal segment at the top, middle, and bottom. By activating specific combinations of segments, the display can represent all decimal digits.

You are working on a maker project involving a seven-segment display component. Your goal is to verify its functionality and understand how it operates.

Working with segments

Digits are displayed with segments as follows:

 _     _  _       _   _  _   _   _
| | |  _| _| |_| |_  |_   | |_| |_|
|_| | |_  _|   |  _| |_|  | |_|  _|

A conventional way to indicate individual segments is to label them with letters a, b, c, d, e, f, g, arranged as follows:

 aaaa 
f    b
f    b
 gggg
e    c
e    c
 dddd

Each segment can switch its state from off to on or vice versa. Depending on the digit currently displayed, certain segments are on and others off. When a new digit is displayed, some segments may switch their state, while others may remain unchanged. Here are a few examples:

  • when the display transitions from digit 6 to 8, segment b turns on: the number of segment switches is 1.

  • when the display transitions from digit 2 to 3, segment e turns off and segment c turns on: the number of segment switches is 2.

  • when the display transitions from blank state to digit 8, all segments turn on: the number of segment switches is 7.

One or more seven-segment displays can be arranged together to compose a display board. The amount of displays corresponds to the board size. For instance, a display board of size 4 can display any 4-digit number from 0 to 9999. When a number requires less digits then the display board size, it is displayed aligned to the right, and the components for the unused digits are blank.

Your task

Your task is to write a solution that takes two parameters:

  • size: the size of the display board, i.e. the number of digits (size can be 1 or more)

  • sequence: a sequence of integers, each composed of a number of digits between 1 and size

and returns the total number of segment switches performed by the display board throughout the sequence.

Note initially the display board is blank, meaning all segments for all digit positions are off, and upon completion the last number of the sequence remains displayed.

Fundamentals

More By Author:

Check out these other kata created by alexc19

Stats:

CreatedJul 6, 2023
PublishedJul 13, 2023
Warriors Trained117
Total Skips6
Total Code Submissions187
Total Times Completed43
Python Completions43
Total Stars3
% of votes with a positive feedback rating97% of 19
Total "Very Satisfied" Votes18
Total "Somewhat Satisfied" Votes1
Total "Not Satisfied" Votes0
Total Rank Assessments5
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • alexc19 Avatar
  • dfhwze Avatar
Ad