Linear
During the Battle Phase: Declare a whole number from 1 to 6; choose 1 Effect Monster your opponent controls. Multiply the Effect Monster's Level x the declared number, then add the number of cards your opponent controls, and check if the result equals the number of cards in your GY.
● If yes: Send cards from the top of your Deck to the GY, up to the declared number, and if you do, shuffle cards your opponent controls into the Deck, up to the number sent to the GY.
● If no: You lose LP equal to the declared number x 500.
You can only activate 1 "Linear Equation Cannon" per turn.
local s, id, o = GetID()
function s.initial_effect(c)
	--Activate
	local e1 = Effect.CreateEffect(c)
	e1:SetCategory(CATEGORY_DECKDES + CATEGORY_TODECK)
	e1:SetType(EFFECT_TYPE_ACTIVATE)
	e1:SetCode(EVENT_FREE_CHAIN)
	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
	e1:SetCondition(s.condition)
	e1:SetTarget(s.target)
	e1:SetOperation(s.activate)
	c:RegisterEffect(e1)
end
function s.condition(e, tp, eg, ep, ev, re, r, rp)
	local ph = Duel.GetCurrentPhase()
	return ph >= PHASE_BATTLE_START and ph <= PHASE_BATTLE
end
function s.filter(c)
	return c:IsFaceup() and c:IsType(TYPE_EFFECT) and c:IsLevelAbove(1)
end
function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		return Duel.IsExistingMatchingCard(s.filter, tp, 0, LOCATION_MZONE, 1, nil) and Duel.GetFieldGroupCount(tp, 0, LOCATION_ONFIELD) > 0
	end
	local t = {}
	local i = 1
	for i = 1, 6 do
		t[i] = i
	end
	e:SetLabel(Duel.AnnounceNumber(tp, table.unpack(t)))
	local g = Duel.GetMatchingGroup(Card.IsAbleToDeck, tp, 0, LOCATION_ONFIELD, nil)
	Duel.SetOperationInfo(0, CATEGORY_DECKDES, nil, 0, tp, 0)
	Duel.SetOperationInfo(0, CATEGORY_TODECK, g, 0, 0, 0)
