Test | Status | Code Input and Output |
---|---|---|
1 | Fail |
filetext = fileread('divisible_by_2.m');
assert(isempty(strfind(filetext, '*')),'* forbidden')
assert(isempty(strfind(filetext, 'mtimes')),'mtimes() forbidden')
assert(isempty(strfind(filetext, 'cross')),'cross() forbidden')
assert(isempty(strfind(filetext, 'prod')),'prod() forbidden')
assert(isempty(strfind(filetext, 'cumprod')),'cumprod() forbidden')
assert(isempty(strfind(filetext, 'times')),'times() forbidden')
assert(isempty(strfind(filetext, 'mldivide')),'mldivide() forbidden')
assert(isempty(strfind(filetext, 'mrdivide')),'mrdivide() forbidden')
assert(isempty(strfind(filetext, '/')),'/ forbidden')
assert(isempty(strfind(filetext, '\')),'\ forbidden')
assert(isempty(strfind(filetext, '^')),'^ forbidden')
assert(isempty(strfind(filetext, 'dot')),'dot() forbidden')
assert(isempty(strfind(filetext, 'rem')),'rem() forbidden')
assert(isempty(strfind(filetext, 'mod')),'mod() forbidden')
assert(isempty(strfind(filetext, 'factor')),'factor() forbidden')
assert(isempty(strfind(filetext, 'round')),'round() forbidden')
assert(isempty(strfind(filetext, 'ceil')),'ceil() forbidden')
assert(isempty(strfind(filetext, 'floor')),'floor() forbidden')
assert(isempty(strfind(filetext, 'java')),'java forbidden')
|
2 | Fail |
n_str = '12';
assert(isequal(divisible_by_2(n_str),1))
a =
1 0
|
3 | Pass |
n_str = '13';
assert(isequal(divisible_by_2(n_str),0))
a =
1 1
|
4 | Pass |
n_str = '222';
assert(isequal(divisible_by_2(n_str),1))
a =
0 0 0
|
5 | Fail |
n_str = '232';
assert(isequal(divisible_by_2(n_str),1))
a =
0 1 0
|
6 | Pass |
n_str = '223';
assert(isequal(divisible_by_2(n_str),0))
a =
0 0 1
|
7 | Pass |
n_str = '1236127';
assert(isequal(divisible_by_2(n_str),0))
a =
1 0 1 0 1 0 1
|
8 | Fail |
n_str = '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';
assert(isequal(divisible_by_2(n_str),1))
a =
Columns 1 through 29
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
Columns 30 through 58
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
Columns 59 through 87
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
Columns 88 through 116
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
Columns 117 through 145
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
Columns 146 through 174
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
Columns 175 through 180
1 0 1 0 1 0
|
9 | Pass |
n_str = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901';
assert(isequal(divisible_by_2(n_str),0))
a =
Columns 1 through 29
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
Columns 30 through 58
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
Columns 59 through 87
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
Columns 88 through 116
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
Columns 117 through 145
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
Columns 146 through 174
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
Columns 175 through 181
1 0 1 0 1 0 1
|
10 | Fail |
n_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
assert(isequal(divisible_by_2(n_str),1))
a =
Columns 1 through 29
1 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 30 through 58
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 59 through 87
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 88 through 116
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 117 through 145
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 146 through 174
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 175 through 203
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 204 through 207
0 0 0 0
|
11 | Pass |
n_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';
assert(isequal(divisible_by_2(n_str),0))
a =
Columns 1 through 29
1 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 30 through 58
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 59 through 87
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 88 through 116
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 117 through 145
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 146 through 174
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 175 through 203
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 204 through 207
0 0 0 1
|
12 | Fail |
n_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922796';
assert(isequal(divisible_by_2(n_str),1))
a =
Columns 1 through 29
1 1 0 1 1 1 0 0 1 1 1 0 1 1 1 1 0 1 0 0 0 0 0 0 1 1 0 1 0
Columns 30 through 58
1 1 1 0 0 0 0 0 1 1 1 1 0 1 1 1 1 1 1 1 1 0 1 0 0 0 1 1 0
Columns 59 through 87
1 0 0 1 1 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 1
Columns 88 through 116
0 0 0 1 1 0 0 1 1 1 0 0 1 1 0 0 1 0 0 0 0 0 1 1 1 0 0 0 1
Columns 117 through 145
0 0 0 0 1 0 1 1 0 0 0 0 0 1 1 1 0 1 0 0 0 1 1 1 0 1 1 1 1
Columns 146 through 174
0 0 0 1 0 0 0 0 1 1 1 1 0 1 0 0 0 0 1 0 0 1 0 1 1 1 0 1 0
Columns 175 through 203
1 1 0 1 1 1 1 0 0 0 0 0 0 1 0 0 1 1 0 1 1 0 1 0 1 1 0 0 0
Columns 204 through 232
0 0 0 1 0 1 1 1 0 0 1 1 1 1 0 0 0 1 0 0 0 1 1 0 0 0 0 1 1
Columns 233 through 261
1 0 0 1 0 1 1 0 1 0 1 1 0 0 1 1 0 1 1 0 1 0 0 0 1 0 0 1 0
Columns 262 through 290
1 0 0 0 1 0 0 0 1 0 0 1 0 1 0 0 0 0 0 0 1 1 1 1 1 0 0 1 0
Columns 291 through 319
0 0 0 0 1 1 0 1 0 1 1 1 0 0 1 0 1 0 0 0 0 0 0 1 1 1 1 0 0
Columns 320 through 348
1 1 0 0 0 1 1 0 0 1 0 0 1 0 0 0 0 1 0 1 0 0 1 1 1 1 1 1 0
Columns 349 through 377
0 1 0 1 0 1 0 1 1 0 1 0 0 0 1 1 1 1 0 1 1 0 1 0 0 0 0 0 0
Columns 378 through 406
0 0 1 0 1 1 0 0 1 0 0 1 1 1 1 0 1 1 1 1 0 0 1 0 1 1 0 1 1
Columns 407 through 435
0 1 0 1 0 1 1 1 1 1 1 1 1 1 1 0 1 0 1 0 0 1 1 1 1 0 1 1 1
Columns 436 through 464
0 0 1 1 1 1 1 1 0 1 1 1 0 1 0 0 0 1 0 0 0 0 1 1 1 1 0 0 1
Columns 465 through 493
0 1 1 0 1 1 1 1 0 0 1 1 1 0 1 0 0 0 1 1 0 0 1 1 1 0 1 0 1
Columns 494 through 522
0 1 1 1 0 1 1 0 1 0 1 1 0 1 1 1 0 0 0 0 0 0 1 0 0 0 1 0 0
Columns 523 through 551
0 0 0 1 1 1 0 1 0 0 1 1 1 0 0 0 1 1 1 1 1 0 1 0 0 1 1 1 0
Columns 552 through 580
0 0 1 0 1 1 0 0 1 1 0 1 1 1 0 1 1 1 1 0 0 1 1 1 1 0 1 1 0
Columns 581 through 609
1 0 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 1 1 0 0 0 0 1 0 0 1 0
Columns 610 through 638
1 1 0 1 0 0 1 1 0 0 0 0 1 1 0 1 1 1 1 1 0 0 1 1 1 1 0 1 0
Columns 639 through 667
0 1 1 1 1 0 1 1 1 1 0 1 0 1 0 0 0 0 0 0 1 0 1 0 0 0 1 1 1
Columns 668 through 696
0 1 0 1 0 0 1 0 1 1 0 1 1 1 1 0 1 0 1 1 0 0 1 1 0 0 1 0 1
Columns 697 through 725
0 1 0 1 1 0 0 0 1 1 1 1 0 1 1 0 1 0 1 0 0 1 1 0 0 0 0 0 0
Columns 726 through 754
1 0 0 1 0 1 1 1 0 1 1 0 0 1 1 1 0 1 1 1 1 0 1 1 0 0 1 1 0
Columns 755 through 783
1 0 1 0 1 1 1 0 1 1 1 1 1 1 0 1 1 0 1 1 0 0 0 1 1 1 1 0 1
Columns 784 through 812
1 1 1 1 1 1 0 0 1 0 0 1 0 1 1 0 1 1 1 0 0 0 0 1 1 0 1 1 1
Columns 813 through 841
0 0 1 0 0 1 0 0 0 0 0 1 0 0 1 0 0 0 1 1 1 0 0 0 0 1 0 1 1
Columns 842 through 870
0 0 1 1 1 1 1 0 0 1 1 1 0 1 0 0 0 1 1 1 1 0 1 0 1 1 0 0 0
Columns 871 through 899
0 1 0 1 1 1 1 0 0 0 1 0 1 0 0 0 0 1 1 1 1 1 0 0 1 1 0 1 1
Columns 900 through 928
0 1 1 1 0 0 1 1 0 1 0 0 0 0 1 1 1 0 0 0 1 1 1 1 1 1 1 0 0
Columns 929 through 957
0 0 1 0 0 0 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 1 1 0
Columns 958 through 986
0 1 1 0 1 1 1 0 0 0 0 0 0 0 1 1 0 0 1 1 0 1 0 1 0 0 1 1 1
Columns 987 through 1,015
1 1 1 0 1 0 1 0 0 0 0 1 1 0 1 1 0 0 1 1 0 1 1 0 0 1 0 0 1
Columns 1,016 through 1,044
0 0 1 0 0 1 0 1 0 0 0 1 1 1 0 1 1 1 1 0 1 0 0 1 1 0 0 0 1
Columns 1,045 through 1,073
0 1 0 1 1 1 0 0 1 1 1 0 1 0 1 0 1 0 0 1 1 1 1 1 1 0 0 0 1
Columns 1,074 through 1,102
1 1 0 1 1 0 1 1 0 0 1 1 0 1 1 1 1 0 0 1 0 1 1 1 1 1 1 1 1
Columns 1,103 through 1,131
1 1 0 0 1 1 0 0 0 0 1 0 1 1 0 0 1 1 1 1 0 0 0 1 1 1 1 1 1
Columns 1,132 through 1,160
0 0 0 1 1 0 1 0 1 1 0 0 1 0 1 1 0 1 0 1 0 1 1 1 0 0 1 1 0
Columns 1,161 through 1,189
0 0 1 1 1 1 1 1 0 1 1 0 0 0 0 0 0 1 0 1 1 0 1 0 1 1 1 1 1
Columns 1,190 through 1,218
0 0 1 0 0 0 0 0 0 0 1 0 0 1 0 1 0 1 0 0 1 1 0 1 1 0 1 0 0
Columns 1,219 through 1,247
0 1 0 0 1 1 0 1 0 1 1 0 0 1 1 1 1 1 0 1 1 0 1 0 0 1 0 1 0
Columns 1,248 through 1,276
1 1 0 0 1 0 0 0 0 1 1 1 1 1 1 1 0 1 0 0 0 0 1 1 0 0 0 0 1
Columns 1,277 through 1,305
1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 0 1 1 0 1 1 1 1
Columns 1,306 through 1,334
1 0 1 1 0 0 0 1 0 1 1 1 0 1 0 0 1 1 0 1 0 0 0 1 0 1 0 0 0
Columns 1,335 through 1,363
0 0 0 1 0 0 1 0 1 1 0 1 1 1 1 1 1 0 1 1 1 0 0 0 1 0 0 1 1
Columns 1,364 through 1,392
1 0 1 0 0 0 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 1 1 1 0 1 0 0 0
Columns 1,393 through 1,402
0 0 0 1 1 0 0 1 1 0
|
13 | Pass |
n_str = '1010010101011010101001011010100101101010010100101101010011010100101';
assert(isequal(divisible_by_2(n_str),0))
a =
Columns 1 through 29
1 0 1 0 0 1 0 1 0 1 0 1 1 0 1 0 1 0 1 0 0 1 0 1 1 0 1 0 1
Columns 30 through 58
0 0 1 0 1 1 0 1 0 1 0 0 1 0 1 0 0 1 0 1 1 0 1 0 1 0 0 1 1
Columns 59 through 67
0 1 0 1 0 0 1 0 1
|
14 | Pass |
ind = randi(4);
switch ind
case 1
n_str = '222';
assert(isequal(divisible_by_2(n_str),1))
case 2
n_str = '1010010101011010101001011010100101101010010100101101010011010100101';
assert(isequal(divisible_by_2(n_str),0))
case 3
n_str = '1236127';
assert(isequal(divisible_by_2(n_str),0))
case 4
n_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
assert(isequal(divisible_by_2(n_str),1))
end
a =
Columns 1 through 29
1 0 1 0 0 1 0 1 0 1 0 1 1 0 1 0 1 0 1 0 0 1 0 1 1 0 1 0 1
Columns 30 through 58
0 0 1 0 1 1 0 1 0 1 0 0 1 0 1 0 0 1 0 1 1 0 1 0 1 0 0 1 1
Columns 59 through 67
0 1 0 1 0 0 1 0 1
|
15 | Fail |
ind = randi(4);
switch ind
case 1
n_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
assert(isequal(divisible_by_2(n_str),1))
case 2
n_str = '12';
assert(isequal(divisible_by_2(n_str),1))
case 3
n_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';
assert(isequal(divisible_by_2(n_str),0))
case 4
n_str = '223';
assert(isequal(divisible_by_2(n_str),0))
end
a =
1 0
|
16 | Pass |
ind = randi(4);
switch ind
case 1
n_str = '1236127';
assert(isequal(divisible_by_2(n_str),0))
case 2
n_str = '123678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';
assert(isequal(divisible_by_2(n_str),0))
case 3
n_str = '222';
assert(isequal(divisible_by_2(n_str),1))
case 4
n_str = '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922796';
assert(isequal(divisible_by_2(n_str),1))
end
a =
Columns 1 through 29
1 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 30 through 58
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 59 through 87
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 88 through 116
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 117 through 145
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 146 through 174
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 175 through 203
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 204 through 207
0 0 0 1
|
404 Solvers
856 Solvers
Relative ratio of "1" in binary number
392 Solvers
ベクトル [1 2 3 4 5 6 7 8 9 10] の作成
292 Solvers
215 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!