Login

Welcome, Guest. Please login or register.

March 29, 2024, 07:43:32 pm

Author Topic: SDD Algorithm Contest (ALCON) | Problem 2: Captain Spack Jarrow  (Read 4167 times)  Share 

0 Members and 1 Guest are viewing this topic.

Opengangs

  • New South Welsh
  • Forum Leader
  • ****
  • Posts: 718
  • \(\mathbb{O}_\mathbb{G}\)
  • Respect: +480
+6
<< Prev

ALCON PROBLEM 2:
CAPTAIN SPACK JARROW

Congratulations on making it past the first week's problem - it was tough! But we got there. Before we reveal the problem for this fortnight, a quick recap on Week 1's problem and sample solution.

Week 1 asked you to write a program that inputs a fabric given three options. The program should print the largest number of rolls AND the fabric.

There was one submission, so congratulations to anomalous for the wonderful submission. They've earned points and will be listed on the leaderboard. Remember, if you missed a problem, then you can still participate in that contest to help aid you for your exams. We will help lead you in the right direction from time to time.

Sample answer:
(note [u ][/u] tags mean that the code was underlined.)

Code: [Select]
BEGIN MAINPROGRAM
    plain = 0
    striped = 0
    dotted = 0
    fabric = INPUT(“Enter the name of the fabric type: “)

    WHILE Fabric != “done” DO
        CASEWHERE fabric is
            “plain”: INCREMENT plain
            “striped”: INCREMENT striped
            “dotted”: INCREMENT dotted
        END CASE

    fabric = INPUT(“Enter the name of the next fabric type: ”)
    ENDWHILE

    [u]Find_Largest(plain, striped, dotted)[/u]
END MAINPROGRAM

#This is for the main question-- assumes only one solution

BEGIN [u]Find_Largest(plain, striped, dotted)[/u]
    CASEWHERE
        Plain > striped AND plain > dotted: PRINT(plain, “plain”)
        Striped > plain AND striped > dotted: PRINT(striped, “Striped”)
        Dotted > striped AND dotted > plain: PRINT(dotted, “dotted)
        OTHERWISE: [u]Call_Challenge(plain, striped, dotted)[/u]
    ENDCASE
END [u]Find_Largest[/u]

#Challenge answer-- you know it’s multiple answers, so it’s either all three or a pair

BEGIN [u]Call_Challenge(plain, striped, dotted)[/u]
    IF plain == striped AND plain == dotted THEN
        PRINT(plain, “plain, striped, and dotted”)
    ELSE
        CASEWHERE
            Plain == striped: PRINT(plain, “plain and striped”)
            Plain == dotted: PRINT(plain, “plain and dotted”)
            Striped = dotted: PRINT(striped, “striped and dotted”)
        ENDCASE
ENDIF
END [u]Call_Challenge(plain, striped, dotted)[/u]

Please make sure you've read the rules here.

Week 2 question:

Running a ship takes a lot of crew members, and each of them have a designated role on the ship. E.g. the boatswain (bosun) is in charge of equipment and crew, the coxswain is in charge of the navigation, etc.

Captain Spack Jarrow wants to keep track of all personnel on his ship in what he calls “the Pirate’s Log” (i.e. a database of some sort).

Write a program that allows him to look up the details of a crew member on the Pirate’s Log, meeting the following specifications:

He can search for crew members by name.
Each crew member has a name, a role, an age, and a “mutiny meter” (“low”, “medium”, or “high”, depending on how likely the crew member will commit mutiny)
Once given a name, the program will search and output all the details about that particular crew member (name, role, age, and mutiny meter)

Assume the common sailor roles are numbered so each role name is unique- e.g. sailor1, sailor2, etc. Names are also unique.

Optional challenge add on (+2 marks)
Modify the program to allow Captain Jarrow to search by either name or role.

You’ll be marked on correctness, efficiency, and defensive programming.

Learning objectives for the week:

-> Arrays
-> Loops and searches
-> Records and fields

Marking guidelines

Don't forget to login or register an account to submit your answer!

Good luck, and as always, happy algorithming!
« Last Edit: May 14, 2018, 12:00:29 am by Opengangs »

DrDusk

  • NSW MVP - 2019
  • Forum Leader
  • ****
  • Posts: 504
  • Respect: +130
