Quick actions

cmd+k|ctrl+k

Navigation

Languages

加减各50个20以内带括号

Snippet info

Language

Ruby

Visibility

public

Author

jiemnij

Created

2017-03-11T01:43:03Z

Updated

2017-03-11T01:44:01Z

#coding: GBK
X_RANGE = (1..20)			#第一个数的范围
Y_RANGE = (1..20)			#第二个数的范围
MULT_FORMULA_CNTS = 50		#乘法算式总的个数
DIV_FORMULA_CNTS = 50		#除法算式总的个数


LINE_CNTS = 4				#每行算式个数

res = {}
while res.size < MULT_FORMULA_CNTS do
	x =  rand(X_RANGE)
	y =  rand(Y_RANGE)
	#if x != 1 && y != 1
	if ((x+y) <= 20) && ((x+y) >= 10)
		key = sprintf("%d+%d", x, y)
		type = rand(1..3)
		str = sprintf("(   ) + %-2d = %-2d", y, x+y) if type == 1
		str = sprintf("%-2d + (   ) = %-2d", x, x+y) if type == 2
		str = sprintf("%-2d + %-2d =(    )", x, y) if type == 3
		
		res[key] = str
	end
end


while res.size < (MULT_FORMULA_CNTS + DIV_FORMULA_CNTS) do
	x =  rand(X_RANGE)
	y =  rand(Y_RANGE)
#	if x != 1 && y != 1
	if ((x+y) <= 20) && (x+y) >= 10
		type = rand(1..3)

		key = sprintf("%d_%d", x, y)
		str = sprintf("(   ) - %-2d = %2d", x,   y)if type == 1
		str = sprintf("%-2d - (   ) = %2d", x+y, y)if type == 2
		str = sprintf("%-2d - %-2d =(    )", x+y, x)if type == 3
		
		res[key] = str
	end
end



out_tab = res.to_a
line = 0
out = {}
out_size = 0
while out_size < (MULT_FORMULA_CNTS+DIV_FORMULA_CNTS) do
	i = rand(0..(MULT_FORMULA_CNTS+DIV_FORMULA_CNTS-1))
	out[i] = i
	if out_size != out.size
		printf(out_tab[i][1])
		line = line + 1
	
		if line == LINE_CNTS
			puts ""
			#puts ""
			line = 0
		else
			printf("     ")
		end

		out_size = out.size
	end
end


INFO