Swift Playgrounds - Learn to Code 1: Walkthrough & tutorial with working solutions for every level!

preview_player
Показать описание
Swift Playgrounds - Learn to Code 1: Walkthrough & tutorial with working solutions for every level is here to help you understand the code and to compare your solutions with the ones posted here. This is not intended as a cheat sheet, but rather a helper on your coding journey.

Follow the code as it gets executed, learn the algorithms and understand the solutions.

If you have a different solution, let me know! All comments are welcome because discussion is what helps us become better coders/programmers/developers!

In this video you will find solutions for all levels:

00:00:00 Let's start!
00:00:30 Issuing Commands
00:01:00 Adding a New Command
00:01:26 Toggling a Switch
00:02:03 Portal Practice
00:02:45 Finding and Fixing Bugs
00:03:20 Bug Squash Practice
00:04:05 The Shortest Route
00:05:28 Composing a New Behavior
00:06:05 Creating a New Function
00:07:05 Collect, Toggle, Repeat
00:08:11 Across the Board
00:09:08 Nesting Patterns
00:10:26 Slotted Stairways
00:12:17 Treasure Hunt
00:14:47 Using Loops
00:15:46 Looping All the Sides
00:16:39 To the Edge and Back
00:18:02 Loop Jumper
00:19:23 Branch Out
00:22:10 Gem Farm
00:23:58 Four Stash Sweep
00:26:41 Checking for Switches
00:27:18 Using else if
00:27:50 Looping Conditional Code
00:29:12 Conditional Climb
00:30:44 Defining Smarter Functions
00:33:06 Boxed In
00:34:43 Decision Tree
00:38:05 Using the NOT Operator
00:38:55 Spiral of NOT
00:40:18 Checking This AND That
00:41:58 Checking This OR That
00:43:14 Logical Labyrinth
00:45:32 Running Code While...
00:46:18 Creating Smarter While Loops
00:47:40 Choosing the Correct Tool
00:49:01 Four by Four
00:50:30 Turned Around
00:51:51 Land of Bounty
00:54:25 Nesting Loops
00:56:29 Random Rectangles
00:57:48 You're Always Right
01:02:32 The Right-Hand Rule
01:06:00 Adjusting Your Algorithm
01:13:47 Conquering a Maze
01:17:37 Which Way to Turn?
01:22:35 Roll Right, Roll Left

Please note that sometimes Playgrounds app would go haywire and misrepresent the movement of the character but the solution would still be correct. In these cases I would the level again to show the correct behavior of characters.

In rare cases the code you see here is version 1.0 - most of the time it had at least one correction, sometimes more. Sometimes it's even version 2.0 or 3.0! Don't worry if you don't get things right from the start or if you're struggling with understanding how to do things. Just keep going and slowly improve. We've all been there!

Enjoy and happy coding!

Please LIKE this video and SUBSCRIBE to support this channel. Click the NOTIFICATION bell to join us in our next battle! Thank you!

Hashtags:

#SwiftPlaygrounds, #LearntoCode1, #SwiftPlayground
Рекомендации по теме
Комментарии
Автор

In this video you will find solutions for all levels:

00:00:30 Issuing Commands
00:01:00 Adding a New Command
00:01:26 Toggling a Switch
00:02:03 Portal Practice
00:02:45 Finding and Fixing Bugs
00:03:20 Bug Squash Practice
00:04:05 The Shortest Route
00:05:28 Composing a New Behavior
00:06:05 Creating a New Function
00:07:05 Collect, Toggle, Repeat
00:08:11 Across the Board
00:09:08 Nesting Patterns
00:10:26 Slotted Stairways
00:12:17 Treasure Hunt
00:14:47 Using Loops
00:15:46 Looping All the Sides
00:16:39 To the Edge and Back
00:18:02 Loop Jumper
00:19:23 Branch Out
00:22:10 Gem Farm
00:23:58 Four Stash Sweep
00:26:41 Checking for Switches
00:27:18 Using else if
00:27:50 Looping Conditional Code
00:29:12 Conditional Climb
00:30:44 Defining Smarter Functions
00:33:06 Boxed In
00:34:43 Decision Tree
00:38:05 Using the NOT Operator
00:38:55 Spiral of NOT
00:40:18 Checking This AND That
00:41:58 Checking This OR That
00:43:14 Logical Labyrinth
00:45:32 Running Code While...
00:46:18 Creating Smarter While Loops
00:47:40 Choosing the Correct Tool
00:49:01 Four by Four
00:50:30 Turned Around
00:51:51 Land of Bounty
00:54:25 Nesting Loops
00:56:29 Random Rectangles
00:57:48 You're Always Right
01:02:32 The Right-Hand Rule
01:06:00 Adjusting Your Algorithm
01:13:47 Conquering a Maze
01:17:37 Which Way to Turn?
01:22:35 Roll Right, Roll Left

duxmiv
Автор

Dux, I DID IT! I cracked the mystery of "Defining Smarter Functions --- all on my own. My following notes on this lesson explain it all:
>>>>How to beat this lesson: The function that has been planned in the lesson is named “collectOrToggle()”. Put the following data into the function box (the second layer exit bracket has already been put there for me so that I only need to put the first exit bracket into the function box):

func collectOrToggle() {
moveForward()
if isOnClosedSwitch {
toggleSwitch()
} else if isOnGem {
collectGem()
}
}

CRITICAL: Do NOT neglect to properly bracket the function box. This will create a CODING LAYER ERROR! There is one layer of code for the function. There is a successively inner layer of code for the conditional code. This means that I have to outer-bracket BOTH layers of code — one after the other — in order to properly code the function box. After the function box has been properly coded AND BRACKETED, write the following outer-layer level of code:

moveForward()
moveForward()
collectOrToggle()
moveForward()
moveForward()
turnLeft()
collectOrToggle()
moveForward()
moveForward()
turnLeft()
moveForward()
moveForward()
collectOrToggle()
moveForward()
moveForward()
turnRight()
collectOrToggle()
moveForward()
turnRight()
moveForward()
moveForward()
collectOrToggle()
moveForward()
moveForward()
collectOrToggle()<<<<

So how do you like that? How do you like my learning about layers of code and their entry and exit brackets?

MyNathanking
Автор

I’m passing cs thanks to this. Thanks so much man

giovanniaceti
Автор

Dude!!! I have been stuck on land of bounty! This is a very helpful video! My new reference! Thanks for posting

The-Sound-Explorer
Автор

Hi, Dux. I forgot to explain what I am having trouble with that I want to do. Now I notice that the route you took Byte through to reach the switch he needs to toggle was different than the route I initially thought of. You took Byte through the portal. I wanted to take Byte all the way across the rear side of the puzzle --- turn right, down a stairway, move forward, turn right, go up another stairway, go across the grass, turn right, go down another stairway --- and there's the switch. Now here's how I wanted to do that:

START BLOCK
moveForward()
func turn Right() --- This function is a package of three left turns.
moveForward()
func turnRight()
moveForward() --- this puts Byte on top of the switch that DOESN'T need to be turned on since it is already on.
moveForward()
func turnRight()
moveForward() --- this puts Byte directly at the bottom of the stairway, at the bottom of the first step.
moveForward() --- this puts Byte directly on the tile beyond the top step, on the grass.
moveForward() --- this puts Byte on the second tile and on the other side of the grass strip --- since the grass strip is 2 tiles in length.
moveForward() --- this puts Byte on the solid concrete immediately off the grass.
funct turnRight()
moveForward() --- and this puts Byte on top of the switch.
toggleSwitch() - END PUZZLE

But the system will not let me execute that initial "moveForward" and "func turnRight()" I then tried to "move forward()" "turnLeft" the way you did it in the video so that I could go your way of using the portals to get to the switch --- but that initial "moveForward() "turnLeft" didn't work either. HELP, I'M STUCK --- HOW WILL I EVER LEARN BEYOND THIS POINT? (NOTE: I was careful to define the "func rightTurn()" as three consecutive "turnLeft()" operations.)

