Anda di halaman 1dari 6

Tarea 2

Edgar Barrantes - B10833 - Grupo 3


August 23, 2015

Contents
1 Hotel infinito.

2 Programas en C.
2.1 Comprobaci
on del ejemplo 6.1.9 (pag 388). . . . . . . . . . . . . . . . . . . . . . . .
2.2 Comprobaci
on del ejemplo 6.1.14 (pag 390). . . . . . . . . . . . . . . . . . . . . . . .
2.3 Comprobaci
on del ejemplo 6.2.6 (pag 427). . . . . . . . . . . . . . . . . . . . . . . .

2
2
2
3

3 Ejercicios.
3.1 Parte 6.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.1.1 Problema 12. How many bit strings are there of length six or less, not counting
the empty string? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.1.2 Problema 16. How many strings are there of four lowercase letters that have
the letter x in them? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.1.3 Problema 24. How many positive integers between 1000 and 9999 inclusive
a) are divisible by 9? b)are even? c) have distinct digits? d) are not divisible
by 3? e) are divisible by 5 or 7? f) are not divisible by either 5 or 7? g) are
divisible by 5 but not by 7? h) are divisible by 5 and 7? . . . . . . . . . . . .
3.1.4 Problema 44. How many ways are there to seat four of a group of ten people
around a circular table where two seatings are considered the same when
everyone has the same immediate left and immediate right neighbor? . . . . .
3.1.5 Problema 50. How many bit strings of length 10 contain either five consecutive
0s or five consecutive 1s? . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.1.6 Problema 56. The name of a variable in the C programming language is a
string that can contain uppercase letters, lowercase let ters, digits, or underscores. Further, the first character in the string must be a letter, either
uppercase or lowercase, or an underscore. If the name of a variable is determined by its first eight characters, how many different variables can be
named in C? (Note that the name of a variable may contain fewer than eight
characters.) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.2 Parte 6.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.2.1 Problema 12. How many ordered pairs of integers (a, b) are needed to guarantee that there are two ordered pairs (a1 , b1 ) and (a2 , b2) such that a1
mod 5 = a2 mod 5 and b1 mod 5 = b2 mod 5? . . . . . . . . . . . . . . . . .
3.2.2 Problema 16. How many numbers must be selected from the set 1, 3, 5, 7, 9,
11, 13, 15 to guarantee that at least one pair of these numbers add up to 16?

3
3

3
4

5
5

5
6

6
6

Hotel infinito.

Luego de utilizar potencias de primos para alojar infinitos buses con infinita cantidad de personas,
quedan habitaciones libres, puesto que siempre habra habitaciones de la forma p 2n libres, con
p un n
umero primo, y n un natural. Y no solo eso, ademas, como los primos son infinitos, queda
infinita cantidad de habitaciones libres.

Programas en C.

Se adjuntara la soluci
on en C para resolver el problema y al final se adjuntara una captura de
pantalla con las soluciones en una terminal.

2.1

Comprobaci
on del ejemplo 6.1.9 (pag 388).

#include <s t d i o . h>


int main ( void ) {
int k , i 1 , i 2 , i 3 , i 4 , i 5 ;
k = 0;
for ( i 1 =1; i 1 <= 8 ; i 1 ++){
for ( i 2 =1; i 2 <= 6 ; i 2 ++){
for ( i 3 =1; i 3 <= 1 3 ; i 3 ++){
f o r ( i 4 =1; i 4 <= 7 ; i 4 ++){
f o r ( i 5 =1; i 5 <= 5 ; i 5 ++){
k++;
}
}
}
}
}
p r i n t f ( %d\n , k ) ;
return 0 ;
}

2.2

Comprobaci
on del ejemplo 6.1.14 (pag 390).

#include <s t d i o . h>


int main ( void ) {
int k , i 1 , i 2 , i 3
k = 0;
for ( i 1 =1; i 1 <=
k++;
}
for ( i 2 =1; i 2 <=
k++;
}
for ( i 3 =1; i 3 <=
k++;
}
for ( i 4 =1; i 4 <=
k++;

, i4 , i 5 ;
8 ; i 1 ++){

6 ; i 2 ++){

1 3 ; i 3 ++){

7 ; i 4 ++){

}
for ( i 5 =1; i 5 <= 5 ; i 5 ++){
k++;
}
p r i n t f ( %d\n , k ) ;
return 0 ;
}

