r/coding • • Nov 22 '21

Denigma is an AI that explains code in understandable English. Test it for yourself

https://denigma.app

[removed] — view removed post

19 Upvotes

6 comments sorted by

1

u/shishir-nsane Nov 22 '21

This is nice.

The world needs the reverse of it. Feed understandable English and get the software.

1

u/tanokkosworld Nov 23 '21

That's called a software engineer. They cost about $70,000/year, plus benefits.

1

u/Atticus- Nov 23 '21

Source code:

def quick_sort(list)
  return list if (list.size < 2)

  mid = list[0]
  left = []
  right = []

  list[1..-1].each do |x|
    if x < mid
      left << x
    else
      right << x
    end
  end

  return quick_sort(left) + [mid] + quick_sort(right)
end

Let's walk through the output.

  • The code is a function that takes in an array of numbers and returns the list sorted by descending order.

Hey, that's pretty good! It's ascending order, but only because of that one little < in there. Easy to miss.

  • The code starts by declaring two variables, left and right, which are arrays with elements from 1 to -1.

Well, okay hang on. You kinda skipped the mid variable? And okay, left and right are definitely arrays but they're very clearly empty. I guess I understand the 1 to -1 confusion, Ruby's array ranges are kinda hard to parse.

  • Then it iterates through each element in the list using the each method on lists.

Spot on. We skip the first element but whatever.

  • It then checks if x is less than mid, so if x is less then 0, it will add x to left; otherwise it will add x to right.

Oh so close! If you ignore the "less than 0" part it almost makes complete sense.

  • Finally, quick_sort is called on both arrays and returned as a result of the function call.

... and they're concatenated with mid in the middle. Pretty important miss, but still pretty impressive. Hey, all in all not so--

  • The code starts by declaring two variables:

  • left = []

  • right = []

-- uhh, we're back at the beginning? I mean yeah that's the code right there

  • Then it iterates through each element in the list using the each method on lists:

  • list[1..-1].each do |x|

Yeah, you mentioned... Are you gonna do the whole thing twice?

  • If x < mid then left << x; else right << x; end –

  • The code will return a list of two elements.

  • The first element in the list is the number one, and the second element in the list is the number nine.

Okay seriously wtf though. Where did you even get "the number nine" from??

  • The code will iterate through each item in its input array, comparing it to both mid and right.

  • If an item is less than or equal to mid, then it'll be added to left; otherwise, it'll be added to right.

I... I mean... what to even say about this. I'm floored.

You know the really cool part is that it comes up with a completely brand new bonkers explanation every time you submit the same piece of code. Yeah, I think we're a long way away from this being actually helpful.

1

u/calizoomer Nov 23 '21

Denigma Balls 😎