Download All Files (as .zip)

I actually wrote this contest and this is the code I used to be marked. I've since fixed up the code and rewrote it in Java. Here is a link to that fixed up code.

You might be surprised to know that 2013 is the ﬁrst year since 1987 with distinct digits. The years 2014, 2015, 2016, 2017, 2018, 2019 each have distinct digits. 2012 does not have distinct digits, since the digit 2 is repeated.

Given a year, what is the next year with distinct digits?

**Input Specification**

The input consists of one integer *Y* (0 ≤ *Y* ≤ 10000), representing the starting year

**Output Specification**

The output will be the single integer *D*, which is the next year after *Y* with distinct digits.

**Sample Input 1**

1987

**Output for Sample Input 1**

2013

**Sample Input 2**

999

**Output for Sample Input 2**

1023

Option Strict On Public Class Form1 Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click Try Dim y As Integer = CInt(txtY.Text) Dim l As String = CStr(txtY.Text) Dim num As Boolean = False Dim a As String, b As String, c As String, g As String, f As String If y <= 10000 And y > 0 Then Do Until num = True y += 1 l = CStr(y) If l.Length = 1 Then num = True End If If l.Length = 2 Then a = l.Substring(0) a = a.Remove(1) b = l.Substring(1) If Not (a = b) Then num = True End If End If If l.Length = 3 Then a = l.Substring(0) a = a.Remove(1) b = l.Substring(1) b = b.Remove(1) c = l.Substring(2) If a = b Or a = c Or b = c Then Else num = True End If End If If l.Length = 4 Then a = l.Substring(0) a = a.Remove(1) b = l.Substring(1) b = b.Remove(1) c = l.Substring(2) c = c.Remove(1) f = l.Substring(3) If a = b Or a = c Or a = f Or b = c Or b = f Or c = f Then Else num = True End If End If If l.Length = 5 Then a = l.Substring(0) a = a.Remove(1) b = l.Substring(1) b = b.Remove(1) c = l.Substring(2) c = c.Remove(1) f = l.Substring(3) f = f.Remove(1) g = l.Substring(4) If a = b Or a = c Or a = f Or a = g Or b = c Or b = f Or b = g Or c = f Or c = g Or f = g Then Else num = True End If End If If num = True Then Dim D As Integer = y txtD.Text = CStr(D) End If Loop Else MsgBox("Please enter a positive integer for the year that is between 0 and 10 000") txtY.Text = "" txtD.Text = "" End If Catch ex As Exception MsgBox("Please enter an integer number for the year.") txtY.Text = "" End Try End Sub End Class 'a = l.Substring(0) 'a = l.Remove(1) 'b = l.Substring(1) 'txtD.Text = a + Space(3) + b 'a = l.Substring(0) 'a = l.Remove(1) 'b = l.Substring(1) 'b = b.Remove(1) 'txtD.Text = a.PadRight(3) + b

DOWNLOAD as .zip

Using their test cases:

All the following outputs are exactly the expected outputs.

Input:

3030

Output:

3041

DOWNLOAD as .in

Input:

9029

Output:

9031

DOWNLOAD as .in

Input:

1812

Output:

1820

DOWNLOAD as .in

Input:

1867

Output:

1869

DOWNLOAD as .in

Input:

1776

Output:

1780

DOWNLOAD as .in

Input:

1000

Output:

1023

DOWNLOAD as .in

Input:

2987

Output:

3012

DOWNLOAD as .in

Input:

9

Output:

10

DOWNLOAD as .in

Input:

10

Output:

12

DOWNLOAD as .in

Input:

65

Output:

67

DOWNLOAD as .in

Input:

279

Output:

280

DOWNLOAD as .in

Input:

10000

Output:

10234

DOWNLOAD as .in

Input:

0

Output:

1

DOWNLOAD as .in

Input:

9876

Output:

10234

DOWNLOAD as .in

Input:

987

Output:

1023

DOWNLOAD as .in

Created: February 26, 2013

Completed in full by: Michael Yaworski