【第22期】观点:IT 行业加班,到底有没有价值?

Cody Problem 1-10 Solutions

原创 2016年08月29日 10:06:03

Problem 1  Times 2

function y = times2(x)
  % Modify the line below so that the output y is twice the incoming value x
  y = x*2;
  % After you fix the code, press the "Submit" button, and you're on your way.
end


Problem 2 Make the vector [1 2 3 4 5 6 7 8 9 10]


function x = oneToTen
  x = [1:1:10];
end


Problem 3. Find the sum of all the numbers of the input vector

function y = vecsum(x)
   y = sum(x);
end

Problem 4. Make a checkerboard matrix

function a = checkerboard(n)
  a = ones(n);
  a(1:2:n, 2:2:n) = 0;
  a(2:2:n, 1:2:n) = 0;
end

Problem 5. Triangle Numbers

function t = triangle(n)
    t = sum([1:n]);
end


Problem 6. Select every other element of a vector

function y = everyOther(x)
  y = x(1:2:length(x));
end

Problem 7. Column Removal

function B = column_removal(A,n)
  A(:,n) = [] ;
  B = A;
end

Problem 8. Add two numbers

function c = add_two_numbers(a,b)
  c = a+b;
end


Problem 9. Who Has the Most Change?

function b = most_change(a)
  price = [0.25; 0.05; 0.1; 0.01];
  c = a*price;
  b= find(c==max(c));
end

ps: 每次找index这种题都不是很顺利

Problem 10. Determine whether a vector is monotonically increasing

function tf = mono_increase(x)
  tf = true;
  for i = 1:length(x)-1
      result = x(i+1)>x(i);
      if isequal(result, false)
          tf = false;
      end
  end     
end












版权声明:本文为博主原创文章,未经博主允许不得转载。 举报

相关文章推荐

端口(二)-放在这查询

REGISTERED PORT NUMBERSThe Registered Ports are listed by the IANA and on most systems can beused by...

Problem1~10

社区里有不少project euler的题解,自己也写了些,主要是为了体验ruby的简洁(不过Mathematica好像更简单) 问题1:If

欢迎关注CSDN程序人生公众号

关注程序员生活,汇聚开发轶事。

DP10 0-1背包问题 0-1 Knapsack Problem @geeksforgeeks

01背包问题的取和不取实际上就是一个机会成本的问题,如果取了某件东西,尽管当前的价值暂时地增加了,但你付出了机会成本。因为如果不取,留下的空间以后说不定可以放更有价值的东西。因此空间和价值总是一对矛盾。我们的目的是要用有限的空间装入最优价值的东西。 Given weights and values of n items, put t

一份较心新的端口列表

PORT NUMBERS(last updated 18 November 2004) The port numbers are divided into three ranges: the Well...

The C10K problem

The C10K problem 转自:http://www.kegel.com/c10k.html <p style="font-family: 'Times New Roman'; fon
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)