Cheryl's birthday: Difference between revisions

Added FreeBASIC
(Added Algol 68)
(Added FreeBASIC)
Line 1,574:
July 16
</pre>
 
=={{header|FreeBASIC}}==
{{trans|ALGOL 68}}
<syntaxhighlight lang="vbnet">Dim As Integer i, j, contarDias, dia, mes
Dim fechas(1 To 4, 1 To 6) As Integer => {{0, 15, 16, 0, 0, 19}, {0, 0, 0, 17, 18, 0}, {14, 0, 16, 0, 0, 0}, {14, 15, 0, 17, 0, 0}}
Dim nombreMes(1 To 4) As String => {"May", "June", "July", "August"}
 
Print "Cheryl tells Albert the month and Bernard the day"
Print "Albert doesn't know the date and knows Bernard doesn't either"
 
' elimiate the months with unique days
For i = 1 To 6
contarDias = 0
dia = 0
mes = 0
For j = 1 To 4
If fechas(j, i) <> 0 Then
contarDias += 1
dia = fechas(j, i)
mes = j
End If
Next j
If contarDias = 1 Then
Print " Eliminating "; nombreMes(mes); ", "; Str(dia); "th is unique"
For j = 1 To 6
fechas(mes, j) = 0
Next j
End If
Next i
 
Print "Bernard now knows the date"
 
' eliminate the days that aren't unique
For i = 1 To 6
contarDias = 0
dia = 0
mes = 0
For j = 1 To 4
If fechas(j, i) <> 0 Then
contarDias += 1
dia = fechas(j, i)
mes = j
End If
Next j
If contarDias > 1 Then
Print " Eliminating "; Str(dia); "th, it is non-unique"
For j = 1 To 4
fechas(j, i) = 0
Next j
End If
Next i
 
Print "Albert now knows the date"
 
' eliminate months with non-unique days
For i = 1 To 4
contarDias = 0
dia = 0
mes = 0
For j = 1 To 6
If fechas(i, j) <> 0 Then
contarDias += 1
dia = fechas(i, j)
mes = i
End If
Next j
If contarDias > 1 Then
Print " Eliminating "; nombreMes(i); ", it has multiple days"
For j = 1 To 6
fechas(i, j) = 0
Next j
End If
Next i
 
Print "Cheryl's birthday: ";
For i = 1 To 4
For j = 1 To 6
If fechas(i, j) <> 0 Then
Print " "; nombreMes(i); " "; Str(fechas(i, j)); "th"
End If
Next j
Next i
 
Sleep</syntaxhighlight>
{{out}}
<pre>Same as ALGOL 68 entry.</pre>
 
=={{header|Go}}==
<syntaxhighlight lang="go">package main
2,122

edits