This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// en algún sitio... | |
enum CalculaPrecioComo { | |
SobreElCoste, | |
PrecioMedioPonderado, | |
DescuentoEscalado | |
} | |
// en otro sitio... | |
switch( modoPrecio ) { | |
case CalculaPrecioComo.SobreElCoste: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Extraer( | |
int *A, // I/O unidades actuales en almacén | |
int *C, // I/O valor actual en la tarifa | |
int *P, // I/O unidades pendientes a extraer | |
char *m // microprograma a ejecutar | |
) { | |
int r; // registro de memoria | |
#define INTENTA(S) { \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
void Extraer( | |
int *A, // I/O unidades actuales en almacén | |
int *C, // I/O valor actual en la tarifa | |
int *P, // I/O unidades pendientes a extraer | |
char *m // microprograma a ejecutar | |
) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Cálculo ingenuo de una serie geométrica: | |
int Calculo(int a, int r, int n) { | |
int R = 1, S = 0; | |
while(n--) { | |
S += a * R; | |
R *= r; | |
} | |
return S; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Serie geométrica: | |
int Calculo(int a, int r, int n) { | |
return (a * (ipow(r, n) - 1)) / (r - 1); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Cálculo dígito según coordenada en la matriz caracol. | |
-- Crédito de "jalonso" en: | |
-- http://www.solveet.com/exercises/Coordenadas-de-un-numero-en-una-matriz-caracol-/51/solution-326 | |
coordenadas n p | |
| p <= n = (1,p) | |
| p <= 2*n-1 = (p-n+1,n) | |
| p <= 3*n-2 = (n,3*n-1-p) | |
| p <= 4*n-4 = (4*n-2-p,1) | |
| otherwise = (x+1,y+1) | |
where (x,y) = coordenadas (n-2) (p-4*n+4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Tomandos los cuadros del más exterior al interior x = 1, 2, 3, ... su perímetro | |
Func<int, int, int> perimeter = ( x, n ) => 4 * ( n - 2 * x + 1 ); | |
// Dada las coordenadas de la diagonal principal (1, 1), (2, 2), ... devuelve el número que contiene | |
Func<int, int, int> diagonalPos = ( x, n ) => -4 * x * x + ( 4 * n + 8 ) * x - 4 * n - 3; | |
// Dado un número, indica en qué cuadro está | |
Func<int, int, int> inSquare = ( z, n ) => (int) Math.Floor(n * 0.5 - 0.5 * Math.Sqrt(n * n - z + 1.0) + 1.0); | |
// Dígito en la matriz caracol dada una posición: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Indica si un número muuuuy grande es feliz. | |
// En lugar de indicar el número directamente, | |
// se suponen ya contados el número de dígitos | |
// que tiene. | |
bool IsBigHappy( | |
int _1digits, | |
int _2digits, | |
int _3digits, | |
int _4digits, | |
int _5digits, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int mod4(int n) { | |
return n % 4; | |
} | |
int div4(int n) { | |
return n / 4; | |
} | |
int divX(int n, int x) { | |
return n / x; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#region License | |
/*---------------------------------------------------------------------------------*\ | |
Distributed under the terms of an MIT-style license: | |
The MIT License | |
Copyright (c) 2005-2010 Stephen M. McKamey | |
Permission is hereby granted, free of charge, to any person obtaining a copy |