对一门不是非常熟悉的语言是怎么面试的

公司是一个基础通讯类的公司,需要的职位是一个高级系统和软件工程师。

职位要求,是一个完全不怎么大众的语言:Elixir。

没听过,这就对了,这是一个函数式的语言,可以认为是 Erlang 的升级版本,Erlang 多用在交换机设备上的开发语言,这个语言其实还是比较小众的。

RabbitMQ 就是 Erlang 开发的,虽然 Erlang 在整个项目中的比例并不是很高。

职位需求

这个职位的需求就是使用 Elixir 语言来处理 HTTP 的 API。

这个 API 主要是用户电子邮件相关的内容,我不知道为什么他们选择 Elixir,可能主要还是比较好和现有的系统保持一致吧。

面试

整个面试的时间是 1 个小时。

在这一个小时中主要聊了下对 HTTP 的请求,API 的调用是不是熟悉。不管用的是什么语言,只要你写过 API,这部分还是比较容易说清楚的。

下一步就是在线的 Coding 了,这个在线的代码也是非常简单的,唯一麻烦的地方是 Elixir,因为从来没有接触过这个语言,突然在平台上要用 Elixir 这个语言还是有点懵逼的。

好在示例程序什么都比较简单,就是对照下 API 的调用文档,利用模拟的环境写几个 API 接口。

只要有示例程序,要写其他的还是很简单就完成了,因为对 API 的写法,不管什么语言都差不多。

好在他们提供了一个 API 的示例程序。

在这部,都已经顺利完成了所有的代码,也正确没有问题。

随后他们就提出是不是给我一个回家做的题目,要求是完成这个题目,然后尽快提交给他们。

回家做题

对于给出的题目,稍后我在下面的文章中给出。

如果你是使用其他的比较高级的语言,这个应该没有什么问题,可以说是非常简单的。

但是 Elixir 是一个函数式的语言,同时循环是不可变的,在这里哪怕是一个循环都要折腾半天。

本着,既然我答应你回家试试了,那么我就抱着一定要做出来的想法来做的,也在规定的时间把代码提交了。

结果

大概 1 周后,收到了他们比较客气的拒绝信。

理由是找到了更加合适的人了。

点评

找到更加合适的人,这个不足为奇。因为 Elixir 这个语言实在是非常小众的语言,有比较大的学习曲线。

不是说,你今天开始看文档,明天就能全部看明白的那种。

这个语言没有好的集成 IDE 开发环境,代码写起来不是那么友好,高级语言非常容易实现的东西,Elixir 需要比较多的步骤才能完成。

其实,对公司本身来说,这次面试并没有什么负面评价。主要原因是,在投简历的时候没有仔细看看需要的语言,主要是看了 API 编程能力。

通常来说,这个都不是什么问题。

唯一感觉有点不好的是,公司方面对面试者的反馈比较差。在我提交代码到对方邮箱后,没有任何邮件说邮件已经收到了。完全不知道邮件是不是已经发送过去了或者他们在进行评估什么的。

一般来说,2 到 3 天没有消息的话,感觉都不会非常靠谱,所以也没有抱有太大希望。

只是希望的是,他们应该可以通过更好的沟通让整个流程更加好,可惜他们没有做到,有点把面试当儿戏的意思。

题目和解答

Program 1

Using input_data1.txt, complete the code in file program1.exs

You can install Elixir on a machine you work on, or you can
use Try It Online or something similar.
tio has an input section where you can paste in the input data.

input_data1.txt (3.6 KB)

源代码如下:

defmodule M do
  def read do
    IO.read(:stdio,:all)
  end

  def input_to_list( input ) do
    # turn single string into a list of input values
    String.split(input)
  end

  def calculate([head | tail], acc) do
    calculate( tail, head + acc )
  end
  
  # finish
  def calculate( [], acc ) do
	acc
  end
end


IO.inspect M.read() |> M.input_to_list |> M.calculate(0)

Program 2

Extending the technique of Program 1, write a program that
given 3 lists, selects the greatest even value at each iteration and
adds it to an accumulator. For example:

[ 5, 8, 9, 2, 4, 7 ]
[ 9, 1, 6, 7, 9, 6 ]
[ 4, 4, 8, 6, 2, 4 ]

sums the list:

[ 4, 8, 8, 6, 4, 6 ]

and a sum of 36

The lists to use are:

