| 
	
		|  Autor | Tema: [RETO] Cuadrado Numerico en forma de "¬"  (Leído 4,981 veces) |  
	| 
			| 
					
						| BlackZeroX 
								Wiki  Desconectado 
								Mensajes: 3.158
								
								 
								I'Love...!¡.
								
								
								
								
								
								     | 
 
.Lo vi por Aquí(Enlace)  y me parecio buena idea publicarlo aquí y ver que otras maneras hay de hacer esto... Generar un cuadrado numerico que se le ingrese un numero por ejemplo  * La funcion final debera devolver un Array tipo Long.  * Despues se leera dicho array y se creara un String que devuelva el contenido (En el Formato Propuesto). Se ingresa 10 y se construye el siguiente cuadrado numerico 001 002 003 004 005 006 007 008 009 010
 020 021 022 023 024 025 026 027 028 011
 037 038 039 040 041 042 043 044 029 012
 052 053 054 055 056 057 058 045 030 013
 065 066 067 068 069 070 059 046 031 014
 076 077 078 079 080 071 060 047 032 015
 085 086 087 088 081 072 061 048 033 016
 092 093 094 089 082 073 062 049 034 017
 097 098 095 090 083 074 063 050 035 018
 100 099 096 091 084 075 064 051 036 019
 
 
Se ingrese 20 y da como resultado 001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020
 040 041 042 043 044 045 046 047 048 049 050 051 052 053 054 055 056 057 058 021
 077 078 079 080 081 082 083 084 085 086 087 088 089 090 091 092 093 094 059 022
 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 095 060 023
 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 129 096 061 024
 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 161 130 097 062 025
 205 206 207 208 209 210 211 212 213 214 215 216 217 218 191 162 131 098 063 026
 232 233 234 235 236 237 238 239 240 241 242 243 244 219 192 163 132 099 064 027
 257 258 259 260 261 262 263 264 265 266 267 268 245 220 193 164 133 100 065 028
 280 281 282 283 284 285 286 287 288 289 290 269 246 221 194 165 134 101 066 029
 301 302 303 304 305 306 307 308 309 310 291 270 247 222 195 166 135 102 067 030
 320 321 322 323 324 325 326 327 328 311 292 271 248 223 196 167 136 103 068 031
 337 338 339 340 341 342 343 344 329 312 293 272 249 224 197 168 137 104 069 032
 352 353 354 355 356 357 358 345 330 313 294 273 250 225 198 169 138 105 070 033
 365 366 367 368 369 370 359 346 331 314 295 274 251 226 199 170 139 106 071 034
 376 377 378 379 380 371 360 347 332 315 296 275 252 227 200 171 140 107 072 035
 385 386 387 388 381 372 361 348 333 316 297 276 253 228 201 172 141 108 073 036
 392 393 394 389 382 373 362 349 334 317 298 277 254 229 202 173 142 109 074 037
 397 398 395 390 383 374 363 350 335 318 299 278 255 230 203 174 143 110 075 038
 400 399 396 391 384 375 364 351 336 319 300 279 256 231 204 175 144 111 076 039
 
 
Edito: Estos Son mis Dos Codigos (Con una Sola Matriz Unidimensional xD ):  * Sin Calculo de Espacio...Mod_Main Generate Rentangle.bas  * Implementando Espacio Implementado...Mod_Main Generate Rentangle V2.bas Dulces Lunas!¡.
 
 |  
						| 
								|  |  
								| « Última modificación: 19 Septiembre 2010, 06:11 am por BlackZeroX » |  En línea | 
 
 The Dark Shadow is my passion. |  |  |  | 
			| 
					
						| raul338 
								       
								
								 Desconectado 
								Mensajes: 2.633
								
								 
								La sonrisa es la mejor forma de afrontar las cosas
								
								
								
								
								
								     | 
 
No entiendo la forma de como se hacen los cuadrados, o sea, como seria la serie ._. (aunque sea pon una formula matematica) 
 
 |  
						| 
								|  |  
								|  |  En línea | 
 
 |  |  |  | 
			| 
					
						| Sanlegas 
								
								 Desconectado 
								Mensajes: 131
								
								 
								https://fbcdn-sphotos-e-a.akamaihd.net/hphotos-ak-
								
								
								
								
								
								   | 
 
