Write code logic for this maths problem int this question we give two input 3 and 14 then we get output is 1 [closed]

In connection to the International Mathematics Day celebration, the Mathematical Scholars Society had arranged for a Maths Challenge Event where school students participated in large numbers. The first level of the challenge was an oral quiz, followed by a written test in the second round.

In the second round, the problem that the students had to answer, goes like this:
For every positive number ‘n’ we define a function streak(n)=k as the smallest positive integer k such that n+k is not divisible by k+1.

For example:

13 is divisible by 1
14 is divisible by 2
15 is divisible by 3
16 is divisible by 4
17 is NOT divisible by 5
So streak(13)=4.
Similarly:
120 is divisible by 1
121 is NOT divisible by 2
So streak(120)=1.

Now, define P(k, N) which will give the number of integers n, 1<n<=N, for which streak(n) = k. Write a program to get the input as ‘k’ and ‘N’ and,
find the count of integers until N which has the streak value as ‘k’.

Input Format:

The first line of the input is an integer ‘k’ which is the streak value of an integer n.
The second line of the input is an integer ‘N’ which is the upper limit of numbers until which P(k, N) is calculated.

Output Format:

The output is an integer that gives the count of integers until ‘N’ which has the streak value as ‘k’.

Refer to sample input and output for formatting specifications.

Sample Input 1:

3
14

Sample Output 1:

1

How programically make json to have date to tabulatory react?

My idea is quite complex, because I want to create something similar to { id: 1, Rok: 1, Cena: chart1, cena2: chart2 }, to have date to use in tabulator. I thought that I can create by loop for. I take props from parent, which want to use as a date.

