database design – What type of normalization is it if I “flip” columns to rows

Suppose I have this:

 ID    A_Type    B_Type    C_Type
 ----  --------  --------  --------
 1     Y         N         N
 2     N         Y         Y

And I “flip” those columns into this:

 ID    Type    Value
 ----  ------  -------
 1     A       Y
 1     B       N
 1     C       N
 2     A       N
 2     B       Y
 2     C       Y

I know this is fine to do. I know it means I don’t have to change the target table in the second design if I have a new type, where I would have to in the first design. That is, I get the pros and cons and such.

But I’m interested in the theory. What is the normal form of the first table, and what is the normal form of the second table?

Most things about normalization give you a normal form, then show an example. I’m trying to go the other direction. We do this pattern all the time, so given this example, what is the normal form? Both before and after.


linear algebra – How can I solve for Max Risk / Max Reward variables in both scenarios without having to flip the equations used?

My question is related to finance, but really it’s (I think) a fairly straightforward math problem.

There are two opposing (inverse) investment vehicles with the same equations that solve their Max Risk / Max Reward values, except the solutions to the two variables (Max Risk / Max Reward) are flipped depending on the scenario. To compute them, you have to identify which is which to determine which equation should be used. But it seems to me (intuitively) that since they’re just inversed it should be possible to write a single equation that would calculate the values regardless of which one is is a credit spread or a debit spread. See the following:

DISH 3/17 28c               DISH 3/17 30c
current value: 254.99       current value: 163.75
original cost: 273.75       original cost: 186.24
strike: 28                  strike: 30

Debit Spread
When placing a debit spread, the risk amount is the debit price plus any transaction costs. The potential reward equals the spread width minus the debit price, less transaction costs. For example, let’s look at a spread in DISH consisting of the purchase of the 28-strike call for $273 and the sale of the 30-strike call for $186. Resulting in a trade credit of -$87. (debit of $87)
In this case, the risk amount would be $87 per contract. The potential reward would be the difference between the strikes ($2) x 100 ($200) plus the negative credit (or minus the debit) amount (-$87) = $112 per contract (less transaction costs).

Bought DISH 28c, Sold DISH 30c, Equations:

  • Credit: sold.cost($186) – bought.cost($273) = -$87
  • Max Risk (Cost): Credit(-$87)
  • Max Reward: sold.strike($30) – bought.strike($28) = $2 * 100 = $200 + Credit(-$87) = $112
  • Current Reward: Credit(-$87) – sold.value($163) + bought.value($254) = $4
  • Percent Return: (Current Reward($4) / Max Reward($112)) * 100 = 3%

Credit Spread
To determine the risk amount of a credit spread, take the width of the spread and subtract the credit amount. The potential reward on a credit spread is the amount of the credit received less transaction costs. To illustrate, let’s say you sold the DISH 28-strike call for $273 and bought the DISH 30-strike call for $186. Resulting in a trade credit of $87. (debit of -$87) To calculate the risk per contract, you would subtract the credit received ($87) from the difference between the strikes ($2) x100 ($200) = $112 per contract (plus transaction costs). Your potential reward would be your credit of $87 per contract (less transaction costs).

Bought DISH 30c, Sold DISH 28c, Equations:

  • Credit: sold.cost($273) – bought.cost($186) = $87
  • Max Risk (Cost): sold.strike($28) – bought.strike($30) = -$2 * 100
    = -$200 + Credit($87) = -$112
  • Max Reward: Credit($87)
  • Current Reward: Credit($87) – sold.value($254) +
    bought.value($163) = -$4
  • Percent Return: (Current Reward(-$4) / Max Reward($87)) * 100 = -4%

How can I solve for Max Risk / Max Reward variables in both scenarios without having to flip the equations used?

python – Exact probability for coin flip streaks

This question determined the probability of having a streak of six heads or six tails in 100 coin flips. But only experimentally, trying it 10,000 times and counting how often it was true (and then dividing that by 10,000). It’s about 80%.

I decided to compute the exact probability. There are 2100 possible outcomes of 100 flips. So compute how many of them have such a streak, and then divide by 2100

My naive solution gets me the number for 20 flips in few seconds:

from itertools import product

def naive(flips, streak):
    return sum('h' * streak in ''.join(p) or
               't' * streak in ''.join(p)
               for p in product('ht', repeat=flips))


>>> naive(20, 6)

My fast solution gets me the number for 100 flips instantly:

from collections import Counter

def fast(flips, streak):
    needles = 'h' * streak, 't' * streak
    groups = {'-' * streak: 1}
    total = 0
    for i in range(flips):
        next_groups = Counter()
        for ending, count in groups.items():
            for coin in 'ht':
                new_ending = ending(1:) + coin
                if new_ending in needles:
                    total += count * 2**(flips - 1 - i)
                    next_groups(new_ending) += count
        groups = next_groups
    return total

The idea is to have a pool of still ongoing games, but grouped by the last six flips, and counts for how often that group has appeared. Then do the 100 flips one at a time, updating the groups and their counts. Any group that at some point ends with a streak doesn’t continue playing, instead I add it to the total result. The group occurred count times, there are flips - 1 - i flips left, and they can be anything, so multiply count with 2flips – 1 – i.


>>> fast(20, 6)
>>> fast(100, 6)

And dividing by 2100 gives me the percentage similar to those of the linked-to experiments:

>>> 100 * fast(100, 6) / 2**100

Any comments, suggestions for improvement?

Should mobile apps flip upside down?

Should mobile apps flip upside down? (I am referring to when you turn up phone upside down, and the screen flips.)

Are there any studies on this? Apple says iPad apps should be able to flip upside down, but I haven’t seen anything about apps for mobile phones.

If it’s relevant: This is a utility app. There is no horizontal mode – only portrait.

dell – xrandr issues with HDMI output flip screen to mirror image

I have searched all over the internet and can’t seem to find a solid answer to my problem. I am hoping you all can help. I have a Dell laptop connected via HDMI to a TV monitor. My goal is to invert the screen in such a way that it will appear as a mirror image or be read clearly in a mirror. I am creating a sort of projector and this has become a big issue. Last night I discovered xrandr and while I think it’s probably the key to my solution I can’t seem to get it to work the way I need it to.

I did xrandr –output HDMI-1 –reflect x to mirror/flip mine and it kind of worked but shut off my laptop screen. Is there any way to flip/mirror HDMI output so that I can still use my laptop screen as well?

How can I flip query results in Google Sheets?

I'm trying to select multiple rows from a row in a source sheet based on another column in the source sheet. E.g .:

Name   Start                  Add
Bob    2012-01-01 01:01:00    10:00:00
Tim    2020-01-01 01:01:00    04:00:00

And what I'm looking for in the output is something like:

Bob                    Tim
2012-01-01 11:01:00    2020-01-01 05:01:00
2012-01-01 21:01:00    2020-01-01 10:01:00
2012-01-02 07:01:00    2020-01-01 15:01:00

I'm not sure how to do it if it is possible … I was working on making the time change (which is also not intuitive), but I realized that I also don't know how to do it again and is supposed to turn results.

Flip Ts and CTs over

This is my first code and I'm pretty proud. It's a toss, but instead of tail it's T and CT. I've been programming for 2 weeks now and I think it's a lot of fun. But if someone wants to build on that, please.

import random
import keyboard

times = 0
t = 0
ct = 0

while True:

    flip = (random.random())

    if flip > 0.5:
    t = t + 1
    print("T WON / " + str(t))
    times = times + 1

elif flip < 0.5:
    ct = ct + 1
    print("CT WON / " + str(ct))
    times = times + 1

if keyboard.is_pressed('q'):

        procentct = ct/times * 100
        procentt = t/times * 100

        print('''Are you already going. ok here are the infomation just under me:)''')

        print ('Who won?')           
        print(str(procentt) + ' T')
        print(str(procentct) + ' CT')

        if ct < t:
            t1 = t - ct

            print ('''How big of a gap?
             ''' + str(t1)+'''
            if t > 0:
                print('''How many times did it land on T? '''
                + str(t))

        elif ct > t:
            ct1 = ct - t

            print ('''How big of a gap
             ''' + str(ct1)+'''
            if ct > 0:
                print('''How many times did it land on CT? '''
                + str(ct))


automata – How do I replace a D flip flop with a JK flip flop?

Enter image description here

Hello, I have this circuit with this I want to learn about Mealey and Moore.

Is that a floury machine? I would say yes since the top LED depends on the variables I have.

Otherwise J's line is not the next state? So is it a bog because it only depends on its condition?

Now I want to replace the D flip-flop with a JK. How could i do that

I would only implement a JK to change it, but I think there are things to be done so that the machines have the same expenses.
Any suggestions on how to do that?

Thank you very much