8 kyu
Thinkful - Logic Drills: Traffic light
34,119 of 111,566Grae-Drake
Loading description...
Fundamentals
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
I don' get it.
This comment has been hidden.
Yes... you can do that.
how?
from processing import *
def setup(): size(500,500)
def draw(): background(220) text(str(mouseX) + ", " + str(mouseY), 20, 20) fill(249,248,247) rect(128,98,150,190) line(128,185,279,157) line(130,194,281,166) line(128,208,278,175)
draw = draw run()
Funny how the solution is simpler than where i start making this task.
'Red -> Yellow -> Green' && 'Green -> Yellow -> Red'??? Red -> Yellow -> Green' && 'Green -> Red ???
is after yellow red/green? where are you from, Moon?
after yellow
red
that's it
why theres no for Go?
This comment has been hidden.
Please flag your post as a spoiler and use appropriate markdown formatting when posting code. See https://docs.codewars.com/training/troubleshooting#post-discourse.
If you had spent 10 seconds trying to understand the error, you would have gotten your answer.
Lua translation!
Approved
ça bug grave :D
comment cela ? explique le bug
non ça va merci
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Please do NOT post your solutions in the Discourse tab, for this is the place for discussing the kata itself, not the solutions. For them the Solutions tab exists.
Also not a suggestion, it's used when you want to advice for author's kata to be improved
Nice
This comment has been hidden.
Approved!
Crystal fork with upgrade to 1.0 — for some reason the default version was 0.34.x
Approved! I think it's cuz I translated this one or someone approved it when the version update was taking place :)
No, I'm not. They probably don't give you the person's job after you finish destroying them for the things they did.
There are lights that simply never change green until the sensor picks up a car, and it won't pick up motorcycles or bikes-- though the next major intersection, right at the border of the next city, and a thousand intersetions across that city, do so flawlessly.
There are lights that won't turn green after cross traffic gets a red unless there was already a car sitting there, so that only oncoming traffic can go (because oncoming car was already sitting there), and you get to wait until they get a yellow and keep waiting while cross traffic gets another green and yellow.
There are lights that turn red again as quickly as someone deemed reasonable so that the "favored" direction can resume travelling. So if you happened to be several hundred meters back, you get to watch it turn green and yellow and red again just for the few cars sitting there, right before you get to sit there.
There are lights at weird intersections-- some tens of meters apart-- which don't change together, so you might get to sit at both of them.
The worst is a light that won't turn green at the east end of the one long road that goes all the way through the next town to a city in the next county, because that road has the magical sensor. But cross traffic DOES periodically get reds nevertheless, so that "oncoming" traffic can periodically get greens on the connecting side street which has almost no traffic and obviously no sensor.
The only thing in that department more broken than their sense of good design is someone's hiring strategy.
spamming else if is fun
i have no regrets saying this
Scala translation
LGTM, approved!
Please review and approve, thanks !
.
thsi is a test, do not reply, ignor this
Comment unsuccessfully ignored.
Nice Kata 8, thanks !
Description should be language-agnostic
^^
Why could this be a kata?
Why not? Yeah, it is easy, but this is expected of a 8 kyu kata.
In Germany (&probably other countrys too) its 'Red -> Yellow -> Green' && 'Green -> Yellow -> Red'. The description can be kinda misleading for my folks.
The description gives the complete cycle of lights. How could this be misleading? Feel free to propose a better description.
This comment has been hidden.
I think the person who made this is American cuz that's the order of the lights in the US
I'm pretty sure it's Red -> Yellow -> Green in the U.S too
(nm, I misread the comment)
COBOL translation
Approved
Why write Yellow => Green in the example, and put another option in the tests?
It says:
Where do you see yellow to green?
Sorry, I'm confused. Should I remove the issue?
It's been already marked as resolved, there is no test that expects Green for Yellow input.
i'm sorry but i am having the same issue
This comment has been hidden.
what language ? what is the issue ?
C translation (author inactive)
thanks :)
Typescript translation
(author inactive)
approved
☻
straight forward kata that teaches the basics of control flow. Nice!
This comment has been hidden.
You need to return data, not print it (<return 'green'> instead of <print('green')>)
https://docs.codewars.com/training/troubleshooting
Try "return" instead of the "print()" function.
R translation kumited ~~
Approved, thanks :)
Ruby 3.0 should be enabled, read this to learn how to do it
Please organize the structure of test fixture as following (although it has been mentioned in the attached link, I'm repeated here again)
This fork has Ruby 3.0 enabled. Awaiting moderator approval since author is inactive :)
I can't approve your fork but I've copied your snippet into the editor and made some changes as stated by @XRFXLP ~~
No random tests in
Added those for rust
I don't speak Huskell therefore I tried to google a bit, but I found out that there aren't even loops and if, else if, else statements so I gave up :/
Haskell doesn't need them here. There's no trivial access to side effects so it can't be easily cheated or misbehave. All inputs are tested.
Okay just saw the complete Haskell solution, yeaa it's really an out of the box language I should say, so closing !!! Thanks ~~
I came looking for this issue - because this is the one kata that doesn't need random tests ( in Haskell ).
It has full case coverage and hardcoding is an acceptable solution. Randomising the tests is an option, but even that wouldn't add anything, since values are immutable.
There is an exception to every rule. :]
Updated C++ translation
Thanks :)
great kata
Coffeescript translation
Crystal translation
Julia translation
i was thinking about why can't I use = instead of ===
Please review, the tests do not work.
You have to write your own tests there, that's just a template.
Ok see your point if it is a higher level kata. But an 8kyu is expected to write their own test?
Why not? The sooner the better (and after all, writing sample tests for this kata is easy), but the sample tests were located in the real tests tab, so I moved them and added random tests there.
Rust Translation
Please review.
Please approve this C# fork, I didn't notice the setup lacked a return type.
This comment has been hidden.
Mark your post as having spoiler content when they do. Your function should return those values instead of sending them to the console.
This comment has been hidden.
Not a suggestion.
You're NOT ALLOWED to post solutions.
You are, that's what the spoiler flag is for. It's appropriate when you're trying to discuss whether a certain solution should be allowed to pass, or ask questions.
Just a note.
Still a weird comment, though.
No. That's already a second time I see this user posting/sharing/telling the solution <- this is not allowed.
Well, that code is plain wrong, still, it gives away part of the solution and spoiler flag should be used. Maybe he/she doesn't understand english and confuse Suggestion's label function, as "suggest me what's wrong with my code". No other text so that could be the case. If that is indeed the case, there is always Google translator (and Question label should be used). And all we write will never reach him/her ;)
您好,在 Codewars 上,评论区的 Suggestion 标签是用于给 kata 本身提建议的,而不是让别人给你的解法提建议。如果你认为 kata 本身没有问题,想讨论你的解法的话,所有人的解法在你解出本题后会列出在 Solutions 标签页上,在那里可以进行讨论。
Let's try this...
This comment has been hidden.
This comment has been hidden.
Mark your post as having spoiler content when pasting code like that, the code you pasted is missing a
}
at the end and there are no sample tests, so click Attempt directly and it'll pass.Sorry I will... Thank you!
I've submitted C# translation Please review and approve :)
Added C++ translation.
Approved by someone
NASM translation submitted.
.
The sample test is not working and the example in the instructions has got a different name of function than in the code.
How is this 8 kyu????? this is 2 at best....
kyu
ranking goes from 8 to 1 in ascending difficulty. I think you've got it reversed ;-)Oh that makes sense .... thank you
Fortran Translation Kumited - please accept :D
Ruby translation kumited -- please check and approve
(plus I added random tests to the python version too)
Thanks for approving!
Normally after red or green the next light should be yellow. green -> yellow -> red -> yellow -> green...
It's different in different countries: https://en.wikipedia.org/wiki/Traffic_light
E.g. some places it's green -> yellow -> red -> red + yellow -> green...
But from a more practical point of view, your suggested order would be ambiguous, as
yellow
could change to bothgreen
orred
.exactly why this kata is confusing , myself same as Chrono79 order is green > yellow > red > yellow > green ......
It's mentioned in the kata description so it's fair game.
If you choose not to read kata description and let your own knowledge override the kata instead, well... ;-)
I see the point of ambiguity if yellow could lead to both red or green, so forget the suggestion.
I think the same, yellow is the nexus between red and green...