Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Bob task on Exercism

67 views
Skip to first unread message

Bruce Axtens

unread,
Jan 16, 2023, 4:04:40 AM1/16/23
to
I'm having a hard time finding some help on Exercism with this FORTRAN task.

The link to the task's mentoring portal is at https://exercism.org/mentoring/external_requests/a5e5ee1e-08d0-11ec-81c5-853579c25f94 if any can be bothered.

Alternatively, with respect to the code below I'm having difficulty with the following two tests:
! Test 18: silence
call assert_equal("Fine. Be that way!", hey(""), "silence")
! Test 19: prolonged silence
call assert_equal("Fine. Be that way!", hey(" "), "prolonged silence")

I can't figure out why the my is_silence doesn't work.

-- Bruce

module bob
implicit none

contains

function is_shouted(statement)
logical :: is_shouted
character (len=*), intent(in) :: statement

if (scan(statement,"ABCDEFGHIJKLMNOPQRSTUVWXYZ") .gt. 0) then
if (scan(statement,"abcdefgijklmnopqrstuvwxyz") .eq. 0) then
is_shouted = .TRUE.
return
end if
end if
is_shouted = .FALSE.
end function is_shouted

function is_question(statement)
logical :: is_question
character (len=*), intent(in) :: statement
character (len=len(statement)) :: temp
temp = trim(statement)
is_question = scan(temp, "?", .TRUE.) .eq. len(temp)
end function is_question

function is_silence(statement)
logical :: is_silence
character (len=*), intent(in) :: statement
is_silence = len(statement) .eq. 0
end function is_silence

function hey(statement)
character(100) :: hey
character(len=*), intent(in) :: statement
character(len(trim(statement))) :: trimmed_statement
trimmed_statement = trim(statement)
if (is_shouted(trimmed_statement)) then
if (is_question(trimmed_statement)) then
hey = "Calm down, I know what I'm doing!"
return
else
hey = "Whoa, chill out!"
return
end if
end if

if (is_question(trimmed_statement)) then
hey = "Sure."
return
end if

if (is_silence(trimmed_statement)) then
hey = "Fine. Be that way!"
return
end if

hey = "Whatever."
end function hey

end module bob

JRR

unread,
Jan 16, 2023, 8:20:30 AM1/16/23
to
On 1/16/23 10:04, Bruce Axtens wrote:
> I'm having a hard time finding some help on Exercism with this FORTRAN task.
>
> The link to the task's mentoring portal is at https://exercism.org/mentoring/external_requests/a5e5ee1e-08d0-11ec-81c5-853579c25f94 if any can be bothered.
>
> Alternatively, with respect to the code below I'm having difficulty with the following two tests:
> ! Test 18: silence
> call assert_equal("Fine. Be that way!", hey(""), "silence")
> ! Test 19: prolonged silence
> call assert_equal("Fine. Be that way!", hey(" "), "prolonged silence")
>
> I can't figure out why the my is_silence doesn't work.
>

'Doesn't work' is not a very precise statement because an outsider
cannot know what you expected the is_silence function to do, nor what
you found it to do.
So I can only speculate: e.g. Metcalf/Reid, Modern
Fortran explained, Sec. 9.6.3, says
scan (string, set [,kind]) returns an integer whose value is the
position of a character of string that is in set, or zero if there is
no such character. Probably you confused the two arguments of scan.
In any case you input trimmed spaces to the first argument, which is the
empty character. Per definition, this is not contained in "?", so get
zero and your is_question function returns "Sure."

> -- Bruce
>


--
Juergen Reuter
Theoretical Particle Physics
Deutsches Elektronen-Synchrotron
Hamburg, Germany
---------------------------------
invalid is desy .and. com is de

Bruce Axtens

unread,
Jan 17, 2023, 9:14:38 AM1/17/23
to
On Monday, 16 January 2023 at 9:20:30 pm UTC+8, JRR wrote:
> On 1/16/23 10:04, Bruce Axtens wrote:
> 'Doesn't work' is not a very precise statement because an outsider

Ah, yes, that is not exactly helpful.

Nevertheless, thank you for your patience.

Bruce
0 new messages