AnyDice — efficiency of code calculating rolls hitting a target with mixed pools; hitting the 5 second barrier

I have some code that is hitting the 5 second barrier;

function: target N:n of A:s B:s C:s {
    result: (count {1..N, 1..(N/2)} in (sort {A, B, C}))
}
output (target 7 of 4d12 0d20 0d8)
output (target 7 of 4d12 2d20 0d8)
output (target 7 of 4d12 4d20 0d8)

Even if I remove the final output line, it still fails.

I believe the code does what I want it to – calculate the number of dice rolling at or under the target from mixed pools (it runs when using other pools: d20s seem to be a problem).

Is there anyway I can improve it so that at least the first two of these output lines will run (or better yet, all three of them)?

N.b. from my perspective these were some of the simplest pools I wanted to look at.

tic tac toe code in c++ with two players

My main problems are making draw case and any player can choose a place which is chosen by another player here is the code :

#include <iostream>
using namespace std;

char board(3)(3) = {{'1', '2', '3'}, {'4', '5', '6'}, {'7', '8', '9'}};
static int turnnumber = 1 ;
bool winner = false, flag = false ;
bool win(){
     if(board(0)(0)==board(1)(1)&&board(1)(1)==board(2)(2))
    winner = true ;
    if(board(0)(2)==board(1)(1)&&board(1)(1)==board(2)(0))
    winner = true ;
if(board(1)(0)==board(1)(1)&&board(1)(1)==board(1)(2))
    winner = true ;
if(board(0)(0)==board(0)(1)&&board(0)(1)==board(0)(2))
    winner = true ;
if(board(2)(0)==board(2)(1)&&board(2)(1)==board(2)(2))
    winner = true ;    
if(board(0)(0)==board(1)(0)&&board(1)(0)==board(2)(0))
    winner = true ;
if(board(0)(1)==board(1)(1)&&board(1)(1)==board(2)(1))
    winner = true ;
if(board(0)(2)==board(1)(2)&&board(1)(2)==board(2)(2))
    winner = true ;
            
    if(winner==true&&turnnumber==1)
       cout << "player2 won nn" ;
    if(winner==true&&turnnumber==2)
       cout << "player1 won nn" ;
 
    return winner;
}

void view()
{
    for (int i = 0; i < 3; i++)
    {
        for (int x = 0; x < 3; x++)
        {
            cout << "(" << board(i)(x) << ")  ";
        }
        cout << endl
             << "-------------" << endl;
    }
}
    
void players()
{
    
    char player1 = 'X', player2 = 'O';
    int number;
    cout << "nplayer " << turnnumber << " it's your turn ";
    if(turnnumber==1)
       turnnumber++;
    else if(turnnumber==2)
       turnnumber--;
    char player;
    if(turnnumber==1)
       player=player2;
    if(turnnumber==2)
       player=player1;
    cin >> number ;
    
    switch(number){
        
    case 1:
        board(0)(0) = player;
        break;
    case 2:
        board(0)(1) = player;
        break;
    case 3:
        board(0)(2) = player;
        break;
    case 4:
        board(1)(0) = player;
        break;
    case 5:
        board(1)(1) = player;
        break;
    case 6:
        board(1)(2) = player;
        break;
    case 7:
        board(2)(0) = player;
        break;
    case 8:
        board(2)(1) = player;
        break;
    case 9:
        board(2)(2) = player;
        break;
    default:
        cout << "nwrong numbern";
        players();
         
    }
    system("cls");
    view();
 
    if(!win())
        players();
}

int main()
{
    view();
    players();
}

git – Gitflow, use code from another feature branch in feature branch

me and a friend are working on a project, and we are both doing seperate things (he does UI, I do some data structure), and his code relies on my code. Right now we have a master, a develop and 2 feature branches (one for UI and one for data structure). How can he test his UI with my commits, without making one huge mess out of the commit history and without committing to develop (since both features are not done yet)?

Sorry if it’s a beginner question, quite new to git!

cache – Any Drawback on running setup:upgrade, di:compile, static deploy everytime code level edit on Magento 2

Is it ok to run the following set of commands by default everytime I make a code level edit (layout edits, module creation, extension update)

php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static:content:deploy -f
php bin/magento c:f
chmod -R 777 generated/ var/ pub/

I believe that not all edits require, setup upgrade or di:compile.
But, does running all above set of commands even if not required cause any issue.

coding theory – How do I decode a received polynomial code with an error?

As a message I get (5,0,1,3), which is coding a sequence of numbers of length 2 in $mathbb{F}_7$ as polynom with the 4 support points a1 = 0, a2 = 1, a3 = 2, a4 = 6. In the transimission occured an error.
Calculate the original message.

How do I do this? In my script we didnt’t talked about polynomial codes directly just about the cyclic code. And the topic of this exercise is polynomial codes.

