Submit an Entry

To enter the challenge, you need to signup or login.

This Challenge's Best Entries [View All]

(View the Overall | Perl | PHP | Python | Ruby leaderboard.)

Rank User Size Language Score [?]
1st flagitious 107 Ruby 10,000 (v6)
2nd tybalt89 111 Perl 9,639 (v7)
3rd primo 111 Ruby 9,639 (v26)
4th bearstearns 114 Perl 9,385 (v9)
5th leonid 115 Ruby 9,304 (v7)
6th shinh 118 Ruby 9,067 (v11)
7th kinaba 119 Ruby 8,991 (v5)
8th yowa 119 Ruby 8,991 (v15)
9th Mr.Rm 119 Perl 8,991 (v3)
10th ySas 121 Perl 8,842 (v21)

See who is active in this challenge →

Seven-Segment Displays

(Challenge added 952 days ago.)

Represent numbers on a seven-segment display.

Discuss This Challenge →

The Problem

You'll all be familiar with seven-segment displays, they are everywhere. They are capable of displaying all 10 numeric digits using just 7 different segments. This challenge is all about emulating them - Given a number, you should display that number as it would appear on a set of seven-segment displays. For example, the number 0123456789 should be displayed like this :

 ###           ###    ###           ###    ###    ###    ###    ### 
#   #      #      #      #  #   #  #      #          #  #   #  #   #
#   #      #      #      #  #   #  #      #          #  #   #  #   #
#   #      #      #      #  #   #  #      #          #  #   #  #   #
               ###    ###    ###    ###    ###           ###    ### 
#   #      #  #          #      #      #  #   #      #  #   #      #
#   #      #  #          #      #      #  #   #      #  #   #      #
#   #      #  #          #      #      #  #   #      #  #   #      #
 ###           ###    ###           ###    ###           ###    ### 

As you can see, the number 8 uses all seven segments :

 ### 
#   #
#   #
#   #
 ### 
#   #
#   #
#   #
 ### 

You can display all the other numbers by turning off one or more of the segments :

 ### 
#    
#    
#    
 ### 
#   #
#   #
#   #
 ### 
 ### 
#    
#    
#    
 ### 
    #
    #
    #
 ### 
     
    #
    #
    #
     
    #
    #
    #
     

As you can see, using this method, you can represent the digits 0-9.

More Information

  • Your program will be given a number in the range 0 <= x < 1,000,000,000 on stdin. The number may contain leading zeroes to a maximum length of 10 digits. You should print the representation of the number on stdout.
  • You should use the hash sign (#) to indicate a segment that is illuminated (on) and spaces for padding and indicating segments which are off.
  • If a segment doesn't extend to the end of the line (which is the case in the horizontal segments), you should pad the end of the line with a space.
  • Each seven-segment display in your output should be separated from the previous one by 2 spaces :

     ###    ### 
    #   #  #   #
    #   #  #   #
    #   #  #   #
     ###    ### 
    #   #  #   #
    #   #  #   #
    #   #  #   #
     ###    ### 
  • Your program will be run 6 times. It will need to pass all 6 runs to be deemed successful.

More Examples

As mentioned above, your program will be run 6 times. The first run will always be the same, and will enable you to make sure you are forming all the digits correctly. To see the input and the expected output, click below.

For the other five runs, your program will be given a random number to represent. Click below for an example random input and the expected output. Reload the page to get another random number.

Thanks

Thanks to Mark Byers for suggesting this challenge.