Kyle Taylor on 13 Sep 2017 11:16:35 -0700


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] Why Can't Programmers.. Program?


You guys covered a lot of the discussion already, but I like the video from “Tom Scott” if any of you are fans or aware. He does a pretty good discussion of the problem, notably the tricky part of the problem (as was mentioned earlier) and even explains the true purpose of the problem.

https://www.youtube.com/watch?v=QPZ0pIK_wsc

Since this was intriguing for some I’d like to mention the famous Microsoft interview question: 

“Why are manhole covers round?”

https://en.wikipedia.org/wiki/Microsoft_interview#Manhole_cover_question

- Kyle

On Sep 13, 2017, at 1:27 PM, Thomas Delrue <delrue.thomas@gmail.com> wrote:

On Wednesday, September 13, 2017 10:00:09 AM EDT Rich Freeman wrote:
On Wed, Sep 13, 2017 at 7:47 AM, ronpguilmet <ronpguilmet@gmail.com> wrote:
This is not New, but it is new to me. Apparently this is a programming
interview question to weed out applicants. It's called FizzBuzz.

Write a program that prints the numbers from 1 to 100. But for multiples of
three print "Fizz" instead of the number and for the multiples of five
print
"Buzz". For numbers which are multiples of both three and five print
"FizzBuzz".

https://blog.codinghorror.com/why-cant-programmers-program/

Part of me wants to make it slightly more challenging by adding one more
rule:
The program cannot do more than 2 comparisons.

I'm trying to think of what the most optimized solution overall for
this is.  

With the risk of sounding pedantic: optimized for what? Cycles (on which 
silicon exactly, is it x86, ARM, ...?), speed, readability, IoT, the failure 
rate, power usage, memory usage, pink unicorns...?

The most readable solutions will often involve 3
comparisons.  You could get by with 2, but depending on how you store
the result of one of the comparisons I'm not sure that actually buys
you anything.

Optimizing for readability is not a bad thing. Code gets read more often than 
it gets written. And when it is read, it is important to make sure the reader 
understands what is happening rather than pulling a couple of fancy tricks 
just to show off how much you master language X or Y.
Plus, compilers are pretty darn clever and can 'undo' a lot of your 
readability optimization and optimize for speed - even if your code is verbose 
and sub-optimal because sometimes they can detect your intent(*).

(*) I've worked on compilers and interpreters in the past, it's a very 
interesting space! If you're interested in this, grab a copy of the dragon 
book to get started!___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug

___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug