Résultat du concours CodinGame ASCII

CodinGame

Pour rigoler j’ai essayé de faire l’épreuve du CodinGame sur l’art ASCII.

Voici le code que j’ai fait en une vingtaine de minutes:

Imports System.IO
Module Module1
Sub Main(ByVal args() As String)
Dim s As New Stopwatch
s.Start()
If args.Length > 0 Then
If File.Exists(args(0)) Then
Dim lines() As String = File.ReadAllLines(args(0))
If lines.Count >= 4 Then
Dim largeur As Integer = CInt(lines(0))
'Dim hauteur As Integer = CInt(lines(1))
Dim mot As String = Trim(lines(2))
Dim linesParse As New List(Of String)
For i As Integer = 3 To lines.Count - 1
linesParse.Add(lines(i))
Next
Call AsciiLetter.SetLetters(largeur, linesParse)
Console.WriteLine(AsciiLetter.GetText(mot))
End If
End If
End If
s.Stop()
Console.WriteLine(s.ElapsedMilliseconds)
Console.ReadLine()
End Sub
Public Class AsciiLetter
Public Shared Letters(26) As List(Of String)
Public Shared Sub SetLetters(ByVal l As Integer, ByVal lines As List(Of String))
For i As Integer = 0 To lines.Count - 1
Dim line As String = lines(i)
Dim pos As Integer = 0
For j As Integer = 0 To 26
If i = 0 Then
Letters(j) = New List(Of String)
End If
Letters(j).Add(Mid(line, 1 + (j * l), l))
Next
Next
End Sub
Public Shared Function GetText(ByVal s As String) As String
Dim h As Integer = Letters(26).Count
Dim l As New List(Of List(Of String))
s = s.ToUpper
For i As Integer = 0 To s.Length - 1
Dim code As Integer = Asc(s(i)) - 65
If code >= 0 AndAlso code <= 25 Then
l.Add(Letters(code))
Else
l.Add(Letters(26))
End If
Next
Dim ret As String = vbNullString
For i As Integer = 0 To h - 1
For j As Integer = 0 To l.Count - 1
ret &= l(j)(i)
Next
If i < h - 1 Then ret &= vbCrLf
Next
Return ret
End Function
End Class
End Module

La solution dotnet est téléchargeable ici CodinGame ASCII.

Leave a Reply

Your email address will not be published. Required fields are marked *