military aptitude test fractions - fractions

I'm looking to get into the armed forces and have been practicing an online practice test. I'm having trouble with one question. I know guess and check will work but was hoping for a more effective solution.
The question is:
How many soldiers are there in a group of 27 sailors and soldiers if there are four fifths as many sailors as soldiers?

This isn't the place for this, but what the hell.
Sa = Sailors
So = Soldiers
Sa + So = 27
Sa = (4/5)So
Using the substitution method we can substitute (4/5)So in place of Sawhich gives us
(4/5)So + So = 27
(4/5)So + (5/5)So = 27
(9/5)So = 27
So = 27/(9/5)
So = (5/9)*27
So = 15
There are 15 soldiers and 12 sailors.

Related

Calculate the delay of a company's employees and TypeError. /pychrm

`'''I'm new in Python and I've just started Python 3.9, but I wrote the following Python code, but it doesn't work properly and it gives me the following error: (I apologize in advance for writing my own English grammar)
unsupported operand type(s) for -: 'str' and 'str'
The question is to calculate the hourly delay of 20 employees, which should be written with the function and class for 20 people, so that two random numbers from each of the 20 people in the two time slots of 12-12 and 17-13 are written with the random function, but except for Thursday, which is only between 8:00-13:00 should take a random input time slot. And then add up the time delay of each person in one week and print their delay and do it in order until the 20th person and for each person the delay of each person is printed as the number of days or hours of delay.
I wrote the code, but the problem is that it gives a TypeError and says that these calculations are not possible for the string.'''
import random
c=0
def weeklyPaid(delays):
if delays >8:
return delays / 8
else:
return delays * 1
while c<=20:
sat1 = input(random.randint(8, 12))
sun1 = input(random.randint(8, 12))
mon1 = input(random.randint(8, 12))
tue1 = input(random.randint(8, 12))
wed1 = input(random.randint(8, 12))
thu1 = input(random.randint(8, 12))
sat2 = input(random.randint(13, 17))
sun2 = input(random.randint(13, 17))
mon2 = input(random.randint(13, 17))
tue2 = input(random.randint(13, 17))
wed2 = input(random.randint(13, 17))
thu2 = input(random.randint(13, 13))
delays = (sat2-sat1*1-8-1) + (sun2-sun1*1-8-1) +(mon2-mon1*1-8-1) + (tue2-tue1*1-8-1) + (wed2-wed1*1-8-1) + (thu2-thu1*1-8-1)
print("person delays","no",c+1, "=",delays)
c = c + 1
"If the prompt argument is present, it is written to standard output without a trailing newline. The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that. When EOF is read, EOFError is raised. "
this is from python docs. so I thought the reason of your issure is the type of the value from input is 'string', it can't plus with numbers.
your can use int() method to solve the problem.
e.g, sat2 = int(input(……))
a good method is use type(), when you are not sure the variant's type.
I'm puzzled about your code.
1st, the c+=1 will never be excuted, so the program will fall in endless loop, but you said only a error occured.
second, the function didn't be used
third, there is wrong indent in line 21 - 26
so, I suggest you re write your code

How can i deobfuscate this text?

I've recently found some lua code and what I found inside was some obfuscated string. That made me wonder what sort of obfuscation technique was used there. Does anybody have an idea?
240.06230.0575240.06240.06270.0675250.0625265.06625270.0675250.0625285.07125260.065260.065260.065250.0625265...
https://pastebin.com/raw/7RkxjWQw
If this string is splitted into xxx.yyyy... chunks (exactly three digits before decimal point), then multiply each number by 800/4001 (the results will be integer!), then convert these integer numbers to ASCII, the hidden sequence of 16 floating point numbers would be revealed:
0.0062562944425795
0.036286507766961
0.02127140110477
0.047547837763604
0.041291543321025
0.0025025177770318
0.011261329996643
0.018768883327738
0.017517624439223
0.042542802209541
0.037537766655477
0.016266365550707
0.0087588122196113
0.057557908871731
0.025025177770318
0.026276436658834
Is the puzzle stops here?
Or should we try to decipher it further?
Ok, we could multiply them all by 32767/41 (the results will be integer!)
5
29
17
38
33
2
9
15
14
34
30
13
7
46
20
21
Hmm, the puzzle seems to be really interesting...
Is it the end?
Just googled it.
That's the passwords encrypted, something Roblox-related
So, OP surely doesn't have decoder script :-)
Ok, finally did it.
function decode_password(encoded_password)
local result = ""
local buffer = ""
for x in encoded_password:gsub("%d%d%d%.", "\0%0"):gmatch"%Z+" do
x = math.floor(tonumber(x) / 5.00125 + 0.5)
if x ~= 95 then
buffer = buffer..string.char(x)
elseif buffer ~= "" then
x = math.floor(tonumber(buffer) * 799.195122 + 0.5)
result = result..("qazwsxedcrfjmik,o0 23456-=\\vtgbyhnul.p;;;/[']1789"):sub(x, x)
buffer = ""
end
end
return result
end
Example 1:
local p = '240.06230.0575240.06240.06270.0675250.0625265.06625270.0675250.0625285.07125260.065260.065260.065250.0625265.06625275.06875285.07125265.06625475.11875240.06230.0575240.06255.06375270.0675250.0625280.07270.0675265.06625240.06275.06875275.06875270.0675270.0675285.07125270.0675245.06125475.11875240.06230.0575240.06250.0625245.06125250.0625275.06875245.06125260.065240.06245.06125245.06125240.06260.065275.06875275.06875475.11875240.06230.0575240.06260.065275.06875265.06625260.065275.06875280.07255.06375275.06875275.06875270.0675255.06375270.0675240.06260.065475.11875240.06230.0575240.06260.065245.06125250.0625285.07125245.06125265.06625260.065255.06375255.06375250.0625245.06125240.06250.0625265.06625475.11875240.06230.0575240.06240.06250.0625265.06625240.06250.0625265.06625245.06125275.06875275.06875275.06875275.06875240.06255.06375245.06125280.07475.11875240.06230.0575240.06245.06125245.06125250.0625270.0675245.06125255.06375250.0625285.07125285.07125285.07125270.0675270.0675260.065255.06375475.11875240.06230.0575240.06245.06125280.07275.06875270.0675280.07280.07280.07255.06375255.06375250.0625275.06875275.06875255.06375280.07475.11875240.06230.0575240.06245.06125275.06875265.06625245.06125275.06875270.0675250.0625260.065260.065255.06375285.07125250.0625250.0625255.06375475.11875240.06230.0575240.06260.065250.0625265.06625260.065250.0625280.07240.06250.0625250.0625240.06285.07125265.06625260.065245.06125475.11875240.06230.0575240.06255.06375275.06875265.06625255.06375275.06875275.06875270.0675270.0675270.0675265.06625265.06625260.065275.06875275.06875475.11875240.06230.0575240.06245.06125270.0675250.0625270.0675270.0675255.06375270.0675265.06625265.06625265.06625240.06275.06875240.06275.06875475.11875240.06230.0575240.06240.06280.07275.06875265.06625280.07280.07245.06125250.0625250.0625245.06125285.07125270.0675245.06125245.06125255.06375475.11875240.06230.0575240.06265.06625275.06875265.06625265.06625275.06875285.07125240.06280.07280.07275.06875245.06125275.06875255.06375245.06125475.11875240.06230.0575240.06250.0625265.06625240.06250.0625265.06625245.06125275.06875275.06875275.06875275.06875240.06255.06375245.06125280.07475.11875240.06230.0575240.06250.0625270.0675250.0625275.06875270.0675260.065255.06375270.0675270.0675265.06625280.07280.07255.06375260.065475.11875'
print(decode_password(p)) --> stophackingme123
Example 2:
for _, info in ipairs(loginDatabase) do
print(info.username, decode_password(info.password))
end

Issues with if iv1 >= hpmin: ; hpmin = iv1

I apologize for the rather vague title, I couldn't think of a good way to describe this issue. Basically I have
def collectivs():
while True:
a = input('Input format IVtype X-Y where X is the lowest possible IV and Y is the highest.\nIV types are:[HP, ATK, DEF, SPA, SPD, SPE]\n')
hpmin = 0
hpmax = 31
hp = "%s-%s" % (hpmin, hpmax)
try:
ivtypeup, ivrange = a.split(' '); ivtype = str.lower(ivtypeup)
print(ivtype, ivrange)
if ivtype not in('hp''atk''def''spa''spd''spe'):
print('k')
else:
print('k its working')
nonintivs = ivrange.split('-')
iv1, iv2 = list(map(int, nonintivs))
print(type(iv1))
if ivtype == 'hp':
if iv1 >= hpmin:
hpmin = iv1
if iv2 < hpmax:
hpmax = iv2
else:
print('k')
more specifically I'm trying to say "if iv1 is greater than hpmin, change hpmin to iv1." and then repeat this multiple times so I can enter say:
hp 23-31
hp 22-29
and then the result would be:
hp 23-29 because 29 is less than hp hpmax and 23 is more than the iv1 inputted in the second input. The problem is it's not doing that, in the example above if I input those the final result would be 22-29, even though it should be 23-29.
I can't think of a better way to describe it, but I've been staring at this code for an hour trying to figure out what's wrong with it, and being a beginner I can't quite figure it out.
You need to move the hpmin and hpmax initial assignments outside of the while loop:
hpmin = 0
hpmax = 31
Before-and-after diff here

Beginner Python: Where to "while"?

tl;dr: My code "works", in that it gives me the answer I need. I just can't get it to stop running when it reaches that answer. I'm stuck with scrolling back through the output.
I'm a complete novice at programming/Python. In order to hone my skills, I decided to see if I could program my own "solver" for Implied Equity Risk Premium from Prof. Damodaran's Valuation class. Essentially, the code takes some inputs and "guesses and tests" a series of interest rates until it gets a "close" value to the input.
Right now my code spits out an output list, and I can scroll back through it to find the answer. It's correct. However, I cannot for the life of me get the code to "stop" at the correct value with the while function.
I have the following code:
per = int(input("Enter the # of periods forecast ->"))
divbb = float(input("Enter the initial dividend + buyback value ->"))
divgr = float(input("Enter the div + buyback growth rate ->"))
tbondr = float(input("Enter the T-Bond rate ->"))+0.000001
sp = int(input("Enter the S&P value->"))
total=0
pv=0
for i in range(1,10000):
erp = float(i/10000)
a = divbb
b = divgr
pv = 0
temppv = 0
print (sp-total, erp)
for i in range(0, per):
a=a * (1+b)
temppv = a / pow((1+erp),i)
pv=pv+temppv
lastterm=(a*1+tbondr)/((erp-tbondr)*pow(1+erp,per))
total=(pv+lastterm)
From his example, with the inputs:
per = 5
divbb = 69.46
divgr = 0.0527
tbondr = 0.0176
sp = 1430
By scrolling back through the output, I can see my code produces the correct minimum at epr=0.0755.
My question is: where do I stick the while to stop this code at that minimum? I've tried a lot of variations, but can't get it. What I'm looking for is, basically:
while (sp-total) > |1|, keep running the code.
per = 5
divbb = 69.46
divgr = 0.0527
tbondr = 0.0176
sp = 1430
total=0
pv=0
i = 1
while(abs(sp-total)) > 1:
erp = i/10000.
a = divbb
b = divgr
pv = 0
temppv = 0
print (sp-total, erp)
for j in range(0, per):
a=a * (1+b)
temppv = a / pow((1+erp),j)
pv=pv+temppv
lastterm=(a*1+tbondr)/((erp-tbondr)*pow(1+erp,per))
total=(pv+lastterm)
i += 1
should work. Obviously, there are a million ways to do this. But the general gist here is that the while loop will stop as soon as it meets the condition. You could also test every time in the for loop and include a break statement, but because you don't know when it will stop, I think a while loop is better in this case.
Let me give you a quick rundown of two different ways you could solve a problem like this:
Using a while loop:
iterator = start value
while condition(iterator):
do some stuff
increment iterator
Using a for loop:
for i in xrange(startvalue, maxvalue):
do some stuff
if condition:
break
Two more thing: if you're doing large ranges, use the generator xrange. Also, it's probably a bad idea to reuse i inside your for loop.
I recommend CS101 from Udacity.com for learning Python. Also, if you're interested in algorithms, work through the problems at projecteuler.com

how to get the number from a string in matlab

I want to how know to get certain numbers from a string in matlab. For example, I have a string:
'ABCD_01 36_00 3 .txt', (there is spacing between 01 and 36)
What I need is to get the number 36 and 3. How can I do it in matlab? I've tried finding the answer from previous posts but can not find one that fits this purpose. Thanks for the help.
Regular expressions:
>> str = 'ABCD_01 36_00 3 .txt';
>> t = str2double( regexp(str,'.* (\d+)_.* (\d+)','tokens','once') )
t =
36 3
If the filenames always start with four characters you can do:
>> filename = 'ABCD_01 36_00 3 .txt';
>> sscanf(filename, '%*4c_%*u %u_%*u %u.txt')
ans =
36
3

Resources