…meie igapäevast IT’d anna meile igapäev…

2015-05-15

Want a hamburger?

Filed under: Isiklikud — Sander @ 10:05:47
Tags:

2015-05-13

Some fun with FizzBuzz in C#

Filed under: Isiklikud,Programmeerimine — Sander @ 13:34:03
Tags: ,

image As a very first thing, I must say that I don’t like whiteboard coding exercises during the job interviews.

These exercises have almost never any relation to real-life programming problems (“Reverse a linked list?” If your reply is anything besides “linkedList.Reverse();”, your answer is wrong.). There are only a few dozen common whiteboard coding questions – and every candidate with a common sense will review those before the interview.

Finally, success with whiteboard coding seems to have next to no connection with the actual qualities of the candidate. And yes, this includes “solving a problem under pressure”.

I much prefer to give the candidates a small task, to do at home in 2..3h. This will give me much more information – what is his coding style? Can he write high-quality and well-commented code? Did he actually manage to finish all parts of the task – and if not, then why? Does he even want the position enough to do a proper job?

That all said, FizzBuzz does have one good use – it can be used to quickly weed out the candidates who cannot program at all. If they cannot do a simple logical exercise, and write a loop with a couple of if-clauses inside it, they really shouldn’t be hired as developers.

That is why ex-coworker Erti-Chris and I were rather surprised after reading “Tales of a Non-Unicorn: A Story About The Trouble with Job Titles and Descriptions” (reddit thread). A person claiming to be “designer/developer if there ever was one” goes “OMG MATH” and cannot solve FizzBuzz (which has almost nothing to do with math)?!

Out of boredom we started to play around with FizzBuzz – albeit in C#, not JS (but all our ideas work with Javascript as well, with a little prodding) – first the “standard solution” and then limiting ourselves further and further.

The “standard solution” using modulus:

  1. Enumerable.Range(1, 100).ToList().ForEach(x =>
  2. {
  3.     var d3 = x % 3;
  4.     var d5 = x % 5;
  5.  
  6.     Print(d3 == 0, d5 == 0, x);
  7. });

Method Print is used repeatedly, it is the same everywhere:

  1. private static void Print(bool three, bool five, int i)
  2. {
  3.     if (three && !five)
  4.         Console.WriteLine("Fizz");
  5.     else if (five && !three)
  6.         Console.WriteLine("Buzz");
  7.     else if (five)
  8.         Console.WriteLine("FizzBuzz");
  9.     else
  10.         Console.WriteLine(i);
  11. }

But what if we don’t allow modulus to be used?

  1. Enumerable.Range(1, 100).ToList().ForEach(x =>
  2. {
  3.     var d3 = x / 3f == Math.Round(x / 3f);
  4.     var d5 = x / 5f == Math.Round(x / 5f);
  5.  
  6.     Print(d3, d5, x);
  7. });

But what about not using neither round nor modulus?

  1. Enumerable.Range(1, 100).ToList().ForEach(x =>
  2. {
  3.     var d3 = x / 3 * 3 == x;
  4.     var d5 = x / 5 * 5 == x;
  5.  
  6.     Print(d3, d5, x);
  7. });

(and also the same limitations as above, nutcase version. Proudly mine).

  1. Enumerable.Range(1, 100).ToList().ForEach(x =>
  2. {            
  3.     var d3 = !(x / 3f).ToString().Contains(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator);
  4.     var d5 = !(x / 5f).ToString().Contains(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator);
  5.  
  6.     Print(d3, d5, x);
  7. });

Still too easy. What about not allowing modulus, rounding, multiplication and division?

  1. for (int i = 0, three = 0, five = 0; i < 100; i++, three++, five++)
  2. {
  3.     if (three == 3 && five == 5)
  4.     {
  5.         Console.WriteLine("FizzBuzz");
  6.         three = 0;
  7.         five = 0;
  8.     }
  9.     else if (three == 3)
  10.     {
  11.         Console.WriteLine("Fizz");
  12.         three = 0;
  13.     }
  14.     else if (five == 5)
  15.     {
  16.         Console.WriteLine("Buzz");
  17.         five = 0;
  18.     }
  19.     else
  20.         Console.WriteLine(i);
  21. }

Amusingly, the last version is fastest of them all.

And by now we were out of time and bored of this. It was fun, though – a sort of minor coding kata.

All the code above can be seen and executed in dotNetFiddle, https://dotnetfiddle.net/84PodI

2015-04-24

Aasta eesti-inglise sõnastiku uusversioonist

Filed under: Isiklikud — Sander @ 14:11:38
Tags: , ,

Täna saab aasta sellest, kui mu eesti-inglise-eesti sõnastiku uusversioon välja tuli (blogipost, sõnastik). Mis siis aasta jooksul on toimunud?

  • 55 231 külastust
    • 50 999 (92.34%) arvutist
    • 3 406 (6.17%) mobiilist
    • 826 (1.50%) tabletist
  • 282 035 otsingut
    • 273 276 (96.89%) arvutist
    • 8 759 (3.11%) mobiilist
    • 165 538 (58.69%) inglise ⇒ eesti suunal
    • 116 497 (41.31%) eesti ⇒ inglise suunal
  • 211 942 sõna eesti ⇒ inglise suunal
  • 199 640 sõna inglise ⇒ eesti suunal

Allpool on graafik külastajate hulgast, kuude kaupa. Nagu näha, siis on pidev kerge tõusutrend. Järsk tõus jaanuaris 2015 on seetõttu, et eelmine sõnastikuversioon (dukelupus.com/dict) hakkas automaatselt külastajaid uuele sõnastikule suunama.

 image

Ideid tulevikuks

  • Ülemine ASP.NET 5’le. Saab teha siis, kui SmarterASP.net seda toetama hakkab.
  • Korralik haldusliides.
  • HTML5 <datalist> on endiselt Firefoxis katki, seega kas jQuery UI AutoComplete või mõni pisem lahendus. Kuivõrd Chromel ja IE’l datalistiga probleeme pole, siis kas brauserispetsiifiliseks?

Eraldi tahaks tänada Henri P.’d, kes teatas mitmetest probleemidest ja puudustest.

Järgmine lehekülg »

The Rubric Theme. Create a free website or blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 84 other followers