fix repl.it 1/30 - Code Challenge # 24
sequence is required???_Originally posted by @judytuna in https://github.com/Techtonica/curriculum/issues/544#issuecomment-459179557_
Hello, I wpuld like to work on this. can I?
@yati1998, that would be great! Are you part of gssoc?
Since we are a US Non-profit, please be sure to fill out this form before you start this project: https://docs.google.com/forms/d/e/1FAIpQLSeW0mo-Dpsig70374UEPvzexpas-31Ost_HsFwm0kjNOxtbtg/viewform?c=0&w=1
@yati1998, here is the problem and the existing code. Pleased return it in a comment here when it is complete.
Given an array of ints, return True if the sequence of numbers 1, 2, 3 appears in the array somewhere.
array123([1, 1, 2, 3, 1]) → True
array123([1, 1, 2, 4, 1]) → False
array123([1, 1, 2, 1, 2, 3]) → True
function array123(int_array){
// Add functionality here!
return
}
// Test cases below, click run!
var test_cases = [{
"test_case_num": 1,
"int_array": [1, 1, 2, 3, 1],
"expected_array123": true
},
{
"test_case_num": 2,
"int_array": [1, 1, 2, 4, 1],
"expected_array123": false
},
{
"test_case_num": 3,
"int_array": [1, 1, 2, 1, 2, 3],
"expected_array123": true
},
]
function run_test_case(int_array, expected_array123){
if (array123(int_array)==expected_array123){
console.log('Test passed!')
} else {
console.log('Test failed!');
console.log('Input parameters:');
console.log(int_array: ${int_array});
console.log(Output: ${array123(int_array)});
console.log(Expected output: ${expected_array123});
}
}
test_cases.forEach(function(test_cases) {
console.log(----- Test Case #${test_cases.test_case_num} -----);
run_test_case(test_cases.int_array, test_cases.expected_array123);
console.log('\n');
});
hi @yati1998 , how is this issue going?
@alodahl working on this. Will try to make pr asa soon as possible.
@alodahl In which file is this code? and where to make the changes. Can you please highliht the file?
It is not in a file, it is just the problem above that we’re using for our code practice challenges. Once you finish fixing the listed problems, I’ll find a way for you to submit a symbolic PR. @yati1998
Q: Given an array of ints, return true if 1, 2, 3 occurs in sequence in the array.
Ans:
tests = {"1":[1,1,2,3,1],"2":[1,1,2,4,1],"3":[1,1,2,1,2,3]}
def array123(array):
state1=False
state2=False
state3=False
if len(array) < 3:
return False
for (index, item) in enumerate(array):
if item == 1:
state1 = True
elif (item == 2) and state1:
state2 = True
elif (item == 3) and state2:
return True
else:
state1 = False
state2 = False
if index == len(array) - 1:
return False
for test in tests:
print "starting test %s" % test
print array123(tests[test])
Q: Given an array of ints, return true if 1,2,3 is present in any sequence in the array.
Ans:
tests = {"1":[1,1,2,3,1],"2":[1,1,2,4,1],"3":[1,1,2,1,2,3]}
def array123(array):
if len(array)<3:
return False
for i in range(len(array)-2):
z = array[i:i+3]
if (1 in z) and (2 in z) and 3 in z:
return True
return False
for i in range(1,len(tests)+1):
print "starting test %s" % tests[str(i)]
print array123(tests[str(i)])
Above are the solution I hope that works. I got the desired output.
@judytuna is this what you were hoping for?
Issue #558 solved.
Thank you, @yati1998 ! My solution for the PR is, fix one typo in the following file, but be sure to include "closes issue #558" in the description, and that this was my idea =)
https://github.com/Techtonica/curriculum/blob/master/learning-to-learn/learning-to-learn.md
@alodahl I am Sorry I am not able to get which typo you are refeering to. and where should I make the change?
The solution seems to be written in python. We use javascript =)
I was hoping for more test coverage, like the "not in order" or "not in sequence"
[5, 1, 3, 2, 4] -> false
[1, 5, 2, 3] -> false
or "1, 2, and 3 not present at all" and "empty array"
to catch tricky edge edge cases and eliminate false positives. Since it's done though, I can just add them later, or shouldnit be another PR?
Sorry, I've been out sick! Thank you for working on this!
@judytuna how can I make this better?
@judytuna, I was able to adjust the old tests pretty easily actually. Tell me if this is ok: https://repl.it/teacher/assignments/1773573/edit (admin link only)
@yati1998, I was told that document has a lot of typos. Pick any one.
Thanks! @yati1998, no further revisions are required =)
The last step (fixing a typo in that unrelated file, but mentioning this PR
as @alodahl instructs) is just to get you credit for it in this repo, since
the code you provided is going into a different service we use with
apprentices to do code challenges.
On Thu, Mar 7, 2019 at 08:26 Alina L. notifications@github.com wrote:
@judytuna https://github.com/judytuna, I was able to adjust the old
tests pretty easily actually. Tell me if this is ok:
https://repl.it/teacher/assignments/1773573/edit (admin link only)@yati1998 https://github.com/yati1998, I was told that document has a
lot of typos. Pick any one.—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/Techtonica/curriculum/issues/558#issuecomment-470594310,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AATQAyw6TZm8zZTEDDU3hYkHYoKqEMFoks5vUT3GgaJpZM4abduJ
.