NillionNetwork / nada-by-example

Learn the Nada language by working with example Nada programs
https://docs.nillion.com/nada-by-example
MIT License
11 stars 8 forks source link

Nth Largest Element of list/array #17

Open jimouris opened 2 months ago

jimouris commented 2 months ago

Request a New Nada Example

Find Nth largest element in list.

Description

Write a Nada program to find the nth largest (or smallest) element in size from a list or array.

optional: extended into multiple dimensions with custom comparators.

Use Case

Describe the use case for this example. Why is it important? How will it benefit other users?

Specific Requirements

Sohammhatre10 commented 2 weeks ago

Hello @oceans404 I'll take this one.

Sohammhatre10 commented 2 weeks ago

Have completed this here https://github.com/NillionNetwork/nada-by-example/pull/40 will you guys please check the same @oceans404 @jimouris Thanks!

jimouris commented 2 weeks ago

Hey @Sohammhatre10! Thanks for your PR!

It seems that the way I wrote this issue was a bit confusing. This was to return the nth largest, not the element on the nth position. Check the inputs and outputs:

Inputs: A list/array of SecretIntegers and the n. Outputs: The nth largest value of the list.

What you implemented is really good though so we can definitely merge it but we'll keep this issue open :) I have some small comments about your implementation; I'll follow up directly in the PR.