Solve hanging lantern problem: Difference between revisions
Content added Content deleted
(→Version 2: Made a bit more general and added more examples.) |
(Solve hanging lantern problem in FreeBASIC) |
||
Line 85: | Line 85: | ||
HOW MANY LANTERNS IN COLUMN 4 ? 4 |
HOW MANY LANTERNS IN COLUMN 4 ? 4 |
||
12600</pre> |
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}}== |
=={{header|Julia}}== |