function Table ({chart1, chart2}){
    const Data = [index, rok, data1, data2 ]
    const data1 = [];
    const data2 = [];
    const index = [];
    const rok = [];

    for(i  = 0; i< 25; i++) {
data1.push(chart1[i]);
data2.push(chart2[i]);
rok.push(`rok + ${i}`);
index.push(i);
    }

but the result of the operation will be look like

[ [1,2,3,4,5,6..], [rok1, rok2, rok3....], [], []  ]

then I thought about something differ, but do not work as well:

function Table ({chart1, chart2}){
    const Data = [];
    for(i=0; i<25; i++){
    Data.push(
    `{`"rok": + "rok" i + "id:" + i + "cena1:" + chart1[I] + "cena2": chart2[I]`}` );
    }
()}

How to break text surrounded by other elements

I’m trying to display 3 elements in a row. The 1st and the 3rd ones are fixed size elements, the one in the middle is text and can grow.

Elements Arrangement

The problem begins when the text element grows long. I’d want like to display 1 before the first line of text and 3 right where the text ends.

Some other arrangement

I achieved this by doing two things:

  1. Set flex-wrap: wrap for parentContainer
.parentContainer {
    display: flex;
    flex-direction: row;        
    flex-wrap: wrap;
}
  1. Wrap each word into its own <span>...</span>

Here’s how it looks

enter image description here

It displays the elements the way I want to, but I have two problems with it

  1. Instead of using Unicode line breaking algorithm I have to break text into words myself. The text is not guaranteed to have any whitespaces. Besides, my algorithm is poor comparing to the standard.

  2. Double mouse click only selects text within a single span instead of the entire text.

I wonder if there is a different approach to it that isn’t prone to the issues described above?

Google Search Results In A Variable

I need to create an application that stores Google search results in a array. I’ve never done something like that and haven’t tried anything because I’m undecided which language to use, would it be possible with Python?? Can i do it adding those in a PHP global variable??I just need some ideas so the rest I can research. Thank you!!

Serialized and deserialize HTML style tag with CSS

What I’m trying to do:

  • Save/copy HTML snippet in one place, paste it in another place and have it de-serealized into an analogous DOM

How do I do serialization now

  • Call element.outerHTML on a container element
  • I’ve also tried using new XMLSerializer().serializeToString(element)

The issue

When I serialize style nodes that contain the css like:

.a > .b {
  color: red
}

They actually get serialized like

.a &gt; .b {
  color: red
}

Which is not a valid CSS and so does not get parsed properly.

The problem with greater sign is the only one I observe, but it makes me wonder about other potential serialization issues.

Question: How do I get serialize the style nodes in a way that does not break CSS in them?

Failed to execute ‘getComputedStyle’ on ‘Window’: parameter 1 is not of type ‘Element’ I am getting this error

I am new to Javascript and I can’t figure out why am I getting this error.
Here is my code:

const bckg = document.querySelector(".bckg");
const compStyle = getComputedStyle(bckg);
body {
    box-sizing: content-box;
    position: relative;
}   
.visible {
    position: relative;
    top: 50px;
    margin: auto;
    background-color: bisque;
    height: 300px;
    width: 600px;
    overflow: hidden;
    

}
.bckg {
    position: absolute;
    left: 0px;
    width: 1200px;
    height: 300px;
    background-image: url("bckg.jpg")
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>New Game</title>
    <link rel="stylesheet" href="styles.css">
   
</head>
<body>
    <script src="script.js"></script>
    <div class="visible">
        <div class="bckg" id="bckg">
            <div class="player"></div>
            <div class="obstacle"></div>
        </div>
    </div>
</body>
</html>

This error I get in Mozilla: “Uncaught TypeError: Window.getComputedStyle: Argument 1 is not an object.”
What could it be?

Error when importing ‘@tensorflow/tfjs’ to use local model in Chrome extension

I tried to use tensorflow local model in my chrome extension.
In contentScript:

import * as tf from '@tensorflow/tfjs';
const MODEL_URL = './model/model.json';
const model = tf.load_model(MODEL_URL);
model.run("text");

My manifest.json:

  "content_security_policy": {
    "extension_pages": "script-src 'self' http://localhost; object-src 'self';"
  },
  "background": {
    "service_worker": "background.js"
  },
  "action": {
    "default_title": "My extension",
    "default_popup": "popup.html"
  },
  "permissions": [
    "tabs", 
    "history", 
    "background", 
    "webNavigation", 
    "activeTab", 
    "storage"
  ],
  "content_scripts": [
    {
      "matches": [
        "<all_urls>"
      ],
      "run_at": "document_start",
      "js": [
        "contentScript.js"
      ]
    }
  ]

But I got error Uncaught EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'self'".

My package.json:

{
  "name": "my-extension",
  "version": "0.1.0",
  "description": "My Chrome Extension",
  "private": true,
  "scripts": {
    "watch": "webpack --mode=development --watch --config config/webpack.config.js",
    "build": "webpack --mode=production --config config/webpack.config.js"
  },
  "devDependencies": {
    "copy-webpack-plugin": "^6.4.1",
    "css-loader": "^4.3.0",
    "file-loader": "^6.2.0",
    "mini-css-extract-plugin": "^0.10.1",
    "size-plugin": "^2.0.2",
    "webpack": "^4.46.0",
    "webpack-cli": "^3.3.12",
    "webpack-merge": "^5.8.0"
  },
  "dependencies": {
    "@tensorflow/tfjs": "^3.16.0",
    "@tensorflow/tfjs-node": "^3.16.0"
  }
}

What should be the proper way to using local model?

React Bootstrap columns

I am trying to stack these columns horizontally using react enter image description herebootstrap. How can I modify the code I have to get the columns to stack horizontally. I’d prefer using using the lg columns. Thank you.

enter image description here

Why is sinon still throwing “Attempted to wrap connectMongoose which is already wrapped” after .restore?

I have the following test…

it("basic test", () => {
  stub = sinon.stub(app.mongoose, "connectMongoose").returns(Promise.resolve());
  expect(val.listen.callCount).to.equal(0);
  expect(stub.callCount).to.equal(0);
  app.start();
  expect(stub.callCount).to.equal(1);
  expect(val.listen.callCount).to.equal(1);
  stub.restore();
});
it("Error", () => {
  stub = sinon.stub(app.mongoose, "connectMongoose").returns(Promise.reject(new Error("error")));
  expect(val.listen.callCount).to.equal(0);
  expect(stub.callCount).to.equal(0);
  app.start();
  expect(stub.callCount).to.equal(1);
  expect(val.listen.callCount).to.equal(1);
  stub.restore();
});

But when I run I get

TypeError: Attempted to wrap connectMongoose which is already wrapped

I also tried app.mongoose.connectMongoose.restore() but same result. I also tried sandboxes although those seem deprecated.

How do I restore so I can mock it again?

Google Maps API: One-finger double tap zoom

On mobile, both Google Maps and Apple Maps allow the user to zoom in/out with a single finger by double tapping on the screen and keep the second tap pressed. However, by the default, it seems this gesture is not implemented in Google Maps API. Is there any way to manually add this functionality to the map?

Why doesn’t this generate unique sudoku puzzles?

I built a program that creates sudoku puzzles, but found that the solutions weren’t always unique, so I implemented a solver to try and check that.

My unique() function returns that the puzzles I generate are correct, but when I check them in this website and when I solve them manually it (sometimes) shows otherwise, especially when numOfFilledTiles is less than ~45.

I can’t tell what about my functions doesn’t work… I would love some help!

(I’m using a Cell class that has a value property)

const bestBet = (emptyCells) => {
    let cellIndex;
    let bestLength = 10;
    for(let i = 0; i < emptyCells.length; i++){
        let moves = getMoves(emptyCells[i]); //getMoves() returns all of a cell's legal options
        if(moves.length < bestLength){
            bestLength = moves.length;
            cellIndex = i;
        }
    }
    return cellIndex;
}

const stringify = (arr) => {
    let string = '';
    for(let x of arr){
        string += x.value;
    }
    return string;
}

const solve = (cells /*an array of all the cell objects*/) => {
    let emptyCells = cells.filter(cell => cell.value === 0);
    if(emptyCells.length === 0) return stringify(cells);
    let bestCell = bestBet(emptyCells);
    let moves = getMoves(cells[bestCell]);
    for(let move of moves){
        bestCell.value = move;
        if(solve(cells)) return stringify(cells);
    }
    bestCell.value = 0;
    return false;
}

const unique = (cells) => {
    //filling in all cells that have just one option
    let singleSolutions = cells.filter(cell => cell.value === 0 && getMoves(cell).length === 1);
    for(let cell of singleSolutions){
        cell.value = getMoves(cell)[0];
    }

    const possibleSolutions = [];
    let emptyCells = cells.filter(cell => cell.value === 0);
    for(let cell of emptyCells){
        let moves = getMoves(cell);
        for(let move of moves){
            cell.value = move;
            possibleSolutions.push(solve(cells));
            if (Array.from(new Set(possibleSolutions)).length > 1 ) return false;
        }
    }
    return true;
}

const createPuzzle = (cells, numOfFilledCells) => {
    const full = [];
    let indexes = [];
    for(let i = 0; i < 81; i++){
        full.push(i);
        indexes.push(i);
    }

    for(let i = 0; i < 81 - numOfFilledCells; i++){
        if(indexes.length === 0){
            //in case we've got too many undeletable cells
            indexes = full.slice();
            i = 0;
            for(let cell of cells){
                cell.reveal();
                cell.deletable = true;
            }
        }
        let rand = Math.floor(Math.random() * indexes.length);
        let selectedCell = cells[indexes[rand]];
        if(!selectedCell.deletable){
            i--;
        } else {
            selectedCell.hide();
            if(!unique(cells, rows, columns, boxes)){
                selectedCell.reveal();
                selectedCell.deletable = false;
                i--;
            }
        }
        indexes.splice(rand, 1);
    }
}

Angular – Conditional Custom Validator on a FormGroup Inside of a FormGroup

I have a form that needs to check if one of a group of checkboxes is checked if a dropdown has a specific value. I have a validator that works on the checkboxes, but I only need it to check if the dropdown is a specific value. Below is the form and validation code. I’ve tried having the validator bind like this.requireCheckboxesValidator.bind(this), but then it just seems to ignore the validator

  readonly closeFormGroup: FormGroup;


  constructor(
    formBuilder: FormBuilder,
  ) {
    this.closeFormGroup = formBuilder.group({
      notes: [null],
      reason: [1, Validators.required],
      checkBoxGroup: new FormGroup({
        checkBox1: new FormControl(false),
        checkBox2: new FormControl(false),
        checkBox3: new FormControl(false),
        checkBox4: new FormControl(false),
        checkBox5: new FormControl(false),
      } ,this.requireCheckboxesValidator())
    });
  }
  public requireCheckboxesValidator(): ValidatorFn {
    return function validate(formGroup: FormGroup) {
      let checked = 0;
      console.log(formGroup);
      Object.keys(formGroup.controls).forEach(key => {
         const control = formGroup.controls[key];

         if (control.value === true) {
           checked++;
         }
       });

      if (checked < 1) {
        return {
          requireCheckboxesToBeChecked: true,
        };
      }

      return null;
    };
  }

Trouble with JavaScript based photo gallery

I’m attempting to adapt the HTML, CSS, an JavaScript from here: https://www.w3schools.com/howto/howto_js_slideshow_gallery.asp

The problem I’m having is I would like to have all the JavaScript in the JS file and none be in the html.

When I try to move the onclick out of the HTML and into the JS file I have had nothing but problems. Beginning with the DOM not being loaded(solved with a domLoaded function) then to a problem with event listeners for the individual pictures.

My current problem is that the slides in the showSlides function is undefined if I pass the number 1 through it, either as you see in the document.querySelector or if I call the currentSlides or showSlides function in the console.

Here is my JavaScript

window.addEventListener("DOMContentLoaded", domLoaded);

function domLoaded() {
showSlides(slideIndex);
}

document.querySelector("#img1").addEventListener("click", currentSlide.bind(1));
document.querySelector("#img2").addEventListener("click", currentSlide.bind(2));
document.querySelector("#img3").addEventListener("click", currentSlide.bind(3));
document.querySelector('#img4').addEventListener("click", currentSlide.bind(4));
document.querySelector('#img5').addEventListener("click", currentSlide.bind(5)); 
document.querySelector('#img6').addEventListener("click", currentSlide.bind(6));
//Begin w3schools gallery code

var slideIndex = 1;
// Next/previous controls
function plusSlides(n) {
  showSlides(slideIndex += n);
}

// Thumbnail image controls
function currentSlide(n) {
  showSlides(slideIndex = n);
}

function showSlides(n) {
  console.log("click working")
  let i;
  var slides = document.getElementsByClassName("mySlides");
  let dots = document.getElementsByClassName("demo");
  let captionText = document.getElementById("caption");
  if (n > slides.length) {
    slideIndex = 1
  }
  if (n < 1) {
    slideIndex = slides.length
  }
  for (i = 0; i < slides.length; i++) {
    slides[i].style.display = "none";
  }
  for (i = 0; i < dots.length; i++) {
    dots[i].className = dots[i].className.replace(" active", "");
  }
  slides[slideIndex-1].style.display = "block";

  dots[slideIndex-1].className += " active";
  
  captionText.innerHTML = dots[slideIndex-1].alt;
}

//moving onclick out of HTML file

and here is the part of the HTML that has to do with the photogallery


                <!-- Full-width images with number text -->
                <div class="mySlides">
                <div class="numbertext">1 / 6</div>
                    <img class="mainImage" src="assets/dancingSnow.jpg">
                </div>
            
                <div class="mySlides">
                <div class="numbertext">2 / 6</div>
                    <img class="mainImage" src="assets/CABELL CO TOURNEY 2016.jpg" >
                </div>
            
                <div class="mySlides">
                <div class="numbertext">3 / 6</div>
                    <img class="mainImage" src="assets/IMG_9320.JPG" >
                </div>
            
                <div class="mySlides">
                <div class="numbertext">4 / 6</div>
                    <img class="mainImage" src="assets/Invitation.jpg" >
                </div>
            
                <div class="mySlides">
                <div class="numbertext">5 / 6</div>
                    <img class="mainImage" src="assets/SCAbattleline.jpg">
                </div>
            
                <div class="mySlides">
                <div class="numbertext">6 / 6</div>
                    <img class="mainImage" src="assets/Yorick Paragon Druid.jpg">
                </div>
            
                <!-- Next and previous buttons -->
                <a class="prev" onclick="plusSlides(-1)">&#10094;</a>
                <a class="next" onclick="plusSlides(1)">&#10095;</a>
            
                <!-- Image text -->
                <div class="caption-container">
                <p id="caption"></p>
                </div>
            
                <!-- Thumbnail images -->
                <div class="row">
                <div class="column">
                    <img class="demo" src="assets/dancingSnow.jpg"  id="img1" alt="Dancing in the Snow">
                </div>
                <div class="column">
                    <img class="demo" src="assets/CABELL CO TOURNEY 2016.jpg" id="img2"  alt="Cabell Co Tourney 2016">
                </div>
                <div class="column">
                    <img class="demo" src="assets/IMG_9320.JPG" id="img3" alt="unknown">
                </div>
                <div class="column">
                    <img class="demo" src="assets/Invitation.jpg" id="img4" alt="Invitation">
                </div>
                <div class="column">
                    <img class="demo" src="assets/SCAbattleline.jpg" id="img5"  alt="Ready for War">
                </div>
                <div class="column">
                    <img class="demo" src="assets/Yorick Paragon Druid.jpg" id="img6" alt="Amtgard Award">
                </div>
                </div>
        
                            
                            </p>
                        </div>```

Any input is much appreciated. 

Mapping through Contentful nested array is not working

I’ve successfully managed to bring the data back from Contentful but I can’t seem to map further into the array. I’m not sure what I’m doing wrong as I’m getting the following error: field.fields.map is not a function

export default function Header({ links }) {
  console.log(links);
  return (
      <div className='header-links'>
        <ul className='flex text-white uppercase tracking-widest font-medium'>
          {links.map((link) => (
            <div key={link.title}>
              {link.links.map((field) => {
                <div>
                  {field.fields.map((singleLink) => (
                    <p>{singleLink.title}</p>
                  ))}
                </div>;
              })}
            </div>
          ))}
        </ul>
      </div>
  );
}
[
  {
    "title": "Header",
    "logo": {},
    "links": [
      {
        "fields": {
          "title": "Home",
          "slug": "/"
        }
      },
      {
        "fields": {
          "title": "Food",
          "slug": "/Food"
        }
      },
    ]
  }
]