[184, 89, 960, 133, 239, 413, 425, 355, 636, 519, 430, 562, 296, 175, 471, 260, 279, 934, 667, 804, 954, 274, 833, 428, 912, 789, 76, 805, 522, 692, 139, 598, 943, 309, 954, 265, 958, 559, 722, 910, 388, 996, 716, 706, 291, 236, 593, 154, 103, 8, 319, 722, 863, 493, 384, 206, 696, 563, 276, 422, 642, 163, 926, 823, 608, 193, 713, 119, 141, 297, 99, 321, 976, 972, 46, 34, 719, 186, 446, 563, 139, 887, 729, 319, 679, 734, 565, 531, 210, 275, 113, 409, 384, 872, 442, 364, 757, 44, 332, 802, 389, 626, 15, 376, 143, 450, 362, 31, 847, 935, 103, 856, 700, 78, 904, 697, 453, 995, 420, 426, 1000, 264, 88, 384, 323, 322, 289, 383, 916, 460, 350, 29, 384, 421, 869, 462, 156, 362, 162, 757, 31, 450, 85, 850, 344, 864]
[112, 348, 854, 848, 27, 435, 103, 625, 477, 203, 513, 736, 638, 229, 517, 580, 476, 692, 124, 136, 257, 785, 415, 5, 332, 366, 124, 108, 864, 362, 272, 331, 20, 612, 532, 18, 487, 524, 266, 973, 642, 46, 174, 256, 37, 416, 424, 749, 532, 922, 279, 537, 268, 148, 981, 141, 334, 603, 570, 400, 4, 24, 789, 416, 475, 442, 485, 636, 151, 736, 162, 528, 52, 804, 793, 183, 734, 365, 595, 922, 187, 48, 365, 164, 47, 467, 63, 325, 250, 980, 970, 853, 716, 639, 382, 482, 241, 377, 753, 689, 108, 240, 261, 48, 478, 922, 648, 468, 33, 71, 670, 421, 727, 780, 873, 648, 416, 661, 655, 202, 745, 177, 264, 175, 284, 49, 333, 727, 668, 323, 593, 408, 693, 98, 332, 148, 634, 739, 703, 157, 359, 346, 90]
[915, 576, 254, 844, 744, 656, 149, 46, 883, 902, 636, 545, 978, 972, 572, 686, 927, 781, 463, 384, 450, 690, 322, 454, 686, 309, 56, 152, 622, 94, 579, 395, 964, 787, 886, 336, 606, 286, 880, 248, 337, 425, 590, 342, 980, 731, 541, 941, 788, 481, 753, 912, 100, 306, 414, 736, 360, 454, 52, 984, 420, 750, 839, 173, 450, 260, 189, 929, 659, 349, 664, 989, 219, 62, 566, 346, 150, 446, 838, 880, 644, 898, 662, 610, 688, 225, 519, 655, 489, 63, 492, 916, 762, 990, 273, 241, 925, 259, 138, 929, 769, 991, 981, 298, 437, 120, 627, 636, 107, 505, 80, 781, 13, 924, 901, 905, 507, 559, 48, 778, 444, 65, 312, 287, 804, 960, 573, 533, 52, 763, 188, 379, 709, 820, 334, 519, 992, 218, 550, 253, 812, 83, 620, 539, 404, 317, 966, 657, 630]

源代码如下:

defmodule M do
  def read do
    IO.read(:stdio,:all)
  end

  def input_to_list( input ) do
    # turn single string into a list of input values
    inputList = String.split(input, "\n")
    [head | tail] =inputList 
    list_1_str = head 
    [head | tail] = tail
    list_2_str = head 
    [head | tail] = tail
    list_3_str = head 

	#pattern = :binary.compile_pattern([" ", ", "])
	#IO.inspect(String.split("[1,2 3,4]", pattern))

	list_1_str = String.replace(list_1_str ,"[", "")
	list_1_str = String.replace(list_1_str ,"]", "")
	list_1_str = String.replace(list_1_str ," ", "")
	list_1 = String.split(list_1_str,[" ", ","])

	list_2_str = String.replace(list_2_str ,"[", "")
	list_2_str = String.replace(list_2_str ,"]", "")
	list_2_str = String.replace(list_2_str ," ", "")
	list_2 = String.split(list_2_str ,[" ", ","])

	list_3_str = String.replace(list_3_str ,"[", "")
	list_3_str = String.replace(list_3_str ,"]", "")
	list_3_str = String.replace(list_3_str ," ", "")
	list_3 = String.split(list_3_str ,[" ", ","])


	length_list = [0]
        length_list  = [length(list_1) | length_list ]
	length_list  = [length(list_2) | length_list ]
	length_list  = [length(list_3) | length_list ]
 	length_max = Enum.max(length_list )


	IO.inspect(length_max )

	list_1 = list_1
		|> append_if(length_max > length(list_1),"0")
	list_2 = list_2
		|> append_if(length_max > length(list_2),"0")
	list_3 = list_3
		|> append_if(length_max > length(list_3),"0")

#	IO.inspect(list_1)
#	IO.inspect(list_2)
#	IO.inspect(list_3)


	lx =[list_1 | []]
	lx =[list_2 | lx]
	lx =[list_3 | lx]
	

	lx_1 = Enum.zip(lx)


	l = Enum.map(lx_1 , fn n ->
	 max_even(Tuple.to_list(n))
	end)

	IO.inspect(l)

  end


defp append_if(list, condition, item) do
  if condition, do: list ++ [item], else: list
end



  def max_even(list) do
   evenList = 	list
	|> Enum.map(&String.to_integer/1)
	|> Enum.filter(&rem(&1, 2) == 0)

   if Enum.empty?(evenList ) do
	0
   else 
	evenList 
	|> IO.inspect
	|> Enum.reduce(&max/2)
	|> IO.inspect
   end
  end



  def calculate([head | tail], acc) do

#IO.inspect(acc)
#IO.inspect(tail)
    calculate(tail, head + acc)
  end
  
  # finish
  def calculate( [], acc ), do: acc
end




#IO.puts M.calculate(["1", "2", "3"], 0)

IO.inspect M.read() |> M.input_to_list |> M.calculate(0)

如觉得代码比较难读的话,可以直接下载我们的附件,在附件中有题目说明,测试数据和源代码。

interview.7z (3.9 KB)

上图是网站上的运行结果。