Skip to content
programming languages for all
GitHub

Binary Search in Lua

문제

Binary Search in LuaYou have stumbled upon a group of mathematicians who are also singer-songwriters.

참고할 자료와 개념

풀이된 예제

명령형

---@param s string
---@return boolean
local function is_isogram(s)
    local seen = {}
    for c in s:lower():gmatch "%a" do
        if seen[c] then
            return false
        else
            seen[c] = true
        end
    end
    return true
end

return is_isogram

-- 7 successes / 0 failures / 0 errors / 0 pending : 0.000893 seconds

함수형

local f = require "fun"

---@param s string
---@return boolean
local function is_isogram(s)
	local target = s:lower():gsub('[^%a]', '')

	return not f.enumerate(target):some(function(i, c)
		return target:sub(i + 1):find(c)
	end)
end


return is_isogram

-- 7 successes / 0 failures / 0 errors / 0 pending : 0.001685 seconds