Prath
But get confused
fgntfg
Show me your code than, and we will figure out what wrong with the code
Prath
Okay
Snusmumriken
Input: 1 5 Sam 40.08 Riya 30.7 Harry 41 Anne 35.2 Peter 36.6 Output: Harry Explanation: The maximum score of student is 41 which belong to "Harry"
Solution using FFI : ) local ffi = require'ffi' ffi.cdef[[ typedef struct Student { const char * name; float score; } Student;]] local case, count while not case do print("Write testcase count (number):") case = tonumber(io.read("*l")) end while not count do print("Write students count (number):") count = tonumber(io.read("*l")) end local students = ffi.new("Student[?]", count) for i = 0, count - 1 do local studentname, score while not studentname do print("Write " .. i + 1 .. " student (name score):") local line = io.read("*l") studentname, score = line:match("(%w+).-(%-?%d+%.?%d*)") if studentname then print("Student #" .. i .. ": ", studentname, "score: ", score) students[i].name = studentname students[i].score = tonumber(score) end end end local maxstudent = students[0] for i = 1, count - 1 do if students[i].score > maxstudent.score then maxstudent = students[i] end end print("Coolest student is ", ffi.string(maxstudent.name), ", he's score is:", maxstudent.score)
Prath
Thx you very much
Prath
Using lua
Prath
How many changes
Prath
Plz
Snusmumriken
I'm bored to rewrite it in pure Lua.
Prath
What's change plz
Snusmumriken
Лол, такой булшит использовать ффи для такой фигни.
Prath
Could you write it in notebook then share plz
Prath
Plz only last plz
Snusmumriken
Could you write it in notebook then share plz
local case, count while not case do print("Write testcase count (number):") case = tonumber(io.read("*l")) end while not count do print("Write students count (number):") count = tonumber(io.read("*l")) end local coolest = {name = "", score = -math.huge} for i = 1, count do local studentname, score while not studentname do print("Write " .. i .. " student (name score):") local line = io.read("*l") studentname, score = line:match("(%w+).-(%-?%d+%.?%d*)") if studentname then score = tonumber(score) print("Student #" .. i .. ": ", studentname, "score: ", score) if score > coolest.score then coolest.name = studentname coolest.score = score end end end end print("Coolest student is ", coolest.name, ", he's score is:", coolest.score)
Prath
Thx you very much
Snusmumriken
Thx you very much
This is very typical task. Why you do not google it?
Prath
I was searched but not get
Snusmumriken
Why do you need ffi for it?
Snusmumriken
I was searched but not get
Also why Lua? Why not python, java/javascript, C etc?
Prath
Actually currently learning lua
Prath
On codechef coding platform
Prath
Can we solve this by table as input in lua
Snusmumriken
Can we solve this by table as input in lua
No-no. Any language is a tool for specific tasks. You should learn for specific tasks. Learning for learning is a no way.
Snusmumriken
Can we solve this by table as input in lua
So what do you need Lua for? What tasks are you planning to do?
Prath
But here input in one line how to do
Snusmumriken
But here input in one line how to do
I've already written all this.
Prath
Okay thx
fgntfg
What is next? You will come with next task from codedef?
fgntfg
Хмм, я придумал страшно не эффективный алгоритм поиска максимума.
fgntfg
Придет ещё раз - напишу такой код, что плакать захочется. O(n!) или что-то типа того.
Snusmumriken
Топово
Snusmumriken
Будем закидывать их предельно неэффективными решениями
Snusmumriken
Мой вариант с FFI вон память жрёт без необходимости.
EN3RGY DRAGON
А что такое асинхронность?
Snusmumriken
А что такое асинхронность?
Это когда несколько функций поочерёдно выполняются по кусочкам, потом ставятся на паузу и переходят к следующим. И так пока не будут выполнены.
fgntfg
Ммм, поиск максимума на корутинах
Snusmumriken
Ну, простейший аналог корутины — это какая-нибудь структура типа local task = {} function task:isDone() ... if a an b and c then return result end end Ближе к конечным автоматам, но тоже работает и может поражать асинхронностью. Правда, сам код в isDone приходится писать не прямо, а через задницу, как для конечного автомата.
Anton
Ммм, поиск максимума на корутинах
Мультитредовый пузырек
Anton
Мап-редьюснутый.
Snusmumriken
string.lower and string.upper.
Snusmumriken
Read the doc pls. Lua has tutorial books and list of functions: https://www.lua.org/manual/5.1/ Read it.
Snusmumriken
This chat is not your "task solver". You MUST solve it by yourself.
Highly Likely
Есть тут кто-нибудь, кто успешно РУКАМИ (без мингв) собрал и поставил на винду Lua 5.1 + Luarocks под 5.1?
Highly Likely
У меня уже это выглядит как какой-то невыполнимый квест и накатить Линукс второй осью звучит уже значительно более простой задачей
Highly Likely
Потому что он полумертвый как минимум
Highly Likely
Но это скорее просто хотелка
Highly Likely
Емнип это не оригинал, но надо посмотреть
Highly Likely
Но суть от этого конечно сильно не меняется
Highly Likely
Не может же быть такого, что эту связку на винде руками поставить невозможно
Highly Likely
Я знал, что Винда не про разработку, но не подозревал, что настолько
Highly Likely
Я вот просто размышляю, насколько мне это принципиально уже
Highly Likely
накатить среду разработки на винде
Leon174
Не может же быть такого, что эту связку на винде руками поставить невозможно
Ну, я таки не осилил. Не могу сказать, что сильно упирался, тем не менее не осилил. По этой причине, луароксом не пользуюсь. Мне не сильно и надо (зелен виноград, ага).
Highly Likely
Я каким-то образом на рабочей машине смог их настроить и подружить
Highly Likely
А вот на своем компе уже второй день е... мучаюсь
Leon174
Приятно знать что я не один
Если ишью почитать у луарокса, то там соратников дофига будет. Винда - это про боль.
Highly Likely
Короче, пойду я дальше писать код на этих ваших Юникса
Highly Likely
А Винду оставлю для поиграть
Highly Likely
Безумие какое-то
Snusmumriken
Есть тут кто-нибудь, кто успешно РУКАМИ (без мингв) собрал и поставил на винду Lua 5.1 + Luarocks под 5.1?
Собирай VS. Считай что это стандартный компилер венды. И им всё замечательно собирается.
Leon174
С busted такая же фигня была. И тоже куча страдальцев с проблемами под виндой. Нашел pure вариант на замену, тесты переписал, и послал к чертовой бабке этот бустед со всеми его геморроидальными шишками.
Snusmumriken
Луарокс отлично подсоединяется к ВС, покопайся в конфигах
Highly Likely
А вот дальше распихать все по путям и настроить их взаимодействие уже нечто за гранью моего понимания
Алексей
Ребята привет, может тут есть кто то , кто бы мог за определенную плату, довести до ума небольшой скрипт в lua для node mcu?
Alexey
Есть тут кто-нибудь, кто успешно РУКАМИ (без мингв) собрал и поставил на винду Lua 5.1 + Luarocks под 5.1?
Есть :) https://github.com/moteus/lua-windows-environment Либы правда давно не обновлял
Prath
Plz help me
Prath
What changes in code to do??
Prath
I will search but not find
Snusmumriken
What changes in code to do??
You should read it all.
Prath
Plz one help
Prath
Plz plz
Snusmumriken
No.