Función: Public Function SquareNumber(NumberLineToPrint As Long) As Long()Dim MArray()             As Long
 Dim Z                    As Long
 Dim N                    As Long
 Dim C                    As Long
 Dim Aux()                As Long
 
 ReDim MArray(NumberLineToPrint)
 ReDim Aux(NumberLineToPrint - 1, NumberLineToPrint - 1)
 
 For Z = 0 To NumberLineToPrint - 1
 For N = 0 To NumberLineToPrint - Z - 1
 C = C + 1
 Aux(Z, N) = C
 Next N
 For N = Z To 1 Step -1
 MArray(N - 1) = MArray(N - 1) + 1
 Aux(Z, NumberLineToPrint - N) = MArray(N - 1)
 Next N
 MArray(Z) = C
 C = C + NumberLineToPrint - Z - 1
 DoEvents
 Next Z
 SquareNumber = Aux
 End Function
Llamada: Dim V() As LongV = SquareNumber(20)
 
 For Z = 0 To UBound(V)
 For N = 0 To UBound(V)
 Select Case Val(V(Z, N))
 Case Is < 10
 Text1.Text = Text1.Text & "00" & V(Z, N) & " "
 Case Is < 100
 Text1.Text = Text1.Text & "0" & V(Z, N) & " "
 Case Else
 Text1.Text = Text1.Text & V(Z, N) & " "
 End Select
 Next N
 Text1.Text = Text1.Text & vbNewLine
 Next Z
 Salida: 001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 040 041 042 043 044 045 046 047 048 049 050 051 052 053 054 055 056 057 058 021
 077 078 079 080 081 082 083 084 085 086 087 088 089 090 091 092 093 094 059 022
 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 095 060 023
 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 129 096 061 024
 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 161 130 097 062 025
 205 206 207 208 209 210 211 212 213 214 215 216 217 218 191 162 131 098 063 026
 232 233 234 235 236 237 238 239 240 241 242 243 244 219 192 163 132 099 064 027
 257 258 259 260 261 262 263 264 265 266 267 268 245 220 193 164 133 100 065 028
 280 281 282 283 284 285 286 287 288 289 290 269 246 221 194 165 134 101 066 029
 301 302 303 304 305 306 307 308 309 310 291 270 247 222 195 166 135 102 067 030
 320 321 322 323 324 325 326 327 328 311 292 271 248 223 196 167 136 103 068 031
 337 338 339 340 341 342 343 344 329 312 293 272 249 224 197 168 137 104 069 032
 352 353 354 355 356 357 358 345 330 313 294 273 250 225 198 169 138 105 070 033
 365 366 367 368 369 370 359 346 331 314 295 274 251 226 199 170 139 106 071 034
 376 377 378 379 380 371 360 347 332 315 296 275 252 227 200 171 140 107 072 035
 385 386 387 388 381 372 361 348 333 316 297 276 253 228 201 172 141 108 073 036
 392 393 394 389 382 373 362 349 334 317 298 277 254 229 202 173 142 109 074 037
 397 398 395 390 383 374 363 350 335 318 299 278 255 230 203 174 143 110 075 038
 400 399 396 391 384 375 364 351 336 319 300 279 256 231 204 175 144 111 076 039
