Code Signal_练习题_chessBoardCellColor

Given two cells on the standard chess board, determine whether they have the same color or not.

Example

  • For cell1 = "A1" and cell2 = "C3", the output should be
    chessBoardCellColor(cell1, cell2) = true.

  • For cell1 = "A1" and cell2 = "H3", the output should be
    chessBoardCellColor(cell1, cell2) = false.

 

我的解答:

def chessBoardCellColor(cell1, cell2):
    return abs(int(cell1[1])-int(cell2[1])) % 2 == 0 if abs(ord(cell1[0]) - ord(cell2[0])) % 2 == 0 else abs(int(cell1[1])-int(cell2[1])) % 2 == 1

 

 

def chessBoardCellColor(cell1, cell2):
    return (ord(cell1[0]) + int(cell1[1]) + ord(cell2[0]) + int(cell2[1])) % 2 == 0
膜拜大佬

 

转载于:https://www.cnblogs.com/BlameKidd/p/9470514.html

当然,这是一个生成信号的函,它可以生成一个包含载波和码元的复合信号。以下是一个可能的实现: ```matlab function signal_r = signal_gen(fsample, f_carrier, f_code, code_phase_init, dBW_signal_pow, dB_C_I, dot_num) % Inputs: % - fsample: 采样频率 % - f_carrier: 载波频率 % - f_code: 码元频率 % - code_phase_init: 码元初始相位 % - dBW_signal_pow: 信号功率 % - dB_C_I: 载波与干扰的功率比 % - dot_num: 码元个 % Output: % - signal_r: 生成的信号 % 计算采样间隔 T = 1/fsample; % 计算码元时长 T_code = 1/f_code; % 生成时间轴 t = (0:T:(dot_num-1)*T_code)'; % 生成码元 code = sign(sin(2*pi*f_code*t + code_phase_init)); % 生成带有干扰的载波 carrier = sqrt(10^(dBW_signal_pow/10)) * cos(2*pi*f_carrier*t) ... + sqrt(10^((dBW_signal_pow-dB_C_I)/10)) * randn(size(t)); % 生成复合信号 signal_r = carrier .* code; ``` 这个函中,我们首先计算了采样间隔 $T$,然后根据码元频率 $f_\text{code}$ 计算了码元时长 $T_\text{code}$。然后,我们生成了时间轴 $t$,包含了所有的采样点。接着,我们生成了码元信号 $code$,使用了 sign 函将正弦波转换为方波。然后,我们生成了带有干扰的载波 $carrier$,其中信号功率 $P_\text{signal}$ 的 dB 值为 $dBW_\text{signal\_pow}$,干扰功率 $P_\text{interference}$ 的 dB 值为 $dB_\text{C_I}$,并且使用 randn 函生成了一个高斯白噪声序列,其功率为 $P_\text{interference}$。最后,我们生成了复合信号 $signal_r$,其为载波和码元信号的乘积。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值