MyNathanking
Автор

Hi, Dux. I’m giving the bug squash exercise another try. So here’s what I have to do:
Start at the gray arrow.
Enter a “moveForward()”
Enter a “moveForward()”
Enter a “moveForward()”
This puts Byte on top of the switch. The switch is open, since it’s green, so that means I don’t have to toggle it with a “toggleSwitch()”.
Enter a “turnLeft().”
Enter a “moveForward()”.
Enter a “moveForward()”.
This advances Byte two tiles to the left and puts Byte in front of a stairway, with the stairway to Byte’s left.
Enter a “turnLeft()”. This puts Byte directly facing the stairway.
Enter a “moveForward()”.
Enter a “moveForward()”.
This puts Byte directly on top of the switch. Since the switch is closed, I have to toggle it open.
Enter “toggleSwitch()”.
And…what’s this? Byte has to make a RIGHT turn — not a left turn — to advance two steps forward to reach the portal and then to come up on the other side of the portal, then to advance another two steps forward, and then to collect the gem. BUT…it won’t let me enter a “turnRight()”. It also will not let me do three enters of "turnLeft()".
And…I’m stuck. I want to start over and erase all my previous mistakes, but the system won’t let me; it seems to be forcing me to start up where I last left off. I enter “Run My Code, ” but Byte won’t move; he simply remains at the “Start” tile.
Show me that this Swift Playground Learning To Code is not the piece of crap that I'm now thinking it is! See what I mean? BOTH mathematics AND coding exist at the same level of difficulty for me! I don't understand how ANYONE does either!

MyNathanking
Автор

Coding in Swift is super fun! Prove me wrong! :)

duxmiv
Автор

Thank you so much I have this due today without this I would be failing

caleb
Автор

Bro I am passing my classes thanks to this

arm_
Автор

Absolute beast. Thanks for the help bro

arisnyder
Автор

I don't know why, but I can't do "using the Not Operator " it won't work

Marzkii
Автор

This is really helpful I thought I’d fail

andreaperez
Автор

I am here since 3 pm and is 9 pm thanks.

spangly
Автор

Dux, I'm still willing to make the effort to learn what I can from this tutorial even without spoken narration. It's a matter of learning how to sync what I'm seeing in this video with what I see on Swift Playgrounds on my computer, which I think I can at least try to do. The constantly changing angles of the puzzle in your video make it harder to understand. Now as for the pathway from start to complete in the Bug Squash exercise, I see where I went wrong. In this video you show how to guide Byte to the left right away, whereas I was taking Byte the long way around on a hook-shaped path. This means that Byte has to go straight ahead at the point where I thought he had to turn right. See what I mean? These exercises do not map out the paths Byte has to travel through each puzzle, and then I make mistakes assuming how Byte has to move through the puzzle to get to the gem.

MyNathanking
Автор

I was up to Decision Tree when I decided to look up walkthroughs so I could compare and contrast my solutions up until now with what others have done. I feel really stupid. My code is extremely inefficient.

crystanubis
Автор

Hi, Dux.
The problem I'm having with this lesson is that I think I'm going to write for "func collectOrToggle":
moveForward()
moveForward()
if isOnClosedSwitch {
toggleSwitch()
} else if isOnGem {
collectGem()
}

Then I think I'm going to write for the outer code layer:
collectOrToggle()
collectOrToggle()
turnLeft()
moveForward()
moveForward()
turnLeft()
collectOrToggle
collectOrToggle
turnRight()
moveForward()
turnRight()
collectOrToggle
collectOrToggle
But it JUST ISN'T WORKING. I get a red error dot no matter what I write in the function box. Plus, I can't see where I must include a loop in this lesson because there seem to be no places for adding a loop. This is another one of those impossible lessons where I JUST CAN'T SEE what I'm doing wrong. Once again, I want to advance in this, but if I can't get help with this I'm just going to have to give up and resign myself to the fact that I just can't do this Swift Playground coding thing.

