# # Written by: # -- # John L. Weatherwax 2007-07-05 # # email: wax@alum.mit.edu # # Please send comments and especially bug reports to the # above email address. # #----- # Jousting in a Tournament: # tournament_number = 1:11 numbers_less_than = tournament_number - 1 numbers_greater_than = 11 - tournament_number number_product = numbers_less_than * numbers_greater_than rbind( tournament_number, numbers_less_than, numbers_greater_than, number_product ) # How much for a Knife, Sword, or Arrow: # arrows = 1:floor( 72/22 ) knives = ( 72 - 22 * arrows ) / 3 rbind( arrows, knives ) # What is the Human Population of South Primm: # N = 420 sum( c( 1/3, 1/4, 1/5, 1/7 ) * N ) # Strange Rabbits: # x = -20:+20 y = ( 13 - 5 * x ) / 7 integer_y = y == as.integer(y) int_x = x[ integer_y ] int_y = y[ integer_y ] num_jumps = abs(int_x) + abs(int_y) R = rbind( int_x, int_y, num_jumps ) rownames(R) = c("X","Y","Num. Jumps") print(R) # Minotaur Fighters: # A = matrix( data=c(4,-4,-4, -2,6,-2, -1,-1,7), nrow=3, ncol=3, byrow=TRUE ) b = matrix( data=c(48,48,48), nrow=3 ) solve(A, b) print("Switching Allegiance:") # Ls = 5:13 Ms = 7:15 print( rbind( Ls, Ms, Ms+1, Ls-1 ) ) print("Able and Gallant Soldiers:") # A = matrix( data=c(1,1,1,1, -1,0,0,1, 1,1,-1,-1, 0,1,0,-1), nrow=4, ncol=4, byrow=TRUE ) b = matrix( data=c(50,0,-2,-4), nrow=4 ) x = solve(A, b) print(A) print(t(b)) print(t(x)) print("How Many Eggs?") # eggs = 5:39 M = rbind( eggs, eggs %% 2 - 1, eggs %% 3, eggs %% 5 - 3 ) rownames(M) = c("eggs", "mod 2 - 1", "mod 3", "mod 5 - 3" ) print(M) print("Daughters of Alexis") # M = matrix( data=c(1,1,9, 1,2,8, 1,3,7, 1,4,6, 1,5,5, 2,2,7, 2,3,6, 2,4,5, 3,3,5, 3,4,4), ncol=3, byrow=TRUE ) print( M ) print( rowSums(M) ) the_products = apply(M,1,prod) # compute the product of each set of ages M2 = cbind( M, the_products, the_products-16, the_products+16 ) colnames(M2) = c("A1", "A2", "A3", "products", "products-16", "products+16" ) print(M2) print("The Price of Candy:"); Bs = 8:10 other = Bs - 3 C_term = Bs^2 + other^2 - 7*Bs - 7*other print(C_term) descrim = 7^2 - 4 * C_term print( descrim ) M = rbind( Bs, other, C_term, descrim ) print(M) print( c( (7 - sqrt(57) ) / 2, (7 + sqrt(57) ) / 2 ) ) print( c( (7 - sqrt(1) ) / 2, (7 + sqrt(1) ) / 2 ) ) print( 8^2 + ( (7 + sqrt(57) ) / 2 )^2 + 5^2 ) print("Drawing Stones:") # Try various values for B+W one at a time: # print("B+W=7") Bs = 3:7 print( rbind( Bs, ( Bs - 2 ) / 5 - (9/10) * ( Bs / 7 ) ) ) print("B+W=8") Bs = 3:8 print( rbind( Bs, ( Bs - 2 ) / 6 - (9/10) * ( Bs / 8 ) ) ) print("B+W=12") Bs = 3:12 print( rbind( Bs, ( Bs - 2 ) / 10 - (9/10) * ( Bs / 12 ) ) ) print("B+W=13") Bs = 3:13 print( rbind( Bs, ( Bs - 2 ) / 11 - (9/10) * ( Bs / 13 ) ) )