end
function s.activate(e, tp, eg, ep, ev, re, r, rp)
	--Set up the equation
	local dnum = e:GetLabel()
	local fnum = Duel.GetFieldGroupCount(tp, 0, LOCATION_ONFIELD)
	local gnum = Duel.GetFieldGroupCount(tp, LOCATION_GRAVE, 0)
	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
	local dg = Duel.SelectMatchingCard(tp, s.filter, tp, 0, LOCATION_MZONE, 1, 1, nil)
	if #dg == 0 then
		return
	end
	local mon = dg:GetFirst()
	local lnum = mon:GetLevel()
	--The equation
	if ((lnum * dnum) + fnum) == gnum then
		--Select number of cards to send from Deck to GY
		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
		local dcount = Duel.GetFieldGroupCount(tp, LOCATION_DECK, 0)
		local t = {}
		local i = 1
		if dcount <= dnum then
			for i = 1, dcount do
				t[i] = i
			end
		else
			for i = 1, dnum do
				t[i] = i
			end
		end
		local snum = Duel.AnnounceNumber(tp, table.unpack(t))
		if Duel.DiscardDeck(tp, snum, REASON_EFFECT) ~= 0 then
			local og = Duel.GetOperatedGroup()
			local tdnum = og:FilterCount(Card.IsLocation, nil, LOCATION_GRAVE)
			local tdg = Duel.GetMatchingGroup(Card.IsAbleToDeck, tp, 0, LOCATION_ONFIELD, nil)
			if tdnum <= 0 or #tdg <= 0 then
				return
			end
			--Shuffle opponent's cards into Deck
			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
			local rg = tdg:Select(tp, 1, tdnum, nil)
			Duel.HintSelection(rg)
			Duel.SendtoDeck(rg, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
		end
	else
		--Lose LP
		Duel.SetLP(tp, Duel.GetLP(tp) - dnum * 500)
	end
end


Linear
During the Battle Phase: Declare a whole number from 1 to 6; choose 1 Effect Monster your opponent controls. Multiply the Effect Monster's Level x the declared number, then add the number of cards your opponent controls, and check if the result equals the number of cards in your GY.
● If yes: Send cards from the top of your Deck to the GY, up to the declared number, and if you do, shuffle cards your opponent controls into the Deck, up to the number sent to the GY.
● If no: You lose LP equal to the declared number x 500.
You can only activate 1 "Linear Equation Cannon" per turn.
-- Linear
local s, id, o = GetID()
function s.initial_effect(c)
	--Activate
	local e1 = Effect.CreateEffect(c)
	e1:SetCategory(CATEGORY_DECKDES + CATEGORY_TODECK)
	e1:SetType(EFFECT_TYPE_ACTIVATE)
	e1:SetCode(EVENT_FREE_CHAIN)
	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
	e1:SetCondition(s.condition)
	e1:SetTarget(s.target)
	e1:SetOperation(s.activate)
	c:RegisterEffect(e1)
end
function s.condition(e, tp, eg, ep, ev, re, r, rp)
	local ph = Duel.GetCurrentPhase()
	return ph >= PHASE_BATTLE_START and ph <= PHASE_BATTLE
end
function s.filter(c)
	return c:IsFaceup() and c:IsType(TYPE_EFFECT) and c:IsLevelAbove(1)
end
function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		return Duel.IsExistingMatchingCard(s.filter, tp, 0, LOCATION_MZONE, 1, nil) and Duel.GetFieldGroupCount(tp, 0, LOCATION_ONFIELD) > 0
	end
	local t = {}
	local i = 1
	for i = 1, 6 do
		t[i] = i
	end
	e:SetLabel(Duel.AnnounceNumber(tp, table.unpack(t)))
	local g = Duel.GetMatchingGroup(Card.IsAbleToDeck, tp, 0, LOCATION_ONFIELD, nil)
	Duel.SetOperationInfo(0, CATEGORY_DECKDES, nil, 0, tp, 0)
	Duel.SetOperationInfo(0, CATEGORY_TODECK, g, 0, 0, 0)
end
function s.activate(e, tp, eg, ep, ev, re, r, rp)
	--Set up the equation
	local dnum = e:GetLabel()
	local fnum = Duel.GetFieldGroupCount(tp, 0, LOCATION_ONFIELD)
	local gnum = Duel.GetFieldGroupCount(tp, LOCATION_GRAVE, 0)
	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
	local dg = Duel.SelectMatchingCard(tp, s.filter, tp, 0, LOCATION_MZONE, 1, 1, nil)
	if #dg == 0 then
		return
	end
	local mon = dg:GetFirst()
	local lnum = mon:GetLevel()
	--The equation
	if ((lnum * dnum) + fnum) == gnum then
		--Select number of cards to send from Deck to GY
		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
		local dcount = Duel.GetFieldGroupCount(tp, LOCATION_DECK, 0)
		local t = {}
		local i = 1
		if dcount <= dnum then
			for i = 1, dcount do
				t[i] = i
			end
		else
			for i = 1, dnum do
				t[i] = i
			end
		end
		local snum = Duel.AnnounceNumber(tp, table.unpack(t))
		if Duel.DiscardDeck(tp, snum, REASON_EFFECT) ~= 0 then
			local og = Duel.GetOperatedGroup()
			local tdnum = og:FilterCount(Card.IsLocation, nil, LOCATION_GRAVE)
			local tdg = Duel.GetMatchingGroup(Card.IsAbleToDeck, tp, 0, LOCATION_ONFIELD, nil)
			if tdnum <= 0 or #tdg <= 0 then
				return
			end
			--Shuffle opponent's cards into Deck
			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
			local rg = tdg:Select(tp, 1, tdnum, nil)
			Duel.HintSelection(rg)
			Duel.SendtoDeck(rg, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
		end
	else
		--Lose LP
		Duel.SetLP(tp, Duel.GetLP(tp) - dnum * 500)
	end
end