Si dices que tiene que devolver un array de long entonces no puede almacenar 0`s a la izquierda, por lo tal se tienen que imprimir al mostrar el array devuelto por la funcion     |  
						| 
								|  |  
								|  |  En línea | 
 
 |  |  |  | 
			| 
					
						| BlackZeroX 
								Wiki  Desconectado 
								Mensajes: 3.158
								
								 
								I'Love...!¡.
								
								
								
								
								
								     | 
 
Si dices que tiene que devolver un array de long entonces no puede almacenar 0`s a la izquierda, por lo tal se tienen que imprimir al mostrar el array devuelto por la funcion    Estamente con Format(nVal, "0#"") lo realisas mas facil... No entiendo la forma de como se hacen los cuadrados, o sea, como seria la serie ._. (aunque sea pon una formula matematica)
 ve esto mas facil Cuando se ingresa 2: si se ingresa 3 ETC la numeracion va de esta manera Dulces Lunas!¡. |  
						| 
								|  |  
								| « Última modificación: 18 Septiembre 2010, 02:22 am por BlackZeroX » |  En línea | 
 
 The Dark Shadow is my passion. |  |  |  | 
			| 
					
						| LeandroA | 
 
hay va el mio  Option Explicit
 Private Sub Form_Load()
 Dim Arr() As Long, lNum As Long
 
 lNum = 10
 
 CuadradoArray Arr, lNum
 
 PrintArr Arr, lNum
 End Sub
 
 
 Private Sub CuadradoArray(Arr() As Long, lNum As Long)
 Dim x As Long, y As Long, n As Long
 Dim i As Long, lCount As Long
 
 ReDim Arr(lNum - 1, lNum - 1)
 
 For n = 0 To lNum - 1
 
 y = i
 i = i + 1
 
 For x = 0 To lNum - i
 lCount = lCount + 1
 Arr(x, y) = lCount
 Next
 
 x = x - 1
 
 For y = i To lNum - 1
 lCount = lCount + 1
 Arr(x, y) = lCount
 Next
 
 Next
 End Sub
 
 Private Sub PrintArr(Arr() As Long, lNum As Long)
 Dim x As Long, y As Long, sFormat As String
 
 sFormat = String(Len(CStr(lNum * lNum)), "0")
 
 For y = 0 To lNum - 1
 For x = 0 To lNum - 1
 Debug.Print Format(Arr(x, y), sFormat),
 Next
 Debug.Print
 Next
 End Sub
 
 |  
						| 
								|  |  
								|  |  En línea | 
 
 |  |  |  | 
			| 
					
						| BlackZeroX 
								Wiki  Desconectado 
								Mensajes: 3.158
								
								 
								I'Love...!¡.
								
								
								
								
								
								     | 
 
.No quiero molestar pero... L.A. te falto un punto...
 
 
  * La funcion final debera devolver un Array tipo Long.* Despues se leera dicho array y se creara un String que devuelva el contenido (En el Formato Propuesto).
 
 Dulces Lunas!¡.
 |  
						| 
								|  |  
								|  |  En línea | 
 
 The Dark Shadow is my passion. |  |  |  | 
			| 
					
						| LeandroA | 
 
ok siempre apurado no leo bien las cosas    Option Explicit
 Private Declare Function GetTickCount Lib "kernel32.dll" () As Long
 
 Private Sub Form_Load()
 Dim arr() As Long, lNum As Long
 Dim t As Long
 
 
 t = GetTickCount
 
 lNum = 1000
 
 CuadradoArray arr, lNum
 
 Debug.Print ArrToString(arr, lNum)
 
 MsgBox GetTickCount - t
 End Sub
 
 
 Private Sub CuadradoArray(arr() As Long, lNum As Long)
 Dim x As Long, y As Long, n As Long
 Dim i As Long, lCount As Long
 
 ReDim arr(lNum - 1, lNum - 1)
 
 For n = 0 To lNum - 1
 
 y = i
 i = i + 1
 
 For x = 0 To lNum - i
 lCount = lCount + 1
 arr(x, y) = lCount
 Next
 
 x = x - 1
 
 For y = i To lNum - 1
 lCount = lCount + 1
 arr(x, y) = lCount
 Next
 
 Next
 End Sub
 
 
 Private Function ArrToString(arr() As Long, ByVal lNum As Long) As String
 Dim x As Long, y As Long
 Dim LenFormat As Long
 Dim sVal As String
 Dim i As Long
 
 LenFormat = Len(CStr(lNum * lNum))
 
 ArrToString = String((lNum * lNum) * (LenFormat + 1), "0")
 
 lNum = lNum - 1
 
 For y = 0 To lNum
 For x = 0 To lNum
 sVal = arr(x, y)
 i = i + 1
 If x = lNum Then
 Mid$(ArrToString, (i * LenFormat) - Len(sVal) + i) = sVal & vbCr
 Else
 Mid$(ArrToString, (i * LenFormat) - Len(sVal) + i) = sVal & vbTab
 End If
 Next
 Next
 End Function
 
 |  
						| 
								|  |  
								|  |  En línea | 
 
 |  |  |  | 
			| 
					
						| BlackZeroX 
								Wiki  Desconectado 
								Mensajes: 3.158
								
								 
								I'Love...!¡.
								
								
								
								
								
								     | 
 
. Un Bucle de 20 vueltas con un numero ingresado de 1000, y estos fueron los resultados... (Solo la funcion que genera el Array) BlackZeroX (281)
 Tenient101 (625)
 Leandro A. (375)
 
 
Ahora con Convirtiendolo a String... Nos la mata LeandroA... (Hago demasiadas cosas en el ArrayToString yo xP) Dulces Lunas!¡. |  
						| 
								|  |  
								|  |  En línea | 
 
 The Dark Shadow is my passion. |  |  |  |  |  
 
	
 
   |