Re: SDD Algorithm Contest (ALCON) | Problem 2: Captain Spack Jarrow
« Reply #1 on: April 30, 2018, 10:49:53 pm »
+3
Code: [Select]
[b]Main Program:[/b]
BEGIN SEARCH
        Define PirateLog as an Array of Records
        INPUT Name
        FOR i = 1 TO Length of PirateLog
                IF PirateLog(i).Name = Name
                        PRINT PirateLog(i).Name
                        PRINT PirateLog(i).Role   
                        PRINT PirateLog(i).Age
                        PRINT PirateLog(i).MutinyMeter
               ENDIF
        NEXT i
END SEARCH
[b]Challenge[/b]
BEGIN SEARCH
        Define PirateLog as an Array of Records
        INPUT Name OR INPUT Role
        FOR i = 1 TO Length of PirateLog 
                IF PirateLog(i).Name = Name
                        PRINT PirateLog(i).Name
                        PRINT PirateLog(i).Role   
                        PRINT PirateLog(i).Age
                        PRINT PirateLog(i).MutinyMeter   
                ELSE
                        IF PirateLog(i).Role = Role 
                                  PRINT PirateLog(i).Name
                                  PRINT PirateLog(i).Role   
                                  PRINT PirateLog(i).Age
                                  PRINT PirateLog(i).MutinyMeter   
                        ENDIF
                ENDIF
        NEXT i
END SEARCH

Mod edit: Formatting - thanks for the submission! ;D

« Last Edit: May 01, 2018, 12:15:38 am by DrDusk »

JTrudeau

  • Trendsetter
  • **
  • Posts: 109
  • Master of the Meeses
  • Respect: +90
Re: SDD Algorithm Contest (ALCON) | Problem 2: Captain Spack Jarrow
« Reply #2 on: May 01, 2018, 11:18:50 am »
+1
Hey DrDusk-- welcome to ATARNotes! Thanks for your entry (first submission WOO!). Please check back at the end of next week for feedback and scoring.
In the meantime, feel free to hang around and check out the forums, articles, and notes we have to offer. There are a ton of great resources for Software and any other subjects that you do :D
Data Science, Finance || University of Sydney
== First in State for Software Design and Development 2017 ==
Advanced English | Maths Extension 1 | Maths Extension 2 | Economics | Software Design & Development | Chemistry

Jenna Chan

  • Fresh Poster
  • *
  • Posts: 1
  • Respect: 0
Re: SDD Algorithm Contest (ALCON) | Problem 2: Captain Spack Jarrow
« Reply #3 on: May 02, 2018, 07:03:09 pm »
+1
Spoiler
Code: [Select]

