Login

Welcome, Guest. Please login or register.

March 29, 2024, 12:22:22 am

Author Topic: SDD Algorithm Contest (ALCON) | Problem 3: Hairy Bottler  (Read 3705 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
SDD Algorithm Contest (ALCON) | Problem 3: Hairy Bottler
« on: May 13, 2018, 11:59:36 pm »
+3
<< Prev

ALCON PROBLEM 3:
HAIRY BOTTLER

It's been a month since we first launched ALCON, and it's been gaining interest rapidly. Problem 1 saw one entry; we've grown to 5 entries in Problem 2. That's fantastic news, and we're looking to expand on that in the future ;)

Week 2 asked you to write a program that allows Captain Spack Jarrow to look up details of crew members on the Pirate Log. The program had to output all of the details about that particular crew member.

There were five submissions. Huge congratulations to DrDusk and Jenna Chan on their perfect 7/7. Absolutely mental :o Everyone who submitted code has been listed on the leaderboard, so be sure to check back to find where you're currently sitting! If you've missed Problem 2, don't worry! You can always do them in your spare time and get feedback for your code.

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

Code: [Select]
BEGIN [u]Search_Log(piratesLog)[/u]
    Get query_type from user input
    CASEWHERE query_type is
        “name”: [u]searchName(piratesLog)[/u]
        “role”: [u]searchRole(piratesLog)[/u]
    ENDCASE
END [u]Search_Log[/u]

BEGIN [u]searchName(piratesLog)[/u]
    Get target from user input
    FOR i=1 TO piratesLog.length STEP 1
        IF piratesLog[i].name == target THEN
            PRINT piratesLog[i].name, piratesLog[i].role, piratesLog[i].age, piratesLog[i].mutiny
            i = piratesLog.length + 1
        ENDIF
    ENDFOR
END searchName

BEGIN [u]searchRole(piratesLog)[/u]
    Get target from user input
    FOR i=1 TO piratesLog.length STEP 1
        IF piratesLog[i].role == target THEN
            PRINT piratesLog[i].name, piratesLog[i].role, piratesLog[i].age, piratesLog[i].mutiny
            i = piratesLog.length + 1
        ENDIF
    ENDFOR
END [u]searchRole[/u]

Please make sure you've read the rules here.

Week 3 question:

Being able to manage a book of spells is Hairy Bottler’s job. But he doesn’t want to manually update them. Instead, Hairy outsources this job to you.

Luckily for you, Hermit Grunger has agreed to help-- she’s compiled a sequential file of all existing spells that contains the name of each spell followed by its use.

Write a program that searches through the file to determine if a given spell exists or not, and returns the correct use (e.g. if I search for “wingardium leviosa” it returns “levitation charm”).

Optional challenge add-on (+2 marks)
Modify the program so that Hairy can update the spellbook file with new spells.

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

Learning objectives for the week:

-> Reading and opening files.
-> Update files.
-> Close files.

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 28, 2018, 12:14:49 am by Opengangs »

JTrudeau

  • Trendsetter
  • **
  • Posts: 109
  • Master of the Meeses
  • Respect: +90
Re: SDD Algorithm Contest (ALCON) | Problem 3: Hairy Bottler
« Reply #1 on: May 14, 2018, 09:20:17 pm »
0
Just a question with this problem - quite obviously, reading/writing to a sequential file both require a sentinel value of some sort. However, in the process of writing to a sequential file, you'll need to specify what this sentinel is to know when to stop writing. If, then, you go to read from the file like in the searching component of this program, you will end up with a previous sentinel value somewhere in your file as well as the ones added in the write you just did. Is it safe to assume that, prior reading the file for a search, that any previous sentinel values are removed?

Hey anomalous! First off, congrats on first entry! Second, what a great question!!
While in real life, yes you would have to deal with the previous sentinel values, for the HSC, you can assume there is only one sentinel value and it is at the end of the file.

If you’d like to tackle the problem of previous sentinel values, we’d love to see it :) But it’s not needed at a high school level, so you’re in the clear.

Just a heads up to all— we’ve made a typo in the original question. The spellbook contains the name of a spell and it’s uses (not pronunciation). It shouldn’t affect the logic of your pseudo code, but just be aware. Thanks! :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

JTrudeau

  • Trendsetter
  • **
  • Posts: 109
  • Master of the Meeses
  • Respect: +90
Re: SDD Algorithm Contest (ALCON) | Problem 3: Hairy Bottler
« Reply #2 on: May 24, 2018, 08:13:20 am »
0
Bumping this post! We're still taking entries until Sunday! :)
C'mon, let's try and beat last week's record!!
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 3: Hairy Bottler
« Reply #3 on: May 25, 2018, 08:39:40 pm »
0
Code: [Select]
BEGIN SpellSearcher

OPEN spells.txt for input
READ Spells from spells.txt
SET Count to 1
SET foundSpell to false

WHILE Spells(Count) <= length of spells.txt and foundSpell == false DO
GET input
IF input == Spells(Count) THEN
DISPLAY Spells(Count).Use
foundSpell = true
ELSE
DISPLAY “Entered spell does not exist!”
END IF

INCREMENT Count by 1
END WHILE

CLOSE spells.txt

END SpellSearcher

BEGIN SpellAdder

OPEN spells.txt for output
READ Spells from spells.txt

DISPLAY “Enter the spell name.”
GET spellName
Spells(Length of spells.txt + 1) = spellName

DISPLAY “Enter the use of the spell.”
GET spellUse
Spells(Length of spells.txt + 1).Use = spellUse

CLOSE spells.txt

END SpellAdder


I'm not really sure how to correctly do this question, but I followed the method the HSC SDD textbook used.

Opengangs

  • New South Welsh
  • Forum Leader
  • ****
  • Posts: 718
  • \(\mathbb{O}_\mathbb{G}\)
  • Respect: +480
Re: SDD Algorithm Contest (ALCON) | Problem 3: Hairy Bottler
« Reply #4 on: May 28, 2018, 12:24:46 am »
0
ALCON WEEK 3 FEEDBACK

A bit disappointing with only two entries! Congrats on both fantastic entries - points have been awarded. 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 3'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 4's question.

Good luck everyone!