Cheryl's birthday: Difference between revisions

Added uBasic/4tH version
(→‎{{header|Vlang}}: Rename "Vlang" in "V (Vlang)")
(Added uBasic/4tH version)
Line 3,162:
 
<pre>Cheryl's birthday is July 16</pre>
=={{header|uBasic/4tH}}==
{{trans|C}}
<syntaxhighlight lang="ubasic/4th">Dim @d(30)
Dim @m(13)
 
Push 5,15,1, 5,16,1, 5,19,1, 6,17,1 ,6,18,1, 7,14,1, 7,16,1, 8,14,1, 8,15,1, 8,17,1
For x = 29 To 0 Step -1 : @d(x) = Pop() : Next
 
Push Dup("ERR"), Dup("Jan"), Dup("Feb"), Dup("Mar"), Dup("Apr"), Dup("May")
Push Dup("Jun"), Dup("Jul"), Dup("Aug"), Dup("Sep"), Dup("Oct"), Dup("Nov"), Dup("Dec")
For x = 12 To 0 Step -1 : @m(x) = Pop() : Next
 
Proc _printRemaining ' the month cannot have a unique day
Proc _firstPass
 
Proc _printRemaining ' the day must now be unique
Proc _secondPass
 
Proc _printRemaining ' the month must now be unique
Proc _thirdPass
 
Proc _printAnswer
End
 
_printRemaining
Local (2)
b@ = 0
For a@ = 0 To 29 Step 3
If @d(a@+2) Then b@ = b@ + 1
Next
 
Print b@; " remaining."
Return
 
_printAnswer
Local (1)
 
For a@ = 0 To 29 Step 3
If @d(a@+2) Then Print Show (@m(@d(a@))); ", "; @d(a@+1)
Next
Return
 
_firstPass ' the month cannot have a unique day
Local (3)
For a@ = 0 To 29 Step 3
c@ = 0
For b@ = 0 To 29 Step 3
If @d(b@+1) = @d(a@+1) Then c@ = c@ + 1
Next
If c@ = 1 Then
For b@ = 0 To 29 Step 3
If @d(b@+2) = 0 Then
Continue
EndIf
If @d(b@) = @d(a@) Then
@d(b@+2) = 0
EndIf
Next
EndIf
Next
Return
 
_secondPass ' the day must now be unique
Local (3)
For a@ = 0 To 29 Step 3
If @d(a@+2) = 0 Then Continue
c@ = 0
For b@ = 0 To 29 Step 3
If @d(b@+2) = 0 Then Continue
If @d(b@+1) = @d(a@+1) Then c@ = c@ + 1
Next
If c@ > 1 Then
For b@ = 0 To 29 Step 3
If @d(b@+2) = 0 Then
Continue
EndIf
If @d(b@+1) = @d(a@+1) Then
@d(b@+2) = 0
EndIf
Next
EndIf
Next
Return
 
_thirdPass ' the month must now be unique
Local (3)
For a@ = 0 To 29 Step 3
If @d(a@+2) = 0 Then Continue
c@ = 0
For b@ = 0 To 29 Step 3
If @d(b@+2) = 0 Then Continue
If @d(b@) = @d(a@) Then c@ = c@ + 1
Next
If c@ > 1 Then
For b@ = 0 To 29 Step 3
If @d(b@+2) = 0 Then
Continue
EndIf
If @d(b@) = @d(a@) Then
@d(b@+2) = 0
EndIf
Next
EndIf
Next
Return</syntaxhighlight>
{{Out}}
<pre>10 remaining.
5 remaining.
3 remaining.
Jul, 16
 
0 OK, 0:657</pre>
=={{header|VBA}}==
<syntaxhighlight lang="vb">Private Sub exclude_unique_days(w As Collection)
Line 3,224 ⟶ 3,349:
End Sub</syntaxhighlight>{{out}}
<pre>July 16</pre>
 
=={{header|Visual Basic .NET}}==
{{trans|C#}}
374

edits