August 15, 2020, 05:06:46 pm

### AuthorTopic: SDD Algorithm Contest (ALCON) | Problem 4: Strak Enterprises  (Read 1261 times) Tweet Share

0 Members and 1 Guest are viewing this topic.

#### Opengangs

• New South Welsh
• Posts: 697
• $\mathbb{O}_\mathbb{G}$
• Respect: +450
##### SDD Algorithm Contest (ALCON) | Problem 4: Strak Enterprises
« on: May 28, 2018, 12:11:38 am »
+8
<< Prev

ALCON PROBLEM 4:
STRAK ENTERPRISES

After Problem 2's fantastic 5 entries, Problem 3 was a bit more disappointing with only 2 entries. Let's try to bring that up next time!

Week 3 asked you to write a program that allows Hairy Bottler and Hermit Grunger to manage and update their spellbook by looping through a sequential file.

There were two entries for this problem - anomalous and cthulu did well with a fantastic 6/7 and 4/7 respectively. If you missed this problem, you can always do them in your spare time and get feedback in your code.

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

Code: [Select]
BEGIN [u]FindSpell()[/u]    OPEN “Spellbook” for INPUT    Get target from user input    FoundFlag = False    READ element from Spellbook    IF element == target THEN        FoundFlag = True        READ use        PRINT “Spell: “, element        PRINT “Use: “, use    ELSE         READ use        READ element    ENDIF    WHILE NOT FoundFlag AND element != “ZZZ” DO        READ use        IF element == target THEN            FoundFlag = True            PRINT “Spell: “, element            PRINT “Use: “, use        ENDIF        READ element    ENDWHILE    IF NOT FoundFlag THEN         PRINT “Spell not found”    ENDIF    CLOSE “Spellbook”END [u]FindSpell [/u]//ChallengeBEGIN [u]UpdateSpells()[/u]Get name from user inputGet use from user input     OPEN “Spellbook” for APPEND    READ element    WHILE NOT EOF DO        READ element    ENDWHILE    WRITE name, use TO “Spellbook”    CLOSE “Spellbook”END [u]UpdateSpells[/u]

Week 4 question:

You’re the new intern at Strak Enterprises, and Toby Strak has tasked you with keeping track of all the Nickel Man suits in the facility. Currently, there’s a relative file containing the code name and location of each suit, in no particular order.

Mr Strak has decided he wants the file moved into a multidimensional array instead, and alphabetised by code name. Pick an appropriate sorting method and write a program to carry out the requirements.

Jarvis has compiled an alphabetised 2d array (100 x 2 elements) with the code name and the unique nickname Mr Strak comes up with for each suit. E.g. “MK1906” is called “Mark”. Write an additional program that takes in the nickname and looks through the array to output the code name for the suit.

Because Mr Strak talks quickly, this searching process must be done as quickly as possible.

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

Learning objectives for the week:

-> Search and sort arrays.
-> Open and read relative files.
-> Manage multidimensional arrays.

Marking guidelines

Good luck, and as always, happy algorithming!
« Last Edit: June 11, 2018, 10:34:41 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

#### anomalous

• Posts: 10
• :frog:
• Respect: +6
##### Re: SDD Algorithm Contest (ALCON) | Problem 4: Strak Enterprises
« Reply #1 on: May 29, 2018, 02:41:54 pm »
0
Spoiler
Code: [Select]
BEGIN [u]fileToArray[/u](nickelsuits) suit_array = [] OPEN nickelsuits FOR INPUT READ codename, location FROM nickelsuits i = 0 WHILE (codename != 'EOF') AND (location != 'EOF') DO suit_array(i)(0) = codename suit_array(i)(1) = location i = i + 1 READ codename, location FROM nickelsuits ENDWHILE CLOSE nickelsuits end_of_array = length of suit_array - 1 swapped = True WHILE swapped = True DO swapped = False j = 0 WHILE j < end_of_array DO IF suit_array(j)(0) > suit_array(j + 1)(0) THEN temp = suit_array(j) suit_array(j) = suit_array(j + 1) suit_array(j + 1) = temp swapped = True ENDIF j = j + 1 ENDWHILE ENDWHILE RETURN suit_arrayEND [u]fileToArray[/u]BEGIN [u]findASuit[/u](jarvis_array) GET target_nickname target_codename = null found = False k = 0 WHILE (found = False) AND (current < 100) DO IF jarvis_array(k)(1) != target_nickname THEN k = k + 1 ELSE THEN found = True PRINT jarvis_array(k)(0) ENDIF ENDWHILEEND [u]challengeTask[/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)

#### vox nihili

• National Moderator
• Great Wonder of ATAR Notes
• Posts: 5321
• Respect: +1411
##### Re: SDD Algorithm Contest (ALCON) | Problem 4: Strak Enterprises
« Reply #2 on: May 29, 2018, 07:28:43 pm »
+3
<< Prev
Next >>

ALCON PROBLEM 4:
STRAK ENTERPRISES