2.3

Comprobaci
on del ejemplo 6.2.6 (pag 427).

#include <s t d i o . h>


int main ( void ) {
int k , i 1 , i 2 , i 3 , i 4 , i 5 ;
k = 0;
for ( i 1 =1; i 1 <= 8 ; i 1 ++){
for ( i 2 =1; i 2 <= 6 ; i 2 ++){
for ( i 3 =1; i 3 <= 1 3 ; i 3 ++){
f o r ( i 4 =1; i 4 <= 7 ; i 4 ++){
f o r ( i 5 =1; i 5 <= 5 ; i 5 ++){
k++;
}
}
}
}
}
p r i n t f ( %d\n , k ) ;
return 0 ;
}
Finalmente, podemos apreciar el c
odigo luego de correr en la maquina:

Ejercicios.

3.1
3.1.1

Parte 6.1
Problema 12. How many bit strings are there of length six or less, not counting
the empty string?

Aplicando la regla del producto y la suma se observa que, al tener solo dos posibilidades para
cada bit, se puede solucionar el problema con sumas de potencias de dos de la siguiente manera:
26 + 25 + 24 + 23 + 22 + 2 = 126
R:126

3.1.2

Problema 16. How many strings are there of four lowercase letters that have
the letter x in them?

Este problema se resuelve usando la regla de la resta primero vemos que todos los strings posibles
son 264 por la regla del producto. Ahora, la cantidad de strings posibles que no contengan la x son
254 puesto que se usan 25 caracteres. Teniendo as por regla de la resta la respuesta.
R: 264 254
3.1.3

Problema 24. How many positive integers between 1000 and 9999 inclusive a)
are divisible by 9? b)are even? c) have distinct digits? d) are not divisible
by 3? e) are divisible by 5 or 7? f ) are not divisible by either 5 or 7? g) are
divisible by 5 but not by 7? h) are divisible by 5 and 7?

Observemos que usaremos los numeros en [1000, 9999], teniendo as: 9000 n
umeros. Para resolver
los problemas, por lo general se usar
a la regla de la resta para encontrar los n
umeros en [1,9999] y
restarle los encontrados en [1,1000]. Para encontrar la cantidad de los divisibles por n n
umero, se
toma la parte entera de la divisi
on entre el n
umero mayor y n, en el caso de n
umeros cuyo resultado
es entero, implica que 1000 es divisible por n, por lo cual luego se suma 1, para considerar el n
umero
1000. Luego de esto, se procede a ense
nar por partes los resultados de las operaciones para cada
caso.
a) Por regla de la resta.
En [1,1000]: 111
En [1,9999]: 1111.
R: 1111 111 = 1000
b) Por regla de la resta.
En [1,1000]: 500
En [1,9999]: 4999.
R: 4999 500 + 1 = 4500
c) Por regla del producto:
R: 10 9 8 7 = 5040
d) Por regla de la resta dos veces.
Total: 9000
En [1,1000]: 333
En [1,9999]: 3333.
9000 (3333 333) = 6000
e) Analizando por casos. Los divisibles por 35 son los divisibles por 5 y 7 a la vez.
Divisibles entre 5: (1999 199) = 1800
Divisibles entre 7: (1428 142) = 1286
Divisibles entre 35: (285 28) = 257
R: 1800 + 1286 257 = 2829
Divisibles entre 5 y 7: 2829.
f) Se usa el total de los n
umeros menos los divisibles entre 5 o 7.
R: 9000 2829 = 6171
g) Se toman los divisibles por 5 menos los que son divisibles por 5 y 7 a la vez.
R: 1800 257 = 1543
h) Este resultado ya se haba contado.
R: 257

3.1.4

Problema 44. How many ways are there to seat four of a group of ten people around a circular table where two seatings are considered the same when
everyone has the same immediate left and immediate right neighbor?

