oitofelix / pil-4th Goto Github PK
View Code? Open in Web Editor NEWSolutions to Exercises of Book Programming in Lua (Fourth Edition)
License: MIT License
Solutions to Exercises of Book Programming in Lua (Fourth Edition)
License: MIT License
Line 11 in 417e460
This (and also in ex 4.4) should have the -1
in the call to utf8.offset
on the outside and not on the inside. Try this output and you will see:
-- Japanese example.
jp = '私は日本語が分かります。'
print(jp)
print(insert(jp, 3, "少し"))
-- Chinese example.
zh = "我學了四年了,可是很長的時間沒有練習。"
print(zh)
print(insert(zh, 4, "中文"))
-- Japanese example.
jp = '私は少し日本語が分かります。'
print(jp)
print(remove(jp, 3, 2))
-- Chinese example.
zh = "我學了中文四年了,可是很長的時間沒有練習。"
print(zh)
print(remove(zh, 4, 2))
-- Sure, if this is what you mean.
function polyval (p, x)
local sum, pow = 0, 1
for _, a in ipairs (p) do
sum = sum + a * pow
pow = pow * x
end
return sum
end
That would still be 2(n+1) multiplications. They mean this:
a0 + x*(a1 + x*(a2 + x*(a3 ...+ x*an)))))
which would look something like this:
function poly_eval2(p, x)
ret = p[#p]
for k = #p-1,1,-1 do
ret = ret * x
ret = ret + p[k]
end
return ret
end
I'm a noob, just learning lua now but I noticed in your solution for 1.8 if I use the -l method to load the script it will only show lua and not the name of the script, it still works if I directly load it so is the solution correct because technically using -l counts as an extra argument?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.