After Problem 2's fantastic 5 entries, Problem 3 was a bit more disappointing with only 2 entries. Let's try to bring that up next time!

Week 3 asked you to write a program that allows Hairy Bottler and Hermit Grunger to manage and update their spellbook by looping through a sequential file.

There were two entries for this problem - anomalous and cthulu did well with a fantastic 6/7 and 4/7 respectively. If you missed this problem, you can always do them in your spare time and get feedback in your code.

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

Code: [Select]
BEGIN [u]FindSpell()[/u]    OPEN “Spellbook” for INPUT    Get target from user input    FoundFlag = False    READ element from Spellbook    IF element == target THEN        FoundFlag = True        READ use        PRINT “Spell: “, element        PRINT “Use: “, use    ELSE         READ use        READ element    ENDIF    WHILE NOT FoundFlag AND element != “ZZZ” DO        READ use        IF element == target THEN            FoundFlag = True            PRINT “Spell: “, element            PRINT “Use: “, use        ENDIF        READ element    ENDWHILE    IF NOT FoundFlag THEN         PRINT “Spell not found”    ENDIF    CLOSE “Spellbook”END [u]FindSpell[/u]//ChallengeBEGIN [u]UpdateSpells()[/u]Get name from user inputGet use from user input     OPEN “Spellbook” for APPEND    READ element    WHILE NOT EOF DO        READ element    ENDWHILE    WRITE name, use TO “Spellbook”    CLOSE “Spellbook”END [u]UpdateSpells[/u]

Week 4 question:

You’re the new intern at Strak Enterprises, and Toby Strak has tasked you with keeping track of all the Nickel Man suits in the facility. Currently, there’s a relative file containing the code name and location of each suit, in no particular order.

Mr Strak has decided he wants the file moved into a multidimensional array instead, and alphabetised by code name. Pick an appropriate sorting method and write a program to carry out the requirements.

Jarvis has compiled an alphabetised 2d array (100 x 2 elements) with the code name and the unique nickname Mr Strak comes up with for each suit. E.g. “MK1906” is called “Mark”. Write an additional program that takes in the nickname and looks through the array to output the code name for the suit.

Because Mr Strak talks quickly, this searching process must be done as quickly as possible.

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

Learning objectives for the week:

-> Search and sort arrays.
-> Open and read relative files.
-> Manage multidimensional arrays.

Marking guidelines

Good luck, and as always, happy algorithming!

This doesn't get anywhere near enough recognition. You and JT are doing amazing work with this Actually makes me wish I could code!
MED INTERVIEW TUTORING PM to secure your place early, as they fill up quickly!

Join ATARNotes Footy Tipping

2013-15: BBioMed (Biochemistry and Molecular Biology), UniMelb
2016-20: MD, UniMelb
2019: MPH, UniMelb
Year I: BIOL10002 BIOL10003 CHEM10006 MAST10011 MAST10016 PHYC10007 SPAN10001 SPAN10002
Year II: BCMB20005 BIOM20001 BIOM20002 CLAS10022 GENE20001 SPAN20020 SPAN30014
Year III: BCBM30001 BCMB30002 BCMB30010 BIOM30001 BIOM30002 PHRM30008

#### Opengangs

