Monday Hacking Challenge (or Exercise)

by 8 replies
9
So, I was feeling a little geeky today and have not done any serious programming for a few years now.

Here is a simple problem to work on your hacking (coding) chops. You can use any language you like.

1. Take an arbitrary list of numbers
2. Generate a list of functions from these numbers that computes x^2+2y+1 where x is unknown and y is known
So passing 2 as y results in x^2+2*2+1 = x^2+5
3. If your list of numbers has 3 numbers, you generate 3 functions. If it has 10 you generate 10.
4. Positionally apply functions to numbers and add all together for a numerical result.

Example code in Racket (a version of scheme)



Hint: Use a dynamically typed language with higher order computation ability and you'll be happier
#programming #challenge #exercise #hacking #monday
  • what language are you using here?
  • It's a version of Scheme (which is a Lisp)
  • Hi,
    What is the benefit of this computing overall? Can I write the same program in C?
    • [1] reply
    • The benefit is higher order functions -> functions that return or accept functions as an input. With syntax based languages like C, there is also a double learning - you need to understand both logic and syntax before you even start actually programming. Being too close to machine does not allow you to easily express abstract thoughts and algorithms without too much coding.

      Yes, you can write it in C with perhaps a few thousand lines of code.

      It is way more efficient to write it in a higher order language and generate C code before compiling it to machine. Most Lisp->C compilers generate more efficient code than hand-written C (sometimes orders of magnitude).

      Stalin a popular Lisp->C compiler generates 2x to 7x faster executing C code than hand coding a C program by an expert.

      Languages like Scheme, Lisp, Python, Smalltalk etc are also interactive which shortens development time (max expense on project) considerably.

      When you have very few developers and a very large project, then these languages really help and are used as secret weapons.

      Google uses lots of Python (which borrows a lot from Lisp and Peter Norvig, the director of search quality at Google is a well known Lisp expert).

      ITA Software uses Lisp and it powers Orbitz and a whole lot of other airfare search engines

      Ruby is used by many including some popular apps that many IMers use such as Basecamp and Kajabi.

      Many security applications use higher level languages internally.

      Take Care,

      Sanjay
  • i like this stuff sanjay, but i just fried a fuse in my brain
  • so, we need to be able to dynamically create functions on the fly and call them, hmmm...
  • Facebook has some pretty fun coding challenges if anyone is interested.

    Engineering Puzzles | Facebook
  • thank you for sharing ideas how to hack godbless .

Next Topics on Trending Feed