Could someone please get me through this or explain a way? Thanks for any help!

coding theory – Polynom Code with occured error. Find the real code word.

The received message (5,0,1,3) is coding a number sequence of length 2 over $mathbb{F}_7$ as polynom with the 4 support points a1 = 0, a2 = 1, a3 = 2, a4 = 6 . In the transmission an error occured.
Find the original message.

How do I do this? Any clue? I have literally no idea for this one you are my last help to get through this exercise.

Google tag assistant reports: “Same web property ID is tracked twice”when trying to install google analytics code

I was trying to install google analytics code into our google tag manager at first I installed the GTM and add a tag which I grabbed from tracking ID and after all that it doesn’t seem to appear an analytical dashboard on my account, I was wondering how do I fix this error on Google tag assistant and also to have the dashboard appear. thank you so much.

Python selenium web scrapping – how to refactor the code and use explicit wait?

Written following code to extract table form portal. The code works fine (except the net connectivity). But 1. I want to make it more simple, more flat. 2. If I can use explicit wait to avoid stale element error but at the same time save the time. The URL address is available in code itself.

from bs4 import BeautifulSoup as BS
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException, 
    TimeoutException, StaleElementReferenceException, WebDriverException
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.options import Options as FirefoxOptions
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait
from FIR_logging import logger
import os
import time
import pandas as pd


# base function

def get_url(some_url):
    while True:
        try:
            driver.get(some_url)
            break
        except WebDriverException:
            time.sleep(60)
            continue
    driver.refresh()



# Some constants:

URL = r'https://www.mhpolice.maharashtra.gov.in/Citizen/MH/PublishedFIRs.aspx'
options = FirefoxOptions()
options.add_argument("--headless")
options.add_argument("--private-window")
driver = webdriver.Firefox(options=options)
get_url(URL)
time.sleep(10)

Download_Directory = r'/some_directory/raw_footage7'

COLUMNS = ('Sr.No.', 'State', 'District', 'Police Station', 'Year', 'FIR No.', 'Registration Date', 'FIR No',
           'Sections')

ALL_Districts = ('AKOLA', 'AMRAVATI CITY', 'AMRAVATI RURAL', 'AURANGABAD CITY',
                 'AURANGABAD RURAL', 'BEED', 'BHANDARA', 'BRIHAN MUMBAI CITY', 'BULDHANA',
                 'CHANDRAPUR', 'DHULE', 'GADCHIROLI', 'GONDIA', 'HINGOLI', 'JALGAON', 'JALNA',
                 'KOLHAPUR', 'LATUR', 'NAGPUR CITY', 'NAGPUR RURAL', 'NANDED', 'NANDURBAR',
                 'NASHIK CITY', 'NASHIK RURAL', 'NAVI MUMBAI', 'OSMANABAD', 'PALGHAR', 'PARBHANI',
                 'PIMPRI-CHINCHWAD', 'PUNE CITY', 'PUNE RURAL', 'RAIGAD', 'RAILWAY AURANGABAD',
                 'RAILWAY MUMBAI', 'RAILWAY NAGPUR', 'RAILWAY PUNE', 'RATNAGIRI', 'SANGLI', 'SATARA',
                 'SINDHUDURG', 'SOLAPUR CITY', 'SOLAPUR RURAL', 'THANE CITY', 'THANE RURAL', 'WARDHA',
                 'WASHIM', 'YAVATMAL')


# other functions


def district_selection(name):
    dist_list = Select(driver.find_element_by_css_selector(
        "#ContentPlaceHolder1_ddlDistrict"))
    dist_list_options = dist_list.options
    names = (o.get_attribute("text")
             for o in dist_list.options if o.get_attribute("text") not in (
                 'Select'))
    if name not in names:
        logger.info(f"{name} is not in list")
        return False
    dist_list.select_by_visible_text(name)
    time.sleep(8)


def enter_date(date):
    # enters start as well as end dates with "action chains."
    WebDriverWait(driver, 160).until(
        EC.presence_of_element_located((By.CSS_SELECTOR,
                                        '#ContentPlaceHolder1_txtDateOfRegistrationFrom')))
    from_date_field = driver.find_element_by_css_selector(
        '#ContentPlaceHolder1_txtDateOfRegistrationFrom')

    to_date_field = driver.find_element_by_css_selector(
        '#ContentPlaceHolder1_txtDateOfRegistrationTo')

    ActionChains(driver).click(from_date_field).send_keys(
        date).move_to_element(to_date_field).click().send_keys(
        date).perform()

    logger.info(f'date entered: {date}')


def search():
    driver.find_element_by_css_selector('#ContentPlaceHolder1_btnSearch').click()