• New South Welsh
• Posts: 697
• $\mathbb{O}_\mathbb{G}$
• Respect: +450
##### Re: SDD Algorithm Contest (ALCON) | Problem 4: Strak Enterprises
« Reply #3 on: May 30, 2018, 04:22:02 pm »
0
Actually makes me wish I could code!
Why wait? (:
[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

#### vox nihili

• National Moderator
• Great Wonder of ATAR Notes
• Posts: 5321
• Respect: +1411
##### Re: SDD Algorithm Contest (ALCON) | Problem 4: Strak Enterprises
« Reply #4 on: May 30, 2018, 07:08:12 pm »
+5
Why wait? (:

The crushing weight of medical school.
MED INTERVIEW TUTORING PM to secure your place early, as they fill up quickly!

Join ATARNotes Footy Tipping

2013-15: BBioMed (Biochemistry and Molecular Biology), UniMelb
2016-20: MD, UniMelb
2019: MPH, UniMelb
Year I: BIOL10002 BIOL10003 CHEM10006 MAST10011 MAST10016 PHYC10007 SPAN10001 SPAN10002
Year II: BCMB20005 BIOM20001 BIOM20002 CLAS10022 GENE20001 SPAN20020 SPAN30014
Year III: BCBM30001 BCMB30002 BCMB30010 BIOM30001 BIOM30002 PHRM30008

#### JTrudeau

• Trendsetter
• Posts: 109
• Master of the Meeses
• Respect: +90
##### Re: SDD Algorithm Contest (ALCON) | Problem 4: Strak Enterprises
« Reply #5 on: June 10, 2018, 12:51:32 pm »
+1
Just a reminder that submissions close tonight, so get your answers in soon! This is an insane opportunity to brush up on your algorithms and get quality feedback
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 4: Strak Enterprises
« Reply #6 on: June 10, 2018, 09:23:46 pm »
0
Code: [Select]
BEGIN [u]StrakEnterprises[/u]OPEN “Nickelmen” for INPUTSET curIndex = 0READ codeName from NickelmenREAD location from NickelmenWHILE curIndex < sentinel value of Nickelmen DO nickelmenArray(curIndex).codeName = codename nickelmenArray(curIndex).location = location INCREMENT curIndex by 1END WHILESET pass to 1WHILE pass <  length of nickelmenArray DO SET count to pass + 1 SET min to pass WHILE count <= length of nickelmenArray DO IF nickelmenArray(count) < nickelmenArray(min) THEN min = count END IF INCREMENT count by 1END WHILESWAP nickelmenArray(min) with nickelmenArray(count)INCREMENT pass by 1END [u]StrakEnterprises[/u]BEGIN [u]StrakChallenge[/u] GET userInput SET newString to userInput[0] + userInput[length of userInput] SET count to 0 SET found to false WHILE count < length of nickelmenArray and found = false DO SET codeNameString to nickelmenArray(count).codename SET newCodeNameString to codeNameString[0] + codeNameString[length of codeNameString] IF newString == newCodeNameString THEN DISPLAY nickelmenArray(count).codename found = true ELSE False END IF INCREMENT count by 1 END WHILEEND [u]StrakChallenge[/u]
« Last Edit: June 10, 2018, 09:32:47 pm by cthulu »

#### jasn9776

• Forum Regular
• Posts: 57
• Respect: +4
##### Re: SDD Algorithm Contest (ALCON) | Problem 4: Strak Enterprises
« Reply #7 on: June 10, 2018, 09:57:16 pm »
0
[code ]
BEGIN MoveFiletoSortedArray
Open SuitFile for relative access
Set Suits as an array of 100 records of type suit
suit is a record containing:
Codename:string
Nickname:string
REPEAT
RelativeNumber= 1
Read ProductData into Codename, Nickname using
RelativeNumber
Suits(i).codename = SuitFile(RelativeNumber).codename
Suits(i).nickname = SuitFile(RelativeNumber).nickname
Increment i
Increment Relative Number
UNTIL RelativeNumber = 999{Sentinel value} OR i>length of Suits

j= 1

WHILE j <length of Suits and SWAPPED=TRUE
SWAPPED=FALSE
FOR i =1 to length-j
IF Suits>Suits[i+1] THEN
SWAP(Suits.codename,Suits[i+1].codename)
SWAP(Suits.nickname,Suits.nickname)
SWAPPED=TRUE
ENDIF
NEXT i
j=j+1
ENDWHILE
END MoveFileToSortedArray

[/code ]
HSC 2018: English Adv(88) | Bio (90) | Phys(85) | Software Design (87) | 3U Math (41)

#### Opengangs

• New South Welsh
• Posts: 697
• $\mathbb{O}_\mathbb{G}$
• Respect: +450
##### Re: SDD Algorithm Contest (ALCON) | Problem 4: Strak Enterprises
« Reply #8 on: June 11, 2018, 10:39:32 am »
+2
ALCON WEEK 4 FEEDBACK

Week 4 had some great entries, and we can really begin to see an improvement in the way you all write your algorithm! It was definitely a challenging one (JTrudeau can vouch ) so you all did fantastic jobs at writing them. Huge congratulations to anomalous who scored 5/7 in this task. If you haven't already, please register to take part in future contests!

Everything you need for Week 4'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 5's question.

(note [u ][/u] tags mean that the code was underlined.)
BEGIN SystemTransfer()    Suits(100,2) is a 2d array of type string    Open SuitsFile for relative access    Move read/write head to start of file    i = 1    WHILE NOT EOF DO        GET name, location from SuitsFile        Suits[i,1] = name        Suits[i,2] = location        INCREMENT i     ENDWHILE    [u]SortArray(Suits)[/u]END [u]SystemTransfer()[/u]BEGIN SortArray(array)    //Using selection sort, but insertion or bubble can also be used    pass = 1    FOR pass TO array.length() - 1        Min_index = pass        Count = pass + 1        FOR test TO array.length() - 1                IF array[test] < array[min_index] THEN                        Min_index = count                ENDIF                NEXT test                Swap(array, min_index, pass)        NEXT passEND [u]SortArray[/u]()** Where Swap() swaps the values of the elements in the array given. BEGIN [u]Find_Nickname[/u](suits, target_name)        start = 1        end = suits.length()        foundFlag = False        WHILE end >= start AND NOT foundFlag DO                middle = INT((start + end)/2)                IF target = suits[middle,0] THEN                        foundFlag = True                ELSE                        IF target < suits[middle,0] THEN                                end = middle - 1                        ELSE                                start = middle + 1                        ENDIF                ENDIF        ENDWHILE        IF foundflag THEN                RETURN suits[middle,1]        ELSE                 DISPLAY “Not found”        ENDIFEnd [u]Find_Nickname[/u]
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]