Este es una caso de regla del producto y de la division juntas. Analizando, primero se pueden
sentar 10 personas, luego 9, luego 8, y por u
ltimo 7: 10 9 8 7, sin embargo, como hay cuatro
posibilidades que son iguales, se divide entre cuatro, teniendo as:
10 9 8 7/4 = 1260.
R: 1260.
3.1.5

Problema 50. How many bit strings of length 10 contain either five consecutive
0s or five consecutive 1s?

Analicemos el caso de 5 1s seguidos. Asignemos posiciones i a cada posible inicio de 5 1s consecutivos. Sabemos que i estar
a en 0, 1, 2, 3, 4, 5, por tanto tenemos 6 casos a analizar. Para i = 0,
tememos que puede haber 25 posibilidades. Observe:
11111*****.
Para i > 0, tenemos que poner un 1 en el bit anterior al bit i, para no contar casos pasados, por
ende, tenemos 24 posibilidades para cada uno, observe:
100000****, *100000***, **100000**, etc.
Por tanto, en total son 25 + 24 + 24 + 24 + 24 + 24 = 112 posibilidades para cinco 1s seguidos.
Analogamente se llega a la conclusion de que son 112 posibilidades para cinco 0s seguidos.
Sin embargo, hay que considerar que se estan contando 0000011111 y 1111100000 dos veces, por
tanto es necesario restar dos, teniendo as la solucion final 112 + 112 2 = 222
R: 222.
3.1.6

Problema 56. The name of a variable in the C programming language is a string


that can contain uppercase letters, lowercase let ters, digits, or underscores.
Further, the first character in the string must be a letter, either uppercase or
lowercase, or an underscore. If the name of a variable is determined by its first
eight characters, how many different variables can be named in C? (Note that
the name of a variable may contain fewer than eight characters.)

Para analizar esto, veamos la cantidad de posibles caracteres:


lowercase, 26; uppercase, 26; digits, 10; undercore, 1.
Para un total de 63. Analicemos por casos, para la primera letra, solo se pueden secoger
lowercase, uppercase y underscores, por tanto, 53 posibilidades. Para todos los demas, se pueden
ademas escoger dgitos, por tanto 63 posibilidades, como el maximo de caracteres que toma en
cuenta son ocho, veamos los ocho casos y usemos la regla de la suma.
De longitud 8: 53 637
De longitud 7: 53 636
De longitud 6: 53 635
De longitud 5: 53 634
De longitud 4: 53 633
De longitud 3: 53 632
De longitud 2: 53 63
De longitud 1: 53
Teniendo as la respuesta por regla de la suma:
R: 53 (637 + 636 + 635 + 634 + 633 + 632 + 63 + 1)

Nota: Se puede hacer esto m


as escalable usando una sumatoria, con n total de caracteres:
53

n
X

(63nk )

(1)

k=1

3.2
3.2.1

Parte 6.2
Problema 12. How many ordered pairs of integers (a, b) are needed to guarantee
that there are two ordered pairs (a1 , b1 ) and (a2 , b2) such that a1 mod 5 =
a2 mod 5 and b1 mod 5 = b2 mod 5?

Para analizarlo, tomemos dos casos, al elegir el primer n


umero, y al elegir el segundo. Cuando
se elege el primero, sabemos que s
olo hay 5 resultados diferentes hasta llegar a repetir uno, por
palomar. Luego como si fuesemos llenando casillas, se va escogiendo el segundo de la misma forma,
con 5 resultados. Por tanto, hay 25 antes de llegar a repetir un mismo resultado de modulo 5 en el
mejor de los casos. Y sabemos por palomar que se necesitan pues 26 distintos pares ordenados
para garantizar lo dicho.
R: 26.
3.2.2

Problema 16. How many numbers must be selected from the set 1, 3, 5, 7, 9,
11, 13, 15 to guarantee that at least one pair of these numbers add up to 16?

Tenemos ocho diferentes n


umeros, de los cuales observamos que hay 4 pares que suman ocho, por
tanto, podemos elegir 4 n
umeros que no tengan, entre s otro n
umero cuya adicion resulte en 16,
sin embargo, al elegir el 5to, es seguro que habra un par que sume 16.
R: 5.

Anda mungkin juga menyukai