BEGIN
    GET name
    GET role
    index = 1
    FOR index = 1 To length(thePirate'sLog)
        IF name = thePirate'sLog(index).name OR role = thePirate'sLog(index).role THEN
            PRINT thePirate'sLog(index).name
            PRINT thePirate'sLog(index).role
            PRINT thePirate'sLog(index).age
            PRINT thePirate'sLog(index).mutinyMeter
        ENDIF
    NEXT index
END


jasn9776

  • Forum Regular
  • **
  • Posts: 57
  • Respect: +4
Re: SDD Algorithm Contest (ALCON) | Problem 2: Captain Spack Jarrow
« Reply #4 on: May 06, 2018, 09:37:38 pm »
+2
Code: [Select]
Pirates_log = {Sailor1, Sailor2, Sailor3, Sailor4...SailorX}
SailorX = [NameX, RoleX, AgeX, MutinylevelX]

READ searchvalue
For i to 0 to length of pirates_log -1 {assuming 0-index}
    IF searchvalue =  Pirates_log(i)(0) THEN
        PRINT "Name:" Pirates_log(i)(0)
        PRINT "Role:" Pirate_log(i)(1)
        PRINT "Age:" Pirate_log(i)(2)
        PRINT "Mutinylevel:" Pirate_log(i)(2)
    ENDIF
Next i


Mod edit: Formatting.
« Last Edit: May 06, 2018, 09:38:37 pm by Opengangs »
HSC 2018: English Adv(88) | Bio (90) | Phys(85) | Software Design (87) | 3U Math (41)

cthulu

  • Trailblazer
  • *
  • Posts: 35
  • Respect: +1
Re: SDD Algorithm Contest (ALCON) | Problem 2: Captain Spack Jarrow
« Reply #5 on: May 07, 2018, 06:00:52 pm »
+1
Code: [Select]
            BEGIN MainProgram
                SET count to 0
                GET userInput
                   
                WHILE count < max number of items in piratesLog array DO
                    IF userInput is equal to piratesLog(count).Name or piratesLog(count).Role THEN
                        DISPLAY "Name: " + piratesLog(count).Name
                        DISPLAY "Role: " + piratesLog(count).Role
                        DISPLAY "Age: " + piratesLog(count).Age
                        DISPLAY "Mutiny level: " + piratesLog(count).MutinyLevel
                    ELSE
                        DISPLAY "Input is invalid. Please enter a valid name or role!"
                    END IF
                   
                    ADD 1 to count
                END WHILE
            END MainProgram

Hi, just a query, we don't need to define an array in this as if we did there would be no content about the crewmen and hence the search wouldn't return anything. Normally in a question like this an array is already given in the question and we have to use that in our solution.

Thanks
« Last Edit: May 07, 2018, 06:04:29 pm by cthulu »

Opengangs

  • New South Welsh
  • Forum Leader
  • ****
  • Posts: 718
  • \(\mathbb{O}_\mathbb{G}\)
  • Respect: +480
Re: SDD Algorithm Contest (ALCON) | Problem 2: Captain Spack Jarrow
« Reply #6 on: May 09, 2018, 11:06:49 am »
+1
Hi, just a query, we don't need to define an array in this as if we did there would be no content about the crewmen and hence the search wouldn't return anything. Normally in a question like this an array is already given in the question and we have to use that in our solution.

Thanks
Hey there!

Thanks for a submission - you're awesome! :) Normally, in the HSC, the array is already defined for you so no need to redefine it. :)

JTrudeau

  • Trendsetter
  • **
  • Posts: 109
  • Master of the Meeses
  • Respect: +90
Re: SDD Algorithm Contest (ALCON) | Problem 2: Captain Spack Jarrow
« Reply #7 on: May 09, 2018, 11:13:43 am »
+1
Hey there!

Thanks for a submission - you're awesome! :) Normally, in the HSC, the array is already defined for you so no need to redefine it. :)

Adding on— what you can do to give a heads up to the marker is input the array as a parameter!
E.g. BEGIN Search(array)
And then use the array how you’d use it normally.
Data Science, Finance || University of Sydney
== First in State for Software Design and Development 2017 ==
Advanced English | Maths Extension 1 | Maths Extension 2 | Economics | Software Design & Development | Chemistry

cthulu

  • Trailblazer
  • *
  • Posts: 35
  • Respect: +1
Re: SDD Algorithm Contest (ALCON) | Problem 2: Captain Spack Jarrow
« Reply #8 on: May 13, 2018, 03:54:36 pm »
0
Adding on— what you can do to give a heads up to the marker is input the array as a parameter!
E.g. BEGIN Search(array)
And then use the array how you’d use it normally.

Hey thanks for the response, is this required in the HSC? I did it in my half yearly test but my teacher crossed it out.

JTrudeau

  • Trendsetter
  • **
  • Posts: 109
  • Master of the Meeses
  • Respect: +90
Re: SDD Algorithm Contest (ALCON) | Problem 2: Captain Spack Jarrow
« Reply #9 on: May 13, 2018, 06:02:14 pm »
0
Hey thanks for the response, is this required in the HSC? I did it in my half yearly test but my teacher crossed it out.

You can definitely get the marks without doing it, but I like to incorporate the array into my algorithms that way to show that I know how subprograms work (just make sure the parameter has an intuitive name-- e.g. piratesLog). Shouldn't make much of a difference. Hope this helps! :)
Data Science, Finance || University of Sydney
== First in State for Software Design and Development 2017 ==
Advanced English | Maths Extension 1 | Maths Extension 2 | Economics | Software Design & Development | Chemistry

DrDusk

  • NSW MVP - 2019
  • Forum Leader
  • ****
  • Posts: 504
  • Respect: +130
Re: SDD Algorithm Contest (ALCON) | Problem 2: Captain Spack Jarrow
« Reply #10 on: May 13, 2018, 06:50:22 pm »
0
Hey thanks for the response, is this required in the HSC? I did it in my half yearly test but my teacher crossed it out.
Bro u declared a two dimensional array when the question already gave you one and you didnt need to LOL ;D ;D ;D

Opengangs

  • New South Welsh
  • Forum Leader
  • ****
  • Posts: 718
  • \(\mathbb{O}_\mathbb{G}\)
  • Respect: +480
Re: SDD Algorithm Contest (ALCON) | Problem 2: Captain Spack Jarrow
« Reply #11 on: May 14, 2018, 12:06:05 am »
+2
ALCON WEEK 2 FEEDBACK

There were two perfect scores, so really great job to DrDusk and Jenna Chan. Remember there are heaps more problems coming up in the future, so make sure you register to take part in the contest!

Everything you need for Week 2's problem can be found here. You can find your own entry and read the comments and feedback.

In the meantime, don't forget to check out Week 3's question.

Good luck everyone!