August 09, 2020, 03:15:36 pm

### AuthorTopic: SDD Algorithm Contest (ALCON) | Problem 3: Hairy Bottler  (Read 2513 times) Tweet Share

0 Members and 1 Guest are viewing this topic.

#### Opengangs

• New South Welsh
• Posts: 696
• $\mathbb{O}_\mathbb{G}$
• Respect: +450
##### 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 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.

(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]    ENDCASEEND [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    ENDFOREND searchNameBEGIN [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    ENDFOREND [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 »
[2017: HSC]
English (Adv): 86 $\mid$ Mathematics (Adv): 94 $\mid$ Mathematics (Extension 1): 45 $\mid$ Biology: 84 $\mid$ Business Studies: 87 $\mid$ Software Design and Development: 88

[2018 $-$ 2022: UNSW]
Degree: Bachelor of Science (Computer Science) / Bachelor of Science (Mathematics)
Specialisation: Artificial Intelligence

#### 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!
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

#### anomalous

• Posts: 10
• :frog:
• Respect: +6
##### Re: SDD Algorithm Contest (ALCON) | Problem 3: Hairy Bottler
« Reply #2 on: May 15, 2018, 06:38:09 pm »
0
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.

Easy enough in actual programming, pseudocode... ugh. Thanks for the clarification anyways.
Uni: B.Sc. Computer Science / Adv. Mathematics (Hons) @ UNSW, 2019 - 2023

2018 HSC: English Adv. (93), Mathematics (97), Mathematics Ext. 1 (49), Software Design and Development (95), Ancient History (91), Japanese Continuers (83)

#### anomalous

• Posts: 10
• :frog:
• Respect: +6
##### Re: SDD Algorithm Contest (ALCON) | Problem 3: Hairy Bottler
« Reply #3 on: May 19, 2018, 08:33:48 pm »
+1
Reposting solution because post edits on this website are not cooperative.

Spoiler
Code: [Select]
BEGIN [u]manageSpellbook[/u](spellbook) INPUT action GET action CASEWHERE action IS "search": [u]searchSpellbook[/u](spellbook) "update": [u]updateSpellbook[/u](spellbook) ENDCASEEND [u]manageSpellbook[/u]BEGIN [u]searchSpellbook[/u](spellbook) found = "false" INPUT target_spell GET target_spell OPEN spellbook FOR INPUT READ spell, usage FROM spellbook WHILE spell <> "EOF" AND usage <> "EOF" AND found = "false" PRINT spell, usage IF target_spell = spell THEN found = "true" target_usage = usage ENDIF READ spell, usage FROM spellbook ENDWHILE CLOSE spellbook CASEWHERE found IS "true": PRINT "Spell found! Usage:", target_usage "false": PRINT "Spell not found." ENDCASEEND [u]searchSpellbook[/u]BEGIN [u]updateSpellbook[/u](spellbook) PRINT "Enter the new spell and its usage." PRINT "Enter 'EOF' for both fields when done updating." INPUT new_spell, new_usage GET new_spell, new_usage OPEN spellbook FOR OUTPUT WHILE new_spell <> "EOF" AND new_usage <> "EOF" WRITE spellbook FROM new_spell, new_usage         PRINT "Enter the new spell and its usage."         PRINT "Enter 'EOF' for both fields when done updating." INPUT new_spell, new_usage GET new_spell, new_usage ENDWHILE CLOSE spellbookEND [u]updateSpellbook[/u]
Uni: B.Sc. Computer Science / Adv. Mathematics (Hons) @ UNSW, 2019 - 2023

2018 HSC: English Adv. (93), Mathematics (97), Mathematics Ext. 1 (49), Software Design and Development (95), Ancient History (91), Japanese Continuers (83)

#### JTrudeau

• Trendsetter
• Posts: 109
• Master of the Meeses
• Respect: +90
##### Re: SDD Algorithm Contest (ALCON) | Problem 3: Hairy Bottler
« Reply #4 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 #5 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 SpellSearcherBEGIN 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.txtEND 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
• Posts: 696
• $\mathbb{O}_\mathbb{G}$
• Respect: +450
##### Re: SDD Algorithm Contest (ALCON) | Problem 3: Hairy Bottler
« Reply #6 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!
[2017: HSC]
English (Adv): 86 $\mid$ Mathematics (Adv): 94 $\mid$ Mathematics (Extension 1): 45 $\mid$ Biology: 84 $\mid$ Business Studies: 87 $\mid$ Software Design and Development: 88

[2018 $-$ 2022: UNSW]
Degree: Bachelor of Science (Computer Science) / Bachelor of Science (Mathematics)
Specialisation: Artificial Intelligence