def number_of_records():
    """captures the text indicating number of records.
    converts it to integer. if 0 returns and appends name of district to the list
    if page is not loaded. it tries one more time for 15 secs."""
    time_counter = 1
    while time_counter < 19:
        try:
            records_number = driver.find_element_by_css_selector(
                '#ContentPlaceHolder1_lbltotalrecord').text
            if records_number == '':
                time.sleep(1)
                continue
            else:
                records_number = int(records_number)
            if records_number != 0:
                logger.info(f"{district}: {records_number}")

                return records_number
            else:
                logger.info(f"no records @ {district}")
                return False
        except (NoSuchElementException, TimeoutException, StaleElementReferenceException):
            logger.info("page is not loaded")
            time_counter += 1
            continue


def extract_table_current(name, single):
    # entire table of record to be taken to the list.
    soup = BS(driver.page_source, 'html.parser')
    main_table = soup.find("table", {"id": "ContentPlaceHolder1_gdvDeadBody"})
    time_counter = 1
    while main_table is None:
        if time_counter < 16:
            logger.info(f"the table did not load @ {name}")
            time_counter += 1
        else:
            logger.info(f"the table did not load @ {name}."
                        f"stopped trying")
            return
    links_for_pages = driver.find_elements_by_css_selector('.gridPager a')
    rows = main_table.find_all("tr")
    if links_for_pages is None:

        for row in rows:
            time.sleep(8)
            if '...' not in row.text:
                cells = row.find_all('td')
                cells = cells(0:9)  # drop the last column
                # store data in list
                single.append((cell.text for cell in cells))
    else:
        for row in rows(0:(len(rows)) - 2):
            time.sleep(8)
            cells = row.find_all('td')
            cells = cells(0:9)  # drop the last column

            # store data in list
            single.append((cell.text for cell in cells))


def next_page(name, data):
    # check if any link to next page is available
    # iterate every page.
    try:
        driver.find_element_by_css_selector('.gridPager a')
    except NoSuchElementException:
        return False
    links_for_pages = driver.find_elements_by_css_selector('.gridPager a')
    for page in range(len(links_for_pages)):
        # new list, to by pass stale element exception
        links_for_pages_new = driver.find_elements_by_css_selector('.gridPager a')
        # do not click on link for new page slot
        if links_for_pages_new(page).text != '...':
            links_for_pages_new(page).click()
            # if this can be replaced with some other wait method to save the time
            time.sleep(8)
            extract_table_current(name, data)


def second_page_slot():
    # find specific link for going to page 11 and click.
    try:
        link_for_page_slot = driver.find_element_by_link_text('...')
        link_for_page_slot.click()
    except NoSuchElementException:
        return False


# main code

page_data = ()

time.sleep(5)
view = Select(driver.find_element_by_css_selector(
    '#ContentPlaceHolder1_ucRecordView_ddlPageSize'))
view.select_by_value('50')
driver.close()
for district in ALL_Districts:

    b = "06"
    c = "2020"
    district_directory = os.path.join(Download_Directory, f'{district}{b}{c}')
    if not os.path.exists(district_directory):
        os.mkdir(district_directory)
    for i in range(1, 30):
        # reoping the page to wipe out the catch.
        options = FirefoxOptions()
        options.add_argument("--headless")
        options.add_argument("--private-window")
        driver = webdriver.Firefox(options=options)
        get_url(URL)
        # entering date and assuring that 01 to 09 is entered correctly
        if i < 10:
            i = f'{str("0")}{str(i)}'
        date_from = str(i) + b + c
        enter_date(date_from)
        # select district
        district_selection(district)
        time.sleep(3)
        # start the search
        search()
        time.sleep(7)
        if not number_of_records():
            continue
        extract_table_current(district, page_data)
        time.sleep(3)
        if not next_page(district, page_data):
            district_data = pd.DataFrame(page_data, columns=COLUMNS)
            district_data.to_csv(os.path.join(district_directory, f'{district}{i}{b}{c}.csv'))
            continue
        extract_table_current(district, page_data)
        district_data = pd.DataFrame(page_data, columns=COLUMNS)
        district_data.to_csv(os.path.join(district_directory, f'{district}{i}{b}{c}.csv'))
        driver.close()

visual studio code – Q: Indentação aleatória para padronizada

Como transformar de forma automática endentação de arquivos com espaçamentos aleatórios como 1, 2 ou 3 espaços para 4 ou qualquer outro valor usado por quem está desenvolvendo no momento de forma que fique mais claro para quem está desenvolvendo no momento?

debug – Building/running/debugging bitcoind from visual studio code

I wish to get myself familiarized with the bitcoin source code just for personal interest purposes.

Has anyone tried to build/run/debug inside visual studio code?

I just cloned the repo and followed the instructions for mac and I am able to build and run the binaries without issues.

I figure the next steps I would run the the binaries with a debugger attached inside an IDE so I could kind of trace the code paths. How would I set it up in Visual Studio Code?