quick question.. i'm new to python. But in my class I defined a function but when I call it, it says "name not found" why is that? (line 9) coderpad.io/79JT4JAN
@Ralf17: using Python 2 can be a little confusing with regards to unicode. In your case, you have a "str" object, which is basically just a bunch of bytes. htmlmin wants a real string. So you want to decode your bytes into a string, e.g. html.decode("utf-8") [or whatever encoding you're using] or unicode(html).
@Ralf17: as soon as possible, you're going to want to upgrade to Python 3. Working with unicode in Python is pretty straightforward, but 2 lets you get away with a lot of stuff you shouldn't and so it's very hard to build the right mental model because doing the wrong thing will work half the time.
@KevinDuke Other OO languages use something similar and mostly hide it. Occassionally you have to use this in Java and C++, but most of the time it is implied and optional. Python prefers to be more explicit.
There are several teenagers active in the Android room where I usually hang out.
the regulars are pretty good coders all around.
I was talking to my brother recently and his two oldest sons are learning about robotics. Not sure if it is in their school curriculum or an after-school activity or both...didn't get the details about that. I don't think they have gotten into much coding yet, though.
@AndrasDeak, @Code-Apprentice, I think the problem with the database idea is that there is still (I think, not sure) the same problem - so it records every operation that the user wants to be done, and then at the end it calculates it...well, actually, I guess you could maybe use an if statement at that point...oh, wait, I remember what was wrong with that: the user might use multiple control/target commands.
now I don't have to load files or paste my data into source files, I just import it like this. give it a try and let me know if it's working for you...
So I think the problem is, let's say the user wants to apply a Hadamard gate and then the control part of a control not gate to the control qubit and then a target gate to the target qubit. Then it would go through and record some thing like calc 1: hadamard, control calc 2: target. So then it would have to use an if statement like "if calc 1 includes control then run calc 1 first, else run calc 2 first".
But then what if you have the user wanting to do something like calc 1: hadamard, control, target (cNOT) calc 2: target (cNOT), Z, control? Then the if statement doesn't work, does it?
I guess, hmm, could you make the things the user wants to do a list, and then a for loop goes through the list, and for each thing in the list, you check if it is target or control...
hmm, okay. I think what I'll do is start by implementing the dispatch dict thing, it'll make all the code so much easier to work with. it'll take a bit to figure out what I need to do, but I think I can do it. then I'll try to implement that. Part of the problem here i think is that I'm not very experienced at all with python =P
tasks = {0: ['hadamard','control'], 1:['target']}
itask = 0
while True:
task = tasks[itask][0]
# if this can be done: do it
# pop the front of tasks
# else:
itask = 1 - itask #switch queue
# handle invalid input case somehow
might be unnecessarily convoluted, but I still don't understand your specific needs
just a rough idea
there might be better suited tools, but I don't know them
@heather this is how you'll learn, you'll be fine:) You can always ask if you have specific problems. And some working code can always be made more efficient.
the main hurdle is coming up with a clear algorithm for what you want to implement (just to repeat myself:P)
fundict = {'Hadamard':hadop, 'X':xop, 'Z':zop} #etc
if fstgat in fundict:
qstat = fundict[fstgat](qstat)
done2 = input(...)
else:
pass #handle non-trivial and custom cases
@AndrasDeak, I'm trying to implement this, and I don't understand what to do in the else statement. I have a few gates that do work outside of the actual function (I should probably just fix that, now that I think about it...)
nvm then, i'll just fix that part so I don't have to worry about it
My part 1 works. My part two transformation gives me [[101, 102, 103], [301, 302, 303], [501, 502, 503], [201, 202, 203], [401, 402, 403], [601, 602, 603]]
but for some reason, when I run it against the actual input I get the wrong answer >.<
In [14]: {'hadamard':'hadafun','xor':'xorfun','custom':'customfun'}.get('hadamard','invalidfun')
Out[14]: 'hadafun'
In [15]: {'hadamard':'hadafun','xor':'xorfun','custom':'customfun'}.get('nor','invalidfun')
Out[15]: 'invalidfun'
if my code gives a different round 2 output... then I've got something different. Not sure what it could be though, given that it gives the expected groupings based on the input (and I also get 6 with the part 2 sample input)
I can't tell if that was an "uh oh, my fixed version is still broken" or "uh oh, I just found out that the Canucks are leading by one so DSM is unhappy".
Was also unsure if the groups of vertical threes were meant to be treated as distinct groups or if we just iterate down one by one and take each group of 3
Minor: this line singates = ["Hadamard":hadop, "X":xop, "Z":zop, "Y":yop, "sqrtX":sqrtxop,"phase shift":phaseshiftop,"measurement":measurement,"custom":customop, "control":control, "target":target] won't work because it doesn't use curly braces and because the functions haven't been defined yet so you'll get NameErrors.
@heather there are some subtleties such as multiplying non-integer matrices in customop yet using == on them for equality; returning a matrix in one case, returning the input in another case; etc.
Random mind teaser: You decide one day to go out for a walk. You walk 1 mile north, turn right, walk 1 mile east, turn right, and walk 1 mile south. When you are finished, you are back where you started. How is this possible? Where in the world are you?
nah, it just strikes me as one of those "there are only a few places where you could make a teaser about directions" and that is either the north or south poles
@heather I'm learning vim myself. users.ece.utexas.edu/~adnan/vimqrc.html is a good cheat sheet. Also, run vim-tutor for about a half-hour lesson on the basics.
Traceback (most recent call last): File "python", line 118, in <module> File "python", line 23, in hadop TypeError: unsupported operand type(s) for *: 'complex' and 'NoneType'
hmm, I didn't have any errors now that I made target(), control(), and measurement() return qstat, but for the rest I honestly don't know what you are talking about. =)
def control(qstat):
typegat = input("Which gate is this the control qubit for? See list of two qubit gates at the top.")
if typegat == "cNOT":
mem1 = qstat
elif typegat == "swap":
mem2 = qstat
The same script would work for any problems accepting numerical answers. Unless there's something nasty like an increasing amount of time between allowed submissions or completely blocked out after X incorrect submissions.
I wish the AoC instructions were clearer -- I think back to challenges that took me the most time, and most of the wasted energy is spent trying to figure out what's being asked
Except for those RPG questions... those took a while (14 min for day 21, 26 min for day 22)