MyNathanking
Автор

Hi, Dux. I have been waiting all day hoping for more help from you but I haven't gotten it yet. Are you getting impatient with me on account of all the help I need to learn all this? It is 9:35 PM, I have reviewed the introduction to functions, have learned more things than I knew earlier today --- but I'm still running into problems because Swift Playgrounds won't let me group command into functions the way you have demonstrated in this video. In "Composing A New Behavior" I can get Byte from the start to the finish by entering the following commands:

moveForward()
moveForward()
moveForward()
turnLeft()
turnLeft()
turnLeft()
moveForward()
moveForward()
moveForward()
collectGem()

But...it won't let me group those commands into functions --- and I don't even need those functions anyway because Byte still moves from the start block and collect the gem at the finish point. How will I EVER learn to do these horrid functions? It's one thing to find that I've been making mistakes because I've not been following the directions --- but I HAVE been following everything you demonstrate in the video and it STILL won't work. So what confidence am I supposed to have in my ability to learn this crap under these circumstances? What am I to think when even following the directions doesn't work?

MyNathanking
Автор

Hi, Dux. I’m trying out the new routine you describe in the video — but now I have run into another problem. Here it is:
Start at the gray arrow.
Enter “moveForward”.
Enter “turnLeft”.
This culminates in Byte facing the stairway.
Enter “move forward”.
This moves Byte to the top of the stairs.
Enter “moveForward”.
This puts Byte on top of the switch that needs to be toggled closed.
Enter “toggleSwitch”.
But a message comes up which says, “Cannot find ‘ToggleSwitch” in scope’. You show in the video beginning at 3:42 what I'm trying to do with that switch --- except that I can't do it when I try to do it myself.
HHHHEEEELLLLPPPP!!!!

MyNathanking
Автор

40:00: Hi, Dux. I am beginning to see real problems in these lessons with the obsessive use of loops. More and more I'm not doing the lessons as specified especially when I see no need for loops and especially when I see no patterns that would necessitate loops. By the way, I skipped the lesson "Decision Tree" and at this point I am watching this whole tutorial to see where it goes with, once again, no guarantee that I want to continue this if I don't get more training support from ANYWHERE. I don't want to do lessons in which things are more complicated than they have to be. That is how, along with coding, I have also most unfortunately learning other things which I wish I didn't have to learn --- things which are NOT about coding but instead about ways in which Apple developers and programmers love to make their apps so complicated that no wonder apps like Apple notes are so buggy and are always getting buggier with each new upgrade. I don't have the gift of programming, but if I did, I would seek to make and market my own "People's Computer" that the original Apple Macintoshes were meant to be in the late 1980's but which instead have most egregiously abandoned that ideal after 35 years and 25+ operating systems..

MyNathanking
Автор

I am stuck again. Here is my issue this time: I am in "Learning to code creating a new function." Byte is at the start block. He must move forward BEFORE he can execute a "funct RightTurn()". Yet I'm getting the message that he must do a "funct RightTurn()" right away BEFORE he moves forward. I am paused at 7:04 in your video, I have just watched Byte go through the puzzle --- and I STILL can't get it because I see Byte having to do a "moveForward()" before he makes a "funct RightTurn()" Yet when I try to get Byte to do a "moveForward() to move off the start block one tile forward, and then to do a "funct turnRight" I get the red "error" dot. Now I do see that the route on which you take Byte in the video here is different from the route which I have chosen at first impulse --- but I'm still in trouble because no matter how I cut it, Byte still has to move one tile forward off the start block before he can do anything else NO MATTER whether he turns right or left. But I'll try your left turn routine instead of my right turn routine and see what happens...NOPE...it won't let me do a "moveForward () turnLeft" either --- but YOU do it right here in this video. HELP!

MyNathanking