Jump to content

Solve hanging lantern problem: Difference between revisions

Solve hanging lantern problem in FreeBASIC
(→‎Version 2: Made a bit more general and added more examples.)
(Solve hanging lantern problem in FreeBASIC)
Line 85:
HOW MANY LANTERNS IN COLUMN 4 ? 4
12600</pre>
 
=={{header|FreeBASIC}}==
{{trans|Python}}
<lang freebasic>Function getLantern(arr() As Uinteger) As Ulong
Dim As Ulong res = 0
For i As Ulong = 1 To Ubound(arr)
If arr(i) <> 0 Then
arr(i) -= 1
res += getLantern(arr())
arr(i) += 1
End If
Next i
If res = 0 Then res = 1
Return res
End Function
 
Dim As Uinteger n = 5
Dim As Uinteger a(n)
'Dim As Integer a(6) = {1,2,3,4,5,6}
For i As Ulong = 1 To Ubound(a)
a(i) = i
Print "[ ";
For j As Ulong = 1 To i
Print a(j); " ";
Next j
Print "] = "; getLantern(a())
Next i
'
Color 3 : Print !"\n--- terminado, pulsa RETURN---"
Sleep</lang>
{{out}}
<pre>[ 1 ] = 1
[ 1 2 ] = 3
[ 1 2 3 ] = 60
[ 1 2 3 4 ] = 12600
[ 1 2 3 4 5 ] = 37837800</pre>
 
=={{header|Julia}}==
2,136

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.