llm-playground / has_closest_elements.evy
joshcarp
Initial huggingface commit
bcffb9c
func has_close_element:bool nums:[]num threshold:num
for i := range (len nums)
for j := range (i + 1) (len nums)
if (abs nums[i]-nums[j])<threshold
return true
end
end
end
return false
end
func abs:num n:num
if n < 0
return -n
end
return n
end
fails := 0
total := 0
func assert want:any got:any
total = total + 1
if want != got
fails = fails + 1
printf "want != got: want %v got %v\n" want got
end
end
func finished
printf "%v of %v tests passed\n" (total - fails) total
end
// -- Test Cases Start -- //
assert false (has_close_element [1.0 2.0 3.0] 0.5)
assert true (has_close_element [1.0 2.8 3.0 4.0 5.0 2.0] 0.3)
// -- Test Cases End -- //
finished