Fizzbuzz, Interviews, And Overthinking
61–70 of 115 posts
Re: Fizzbuzz, Interviews, And Overthinking
#62I recently challenged people to codegolf fizzbuzz ( http://swizec.com/blog/fizzbuzz-without-ifs-in-90-char-i-wil... ) The Haskell solution was really cool: [max(show x)(concat[n|(f,n) This is much simpler and it looks easier to extend as well.
for i in range(100):print ''.join([s*(i%m==0)for m,s in[(3,"Fizz"),(5,"Buzz")]])or iRe: Fizzbuzz, Interviews, And Overthinking
#63Earlier quoted context omitted.
It's a different kind of pressure though.
Explain. If you can't produce a god damned string reversal function in 10 minutes, why would I believe you can produce a bug fix to your own, complex code in a few hours? That's what interviewers are considering: the interview is a proxy to see if you can come close to the requirements of the job.
The pressure of judgement is not the same as the work pressure of a stressful scenario. It's why public speaking and job interviews are among the most feared activities people go through, but people consider meetings boring and mundane.
Re: Fizzbuzz, Interviews, And Overthinking
#64I recently challenged people to codegolf fizzbuzz ( http://swizec.com/blog/fizzbuzz-without-ifs-in-90-char-i-wil... ) The Haskell solution was really cool: [max(show x)(concat[n|(f,n) This is much simpler and it looks easier to extend as well.
# 97 characters
for my $i (1..100) { say join("", map { {3=>'fizz',5=>'buzz'}->{$_} unless $i % $_ } 3,5) || $i }
# 81, if those pesky spaces are removed
for my$i(1..100){say join("",map{{3=>'fizz',5=>'buzz'}->{$_}unless$i%$_}3,5)||$i}Re: Fizzbuzz, Interviews, And Overthinking
#65I agree that Fizzbuzz can be a more interesting example of how to write code without repetition. While the author suggests that languages such as Haskell provide a unique advantage, the deciding question seems to be the availability of pre-built abstractions. Consider the following solution in Python: for i in xrange(1,101): print (('' if i%3 else 'Fizz')+('' if i%5 else 'Buzz')) or i or the even more general: mappin…
My "I'm going to hell, but that's okay" C version: #include #include #define when(mod, msg) do { if((i mod) == 0) { fputs(#msg, stdout); *hit = true; } } while(0) #define through ; i Super extensible!
Or, since github's being broken right now:
#include
#include
template
class Noisemaker {
private:
union {
uint32_t noise_as_int;
char noise_as_cstr[5];
};
public:
Noisemaker() {
noise_as_int = htonl(noise);
noise_as_cstr[4] = '\0';
}
bool operator()(std::ostream &out, int i) {
if(i % multiples_of == 0) {
out
class NoisemakerPair {
private:
Noise1 noise1;
Noise2 noise2;
public:
bool operator()(std::ostream &out, int i) {
bool matched = false;
matched |= noise1(out, i);
matched |= noise2(out, i);
return matched;
}
};
int main(int argc, char *argv[]) {
NoisemakerPair, Noisemaker > fizzbuzz;
for(int i=1;i
You can nest NoisemakerPairs to add more Noisemakers. But good luck with strings longer than 4 characters… for some absurd reason, string literals can't be template parameters. Go figure.Re: Fizzbuzz, Interviews, And Overthinking
#66I recently challenged people to codegolf fizzbuzz ( http://swizec.com/blog/fizzbuzz-without-ifs-in-90-char-i-wil... ) The Haskell solution was really cool: [max(show x)(concat[n|(f,n) This is much simpler and it looks easier to extend as well.
Re: Fizzbuzz, Interviews, And Overthinking
#67And why introduce monad comprehensions if you're just introducing monoids?
Re: Fizzbuzz, Interviews, And Overthinking
#68Earlier quoted context omitted.
Firstly, the ruby code was produced (admittedly from my memory) from someone on the tail end of a 5 hour interview process, of which I was not the first technical interviewer. It is exceptional in that context. Secondly, I feel like you (and aristus in his/her code snippet above) missed the secondary point of my post. Please consider that monoids and Maybe are capturing a higher level pattern in a way that we can com…
I'd like to understand more that second point. How is Maybe not morally equivalent to a conditional? If my ifs were in a separate function that would also work, no?
fizzbuzz d i = mconcat (rules pure i) pure (d i)
This is written in terms of an Applicative Functor and a Monoid.And then can just do some haskell things. I've done less golfing here and more type signatures to make the code more approachable.
{-# LANGUAGE MonadComprehensions, OverlappingInstances, FlexibleInstances#-}
module Main where
import Control.Applicative
import Data.Monoid
import Control.Monad
import Data.Maybe
import Data.List
import qualified Data.HashMap.Strict as M
import System.Environment
-- Let's make it clear what we're working with.
type Counter = M.HashMap String Integer
-- We want an instance slightly different from the default.
instance Monoid Counter where
mempty = M.empty
mappend = M.unionWith (+)
factors = [(3, "fizz"), (5, "buzz"), (7, "bazz")]
-- Our rule function is slightly different.
-- Not unexpected, since our logic has changed. But we could generalize
-- this further!
rules :: [(Integer -> Maybe Counter)]
rules = [\i -> [M.singleton res 1 | i `rem` fac == 0] | (fac,res) pure i) pure (d i)
main = do
upTo
And then a typical session: ~/P/h/fb-toys > time ./fbg3 10000000
fromList [("bazz",1428571),("fizz",3333333),("buzz",2000000)]
3.58 real 3.54 user 0.03 sys
Which is a pretty expensive way to avoid doing algebra, but the point is that we're talking about very high level patterns here for fizzbuzz. Fizzbuzz is probably a bad name here, it's more like mergeOptionalPatterns. I'm willing to bet if I dug a round a bit in parser combinator libraries I could find something that does nearly exactly this.I confess I had to play with it a bit to get it to play nice with large inputs.
Re: Fizzbuzz, Interviews, And Overthinking
#69I was waiting for a Java solution with an AbstractFactory somewhere.
Re: Fizzbuzz, Interviews, And Overthinking
#70Earlier quoted context omitted.
It's a different kind of pressure though.
Explain. If you can't produce a god damned string reversal function in 10 minutes, why would I believe you can produce a bug fix to your own, complex code in a few hours? That's what interviewers are considering: the interview is a proxy to see if you can come close to the requirements of the job.
The point is more that for a person with a given skill level, interviews can be stressful and make them perform below that skill level. I try to structure my interviews such that people get more comfortable and I don't ram their head into a metaphorical wall. I get all the same information, but without all those hard feelings.