create account

RE: Introducing the Coding Challenge by reggaemuffin

View this thread on: hive.blogpeakd.comecency.com

Viewing a response to: @philosophist/re-reggaemuffin-introducing-the-coding-challenge-20170817t191654393z

· @reggaemuffin ·
Interesting choice :) I like your solution.

String compare will probably be a lot slower than doing the reminder again, but if it is an optimized strcmp it will still be pretty fast. 

Be sure to check a few other solutions and give feedback :)
properties (22)
authorreggaemuffin
permlinkre-philosophist-re-reggaemuffin-introducing-the-coding-challenge-20170817t193456828z
categorycoding-challenge
json_metadata{"tags":["coding-challenge"],"app":"steemit/0.1"}
created2017-08-17 19:35:00
last_update2017-08-17 19:35:00
depth2
children4
last_payout2017-08-24 19:35:00
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length245
author_reputation37,964,839,695,531
root_title"Introducing the Coding Challenge"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id12,114,069
net_rshares0
@philosophist · (edited)
Good point. This should be more optimized. New variable 'neither' is a boolean set to true initially and set to false if n is either divisible by 3, 5, or both. Then that becomes the check for if neither is the case.
```
function output = fizzbuzz(n)
% fizzbuzz(n) returns 'Fizz' if n is a multiple of 3, 
% 'Buzz' if n is a multiple of 5, 'FizzBuzz' if n is a 
% multiple of 5 and 3, and returns n if it is neither a 
% multiple of 3 or 5.
% Format of Call: fizzbuzz(n);
% Returns: output = 'Fizz', 'Buzz', 'FizzBuzz', or n 
% based on if n is a multiple of 3 or 5
    
    if ~isnumeric(n)
        error('Error: Input must be a number, not a %s.',class(n));
    else
        neither = true;
        output = '';
        if rem(n,3) == 0
            output = 'Fizz';
            neither = false;
        end
        if rem(n,5) == 0
            output = strcat(output,'Buzz');
            neither = false;
        end
        if neither
            output = num2str(n);
        end
    end
```
properties (22)
authorphilosophist
permlinkre-reggaemuffin-re-philosophist-re-reggaemuffin-introducing-the-coding-challenge-20170818t013330149z
categorycoding-challenge
json_metadata{"tags":["coding-challenge"],"app":"steemit/0.1"}
created2017-08-18 01:33:30
last_update2017-08-18 01:36:27
depth3
children3
last_payout2017-08-25 01:33:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length994
author_reputation1,642,759,591,030
root_title"Introducing the Coding Challenge"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id12,134,774
net_rshares0
@reggaemuffin ·
That is a good idea! Nice improvement, this is worth a tip!
properties (22)
authorreggaemuffin
permlinkre-philosophist-re-reggaemuffin-re-philosophist-re-reggaemuffin-introducing-the-coding-challenge-20170818t052705282z
categorycoding-challenge
json_metadata{"tags":["coding-challenge"],"app":"steemit/0.1"}
created2017-08-18 05:27:06
last_update2017-08-18 05:27:06
depth4
children1
last_payout2017-08-25 05:27:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length59
author_reputation37,964,839,695,531
root_title"Introducing the Coding Challenge"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id12,147,251
net_rshares0
@philosophist ·
Thanks bud! Much appreciated.
properties (22)
authorphilosophist
permlinkre-reggaemuffin-re-philosophist-re-reggaemuffin-re-philosophist-re-reggaemuffin-introducing-the-coding-challenge-20170818t055825025z
categorycoding-challenge
json_metadata{"tags":["coding-challenge"],"app":"steemit/0.1"}
created2017-08-18 05:58:24
last_update2017-08-18 05:58:24
depth5
children0
last_payout2017-08-25 05:58:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length29
author_reputation1,642,759,591,030
root_title"Introducing the Coding Challenge"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id12,148,732
net_rshares0
@tipu ·
<table><tr><td>http://i.imgur.com/IFF4CSc.jpg</td><td><p>Hi @philosophist! You have just received a 0.5 SBD tip from @reggaemuffin!</p><p><strong>From @reggaemuffin : <a href=https://steemit.com/witness-category/@reggaemuffin/witness-reggaemuffin rel="noopener"> If You Like What I Do, Vote Me For Witness :)</a></strong></p></td></tr></table><hr><p><a href="https://steemit.com/steemit/@tipu/tipu-quick-guide" rel="noopener">@tipU - send tips by writing tip! in the comment and get share in service profit :)</a></p>
properties (22)
authortipu
permlinkre-re-reggaemuffin-re-philosophist-re-reggaemuffin-introducing-the-coding-challenge-20170818t013330149z-20170818t052721
categorycoding-challenge
json_metadata""
created2017-08-18 05:27:21
last_update2017-08-18 05:27:21
depth4
children0
last_payout2017-08-25 05:27:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length517
author_reputation55,914,546,531,008
root_title"Introducing the Coding Challenge"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id12,147,271
net_rshares0