Another classic! I usually use the XOR method the:I got a simple challange for you.
Get 2 variables with random numbers. Try to exchange the values with out using any other variablea.
Code:
a=a^b;
b=a^b;
a=a^b;
Another classic! I usually use the XOR method the:I got a simple challange for you.
Get 2 variables with random numbers. Try to exchange the values with out using any other variablea.
a=a^b;
b=a^b;
a=a^b;
I was given this problum in my class. Whole class wasnt able to solve it. Only i solved. So i remember it to this day.Another classic! I usually use the XOR method the:
Code:a=a^b; b=a^b; a=a^b;
Most people won't. Even though there are those other ways, like the division/multiplication method, but I like this because it's simpler, especially for anyone knows what bits are.I was given this problum in my class. Whole class wasnt able to solve it. Only i solved. So i remember it to this day.
In tution i usually give this problum to my students to solve it. But looks like generation is soo dull. No has give me answer for it.
Programming is very hig field. But here in pakistan there is no place for it.Most people won't. Even though there are those other ways, like the division/multiplication method, but I like this because it's simpler, especially for anyone knows what bits are.
x = 3
y = 4
x, y = y,x
print x # prints 4
print y # print 3
It's... a way to write programs; a thinking approach to how to organize the code by thinking about it in terms of real life objects. An object has 2 things; its attributes (how it looks like, color, weight etc.) and what it can do (actions e.g a car can start, accelerate, slow down etc.). You combine these 2 and you have an object, which you do stuff on.... I dunno it's kinda weird to explain it in such a short way. Basically, you have a layout of how an object should look like and behave called a Class. From a class, you can make objects. You can like make a hundred or a thousand objects, and stuff. Then you can inherit the properties and specializes it.okay i learned some basic of programming specifically python programming but i cant figure out oop its so confusing whenever i try to learn oop i end up quiting...
so my question wtf is oop and do we really need it?
words = ["glove", "emblem", "dragon", "hell", "pakistan", "rexcalibur", "london", "megaman", "football", "alakazam"]
random = words[rand(words.length+1)]
random_mod = random.dup
pattern = random.length
puts "The word is #{pattern} letters long"
x = random.gsub(/[a-z]/, '-')
puts x
if
pattern <= 6
puts "You have only 10 tries"
counter = 0
loop do
puts "Type a letter"
input = gets.chomp
counter += 1
if
random_mod.include? "#{input}"
y = random_mod.index("#{input}")
random_mod[y] = " "
x[y] = "#{input}"
puts x
break if counter == 10 || x == random
else
puts "The suggested letter is not present in the word"
break if counter == 10 || x == random
end
end
else
puts "You have only 14 tries"
counter = 0
loop do
puts "Type a letter"
input = gets.chomp
counter += 1
if
random_mod.include? "#{input}"
y = random_mod.index("#{input}")
random_mod[y] = " "
x[y] = "#{input}"
puts x
break if counter == 14 || x == random
else
puts "The suggested letter is not present in the word"
break if counter == 14 || x == random
end
end
end
puts "Congrats! You won!" if x == random
puts "Sorry, you lost. Try next time" if !(x == random)
All right i have done the hangman... although it gives a weird error if i enter space instead of any letter and if i enter two letters at once? @MegamanEXE does yours give any errors if you do this?
If you have time.... can you test this code and give me some feedback.. here's an online compiler
repl.it
Here is the code
Spoiler: showCode:words = ["glove", "emblem", "dragon", "hell", "pakistan", "rexcalibur", "london", "megaman", "football", "alakazam"] random = words[rand(words.length+1)] random_mod = random.dup pattern = random.length puts "The word is #{pattern} letters long" x = random.gsub(/[a-z]/, '-') puts x if pattern <= 6 puts "You have only 10 tries" counter = 0 loop do puts "Type a letter" input = gets.chomp counter += 1 if random_mod.include? "#{input}" y = random_mod.index("#{input}") random_mod[y] = " " x[y] = "#{input}" puts x break if counter == 10 || x == random else puts "The suggested letter is not present in the word" break if counter == 10 || x == random end end else puts "You have only 14 tries" counter = 0 loop do puts "Type a letter" input = gets.chomp counter += 1 if random_mod.include? "#{input}" y = random_mod.index("#{input}") random_mod[y] = " " x[y] = "#{input}" puts x break if counter == 14 || x == random else puts "The suggested letter is not present in the word" break if counter == 14 || x == random end end end puts "Congrats! You won!" if x == random puts "Sorry, you lost. Try next time" if !(x == random)
It took me a while to figure out what you were trying to say here. The symbol "^" is usually:a=a^b;
b=a^b;
a=a^b;
I actually managed to do that like this method but i thought that this won't work if values are strings...... Your method will work won't it...?a = a*b; (a=6)
b= a/b (6/3=2) [b is now 2, exactly what we want, now to get back a]
a= a/b (6/2=3)
A is now 3, B is now 2. You can do the same thing with addition/subtraction combo.
post the code here and so that the mistake can be foundDammit I am totally stuck in one of the questions of my assignment...
Its one of those currency denominations questions, but its quite different in this question we have to input the amount we have to pay, amount of 100 rupee, 50 rupee and 20 rupee notes we have, and then find out how many of those notes are required to make the amount we have to pay.
Now I've made a program, but the problem is that even when I input 0 in the amount of 100 rupee notes I have, I still get some value of 100 rupee notes required to form the amount we have to pay.
How do I get across this? Help this noob pls! (btw we cant use strings)
Although I'm not entirely sure about your question, but for this stuff, you have to do 'defensive programming', meaning you have to consider cases like 0 and negative numbers, If it's 0 or less, throw an error message. something like if(amount<=0) ERROR else { the rest of your working code }Dammit I am totally stuck in one of the questions of my assignment...
Its one of those currency denominations questions, but its quite different in this question we have to input the amount we have to pay, amount of 100 rupee, 50 rupee and 20 rupee notes we have, and then find out how many of those notes are required to make the amount we have to pay.
Now I've made a program, but the problem is that even when I input 0 in the amount of 100 rupee notes I have, I still get some value of 100 rupee notes required to form the amount we have to pay.
How do I get across this? Help this noob pls! (btw we cant use strings)
There are no such thing as "bad design" bro, its all "artistic vision" nowEternalBlizzard said:Is it just me or people lately seem to defend every bad game design decision made by the devs and try to give bullshit reasons for that? Or perhaps it's because I'm on reddit and discord