20 Algorithmic Style Coding Problems/Questions for Practice

This looks awesome, definitely gonna test myself with this later.

2 Likes

I know I said I would get back to this on the 4th, but I have been busy with my game and I still am
I will post a model showcasing the 20 solutions but I will not be making a github because I am assuming that a github will be made for everyone at a later date

these are my 20 solutions

image
That is my output when all 20 functions are ran at once

1 Like

sorry if im a bit late, here is 16-20
16. not sure what is 'kā€™th

17. built-in math module

math.sqrt(x)

18. recursively prime number search

function prime(n, i) 
   i = i or 2
   if i > n then return false end
   return n % i == 0 or prime(n, i+1) 
end
function findPrimaryInArray(tb, i) 
  local i = i or 1
  if #tb < i then return nil end
  return prime(tb[i]) and tb[i] or findPrimaryInArray(tb, i+1) 
end
-- tb: table<int>, i: number (start index) 
-- {0, 1, 3, 4} -> 3
print(findPrimaryInArray(intTable))

19. modify primary to another value(?)

function modifyPrimaryInArray(tb, newval, nth, i) 
  local i, nth = i or 1, nth or 1
  if #tb < i or nth <= 0 then return tb end
  if prime(tb[i]) then tb[i] = newval; nth = nth - 1 end
  return modifyPrimaryInArray(tb, newval, nth, i+1) 
end
-- tb: table, newval: any, nth: number (n-th occurence that should be changed), i: number (start index) 
-- modifyPrimaryInArray({0, 1, 3, 4}, 6, 1) -> {0, 1, 6, 4}

20. sort table of string by char code index

local tb = {"Ab", "a", "z", "AB"}
table.sort(tb, function(a, b) return a<b end)
print(table.concat(tb, "\n")) 
-- AB = 65+66, Ab = 65+98, a = 97, z = 122

+ bonus part

-- merging table without loop
local a = {0,1,2}
local b = {3, 4}
local c = {table.unpack(a), table.unpack(b), 5}
-- c: {0, 1, 2, 3, 4, 5}

all codes are tested using vanilla lua and should also work in luau.

2 Likes

I think I might do some of those in my free time, over the years I lost all my roblox lua knowledge and right now Iā€™m struggling so hard to even complete the first one :skull: It would be a good chance to clean the rust away and get back into roblox scripting, anyways, using C# I was able to do them all very easily though and it was really fun!

1 Like

Question 9 in easy difficulty, the function add is missing an argument, which is the element you insert into the stack, or I just misunderstood somewhere? :thinking:

1 Like

Your solution can be optimized a bit more :+1:

1 Like

Ooh might try some of these!

1 Like

Solved 20/20, pretty cool challenge! :+1:
Here are my solutions: GitHub - Zoesads/algo-style-quests: 20 Algorithmic style quests - My solutions

1 Like

Did not mean to reply, sorry
Only did the easy pack (all of them), the rest seems too hard for me (I suck at math, Iā€™ll admit it)
coding-questions-re-rev1.rbxm (10.6 KB)

1 Like

You donā€™t really need math to solve them.

1 Like

Can you please put descriptions of each problem in the thread itself?

1 Like

You can check them in my GitHubā€™s repo (along with the solutions)

1 Like

Your GitHub repo isnā€™t linked in the original post.

1 Like

Hereā€™s the repo: GitHub - Zoesads/algo-style-quests: 20 Algorithmic style quests - My solutions

2 Likes