David Prieto
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Working with physical arrays ## Objectives * Work on computational thinking * Describe the concepts of the array * Experiment for yourselves how a computer thinks ![](https://hackmd.io/_uploads/B1186RaL3.png) ## Setup Each student (or pair) needs to have one of the Strings selectors, one counter, the 6 numbers from 0 to 5. We’re going to be the computer that is going to compute with this information and we’re going to read, execute and write instructions. ## Activity 1 Find the latin alphabet and the extended alphabet and create one word of 6 letters. Can be your name or any idea related to you. When you’re done we’re going to write the word that we have written. Since we have a String, we know that String (the whole word) is equal to that. Write down ``` String = {the word that you have chosen} ``` If we write `Output (String)` we ‘re going to write in a special part what we can see on the string. Arrays are linear structures that store data. In this case we have an array of letters that are in a specific order to create a word. This is called “String” (Cadena de caracteres in Spanish, but also known as string) Looking it with care you will tell that the numbers bellow the letters start with 0 instead of 1 and that they are inside brackets. That’s because in computing ordinal numbers (first, second and so one) start with 0 instead of 1. They are called zero-based arrays because of that. You can see that also in physics or in math when you have an initial time t sub 0. To access this data we use the name of the array (String in this case) followed by a couple of brackets. ## Activity 2 Write down the following: ``` String [0] = {the character in the first place on top of the [0] } String[1] = {the character in the second place on top of the [1] } (arrive until String[5]) ```   ## Activity 3 Now we’re going to mess it up a bit. We’re going to change one of the letters If we write `String [1] = ‘A’` we’re going to change the 2 letter (on top of the [1]) into an A Now try to follow, execute, these instructions (in order!) using whatever state you had in your String ``` String[0] = M String[2] = G String[1] = A String[3] = U String[5] = L String[1] = I String[4] = E Output String ``` Write down the instructions to create another word of 6 letters of your choice ## Activity 4 The next step is to use another variable to change the number. That will be the Counter dialer. We can give it values from 0 to 5 (it’s a bit limited). For example if we write ```Counter= 1``` we are putting the 1 in the counter. If then we write ```String[Counter] = T``` we are going to put a T in the second place because ```Counter``` equals to 1 right now If then we write ```String [Counter -1] = A``` then we’re going to substitute the letter that it’s in [0] because that’s the value of ```Counter – 1``` If we change then counter writing ```Counter = 4``` and then we repeat ```String [Counter -1] = A``` we’re going to substitute the 4th letter because ```Counter -1``` is equal to 3 and that's the 4th position Now try to follow, execute, these instructions (in order!) using whatever state you had in your String ``` Counter = 0 String[Counter] = S String[Counter+1] = T Counter = 4 String[Counter-2] = E String[Counter] = E Counter = 3 String[Counter] = V String[Counter+2] =N Output(String) Output(Counter) ``` ## Activity 5 Flow control. Here we're going to use an "if" condition. If somehting is true, then we're going to do something. If not, we're not. Let's supose that we have the word **'FATIMA'** inside the String and we want to check if it has an M as the first letter. To do that we have to write. ``` if (String[0] = M) then output "The string starts with an M" end if ``` :::info Note that comparing inside an if doesn't modify the value of the String itself. FATIMA hasn't change and stil doesn't start with an M ::: if we use programming languages we have to write in different ways this kind of if. For example in Java (For DP Option D) this would be like this: ```java if (String[0] == 'M'){ System.out.println("The string starts with an M"); } ``` in Arduino it would be something similar to this: ```C++ if (String[0] == 'M'){ Serial.println("The string starts with an M"); } ``` If we want to do something else we use `else`. Using the example of seeing if FATIMA starts with an M: ``` if (String[0] = M) then output "The string starts with an M" else then output "The sting doesn't start with an M" end if ``` We can concatenate also several if clauses using `else if` for example ``` if (String[0] = M) then output "The string starts with an M" else if (String[0] = N) then output "The string starts with an N" else then output "The sting doesn't start with an M nor an N" end if ``` Set the String to be the word that you used in Activity 1. Now execute this algorithm: ``` if(String[1] = E) then output "Potato" else if (String[1]= A) then output "Coliflower" else then output "blackberry" end if ``` Now change the algorithm so you output the three posibilities (you can change the index, the number or the letter) ## Activity 6 Now we're going to check if a specific letter is in our String. To do that first we have t repeat a lot of code (you don't have to write it) Let's check the word **'AMELIE'** and check out if it has any L characters If we write it all it would be something like this. Execute this code with your String. ``` if (String [0] = L) then output "The string has an L" end if if (String [1] = L) then output "The string has an L" end if if (String [2] = L) then output "The string has an L" end if if (String [3] = L) then output "The string has an L" end if if (String [4] = L) then output "The string has an L" end if if (String [5] = L) then output "The string has an L" end if ``` It's a nightmare to write this. Imagine if we want to find the letter Q in the Quixote, we would have to write more lines than the Quixote itself. Not a good plan. :::info Also if we have a word with several L (like LLUVIA) we would have several messages telling us that we have an L in the String. Also we don't know when did that happened. ::: ## Activity 7 To face that problem we are going to use _loops_. But, now we're going to go back with the counter for a bit. In this case we're going to use `Counter = Counter + 1` to add 1 to the value of `Counter` Execute this algorithm: ``` Counter = 0 String[Counter] = H Counter = Counter +1 String[Counter] = E Counter = Counter +1 String[Counter] = L Counter = Counter +1 String[Counter] = E Counter = Counter +1 String[Counter] = N Counter = Counter +1 String[Counter] = A Output(String) Output(Counter) ``` (this one is very obvious what it's the name) ## Activity 8 Now let's write another version of the "Let's see if there is and L over here". Execute this code ``` Counter = 0 if (String [Counter] = L) then output "The string has an L" end if Counter = Counter +1 if (String [Counter] = L) then output "The string has an L" end if Counter = Counter +1 if (String [Counter] = L) then output "The string has an L" end if Counter = Counter +1 if (String [Counter] = L) then output "The string has an L" end if Counter = Counter +1 if (String [Counter] = L) then output "The string has an L" end if Counter = Counter +1 if (String [Counter] = L) then output "The string has an L" end if Output counter ``` This code is still repetitive but as you can see when we're repeating we are repeating the exact same lines. In the previous version we had somthing that changed from line to line. We can condense this into a _loop_ that is a bit of code that it's going to repeat while a condition occurs. For example for this the _while_ loop would be something like this ``` counter = 0 loop while Counter < 6 if (String [Counter] = L) then output "The string has an L" end if Counter = Counter +1 end loop Output counter ``` Write an algorithm to find the letter A in the first 3 letters ### Solution for Activity 8 ``` loop Counter from 0 to 2 if (String [Counter] = A) then output "The string has an L" end if end loop ``` ``` loop Counter from 0 to 2 if (String [Counter] = A) then output "The string has an L" break end if end loop ``` ``` counter = 0 Found = false loop while Counter < 6 AND NOT Found if (String [Counter] = L) then output "The string has an L" Found = true end if Counter = Counter +1 end loop Output counter ``` ```java for (counter = 0; counter < 6; counter ++) { if (String[counter] == 'A') { System.out.println("Found the A"); break; } } ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully