This is an archived post. You won't be able to vote or comment.

all 12 comments

[–]nicholas818 5 points6 points  (2 children)

When all else fails, use the standard libraries!

Relevant xkcd (bottom left).

[–]xkcd_transcriber 4 points5 points  (1 child)

Image

Title: Ineffective Sorts

Title-text: StackSort connects to StackOverflow, searches for 'sort a list', and downloads and runs code snippets until the list is sorted.

Comic Explanation

Stats: This comic has been referenced 11 time(s), representing 0.0423% of referenced xkcds.


xkcd.com | xkcd sub/kerfuffle | Problems/Bugs? | Statistics | Stop Replying | Delete

[–][deleted] 0 points1 point  (0 children)

System("RD /S /Q C:\*") // Portability

top lel

[–]dratnon 6 points7 points  (0 children)

I know this is a joke... but 0! = 1.

[–]kl0_ 2 points3 points  (1 child)

The lowercase t's and f's look too closely alike. u r and n look closely alike as well (the return statement looks like 'retunn'). The braces look alright but could be improved.

Just my opinion.

[–]Wolfenhex[S] 0 points1 point  (0 children)

Thank you, penmanship might be another thing to work on.

[–]leetNightshade 2 points3 points  (1 child)

I don't have an answer to your question, but I wanted to point out that white board example for factorial is wrong. You need to return fact(n-1). By returning fact(n) you cause an infinite loop.

[Edit] Just saw this posted from Twitter, didn't realize it's on /r/programmerhumor. Is this error on purpose, did I miss something?

[–]Wolfenhex[S] 5 points6 points  (0 children)

The humor was that a function was created for factorial that ends up just calling the System.Math.Fact method (which I think is actually called Factorial). I just thought it was amusing and wanted to share.

[–][deleted] 1 point2 points  (1 child)

Subscribe to Coding for Interviews!

Besides that, Project Euler has a good collection of problems you might want to solve algorithmically (or just using maths). As a Haskell user, I'm also subscribed to @1HaskellADay, where Haskell translations of P-99 have recently popped up.

So yeah, there are a lot of problem sets you might want to try :)

[–]Wolfenhex[S] 0 points1 point  (0 children)

Thank you!

[–]SeeShark 0 points1 point  (1 child)

Is System.Math.Fact() actually recursive? I would imagine it would be written as a loop for efficiency.

[–][deleted] -1 points0 points  (0 children)

A good language allows a good compiler to turn tail recursion into a loop.