javascript – Creating a binary word search 🔍

var board = document.getElementById('board');
var characters = (
    'H','U','O','M','S','F','I','R','E','I',
    'P','O','B','P','O','S','P','K','K','A',
    'S','E','P','T','E','M','B','E','R','F',
    'Y','T','A','E','W','D','T','I','O','T',
    'W','W','N','S','R','A','I','E','B','E',
    'X','E','H','P','T','A','Y','Z','S','R',
    'S','L','X','G','Y','E','T','U','F','N',
    'K','F','D','R','E','Q','R','I','X','O',
    'Y','T','H','Q','Z','H','X','N','O','O',
    'L','H','Z','D','F','O','U','R','T','N'
);
for (var iCharacters = 0; iCharacters < characters.length; iCharacters++) {
    var binary = '0' + characters(iCharacters).charCodeAt(0).toString(2);
    var square = '<div class="square">';
    for (var iBinary = 0; iBinary < binary.length; iBinary++) {
        if (iBinary == 4) {
            square += '<div class="empty"></div>';
            square += '<div>' + binary.charAt(iBinary) + '</div>';
        }
        else
            square += '<div>' + binary.charAt(iBinary) + '</div>';
    }
    board.innerHTML += square + '</div>';
}
html, body {
    background: linear-gradient(90deg, #00C9FF 0%, #92FE9D 100%);
}
.board {
    width: 800px;
    height: 800px;
    display: grid;
    grid-template-columns: repeat(10, 10%);
    grid-template-rows: repeat(10, 10%);
    grid-gap: 5px;
    border-radius: 5px;
}
.square {
    display: grid;
    grid-template-columns: repeat(3, 33%);
    grid-template-rows: repeat(3, 33%);
    border-radius: 5px;
    background-color: #fff7;
}
.square div {
    display: flex;
    align-content: center;
    justify-content: center;
    font-size: 15px;
    color: #444;
}
.square div:nth-child(1) { border-top-left-radius: 5px; }
.square div:nth-child(3) { border-top-right-radius: 5px; }
.square div:nth-child(7) { border-bottom-left-radius: 5px; }
.square div:nth-child(9) { border-bottom-right-radius: 5px; }
.square .empty {
    background-color: #0003;
    border-radius:5px;
}
<div id="board" class="board"></div>

data structures – Binary Tree as 2D array with variable length raws

Usually we use the tree data structure when we care about time complexity for ins/del/…

-In this special case problem, space saving is mandatory too that is 2 pointers for each node is unaffordable; actual data are in leaves so infact even the internal nodes are considered overhead

-So, I thought of storing it as a 2D array with variable row size, we can assume the tree is almost always full complete power of 2, something like

R[0]= N leaf nodes

R[1]= N/2 level-1 nodes

R[2]= N/4 nodes

..
..

R[logN]= root

-I can derive the formulas for del/ins/… as the tree is easily mind-vewable from this presentation, without any pointers at all.

-Now, did I miss something???
-Is there any flaw in this?
-I’m checking for brainstorming or some opinions.

Converting a decimal to binary number using Karatsuba’s algorithm?

I’m wondering if there’s a way to convert decimal to binary using Karatsuba’s algorithm?

I don’t fully get karatsuba’s fast multiplication algorithm (which runs in $O (n^{log 3}))$ so I feel like an example like this would help!

python – Climbing the leaderboard (Hacker Rank) via binary search

I see three ways to improve your runtime. I have never done this problem so I can’t guarantee that it will be enough to pass all the tests.

Sorted input

The leaderboard scores are sorted in decreasing order. Your duplicate-removal code converts a sorted list to a set to remove duplicates (O(n)), then converts it back to a list (O(n)), then sorts it (O(n*log(n)). You could use the fact that it is sorted: duplicates will always be side by side. You could do something like the following, for example:

prev = ranked(0)
duplicateIndices = set()
for index, val in enumerate(ranked(1:), 1):
    if val == prev:
        duplicateIndices.add(index)
    prev = val
ranked2 = (x for i,x in enumerate(ranked) if i not in duplicateIndices)

This may not be the most efficient way to remove duplicate but it runs in O(n).

Sorted input 2

player is sorted as well. That means that after each iteration, the player’s rank is at most the previous one. This has two consequences:

  1. You don’t need to add the player’s score to ranked2 (either two consecutive scores are equal, which is easy enough to detect without altering ranked2, or the second one is strictly better than the first and having inserted the first in ranked2 will not change the insertion point of the second)
  2. The right boundary of your binary search is your previous insertion point.

This will not change your asymptotical complexity but it should have an interesting effect on your runtime anyway.

Skipping the linear search

With a single line, your code goes from O(m*log(n)) to O(m*n). Since ranked2 is a list, and Python does not know that it is sorted, if i in ranked2 will iterate over the entire list searching for a match. This operation runs in O(n) and is repeated for each of the player’s score. Besides, you have already handled the equality case in your binary search, so why bother?

binary – Can possiblity of hash collision be “zero” when we hash same file in different formats?

Let’s say I have a file A, which is any normal file (pdf, jpeg, mp3 etc.)

Now I get the binary dump of file, say another file B{A}.

And the hexdump of file say, file H{A}.

Now I hash all the three files with any 256 bit HASH (SHA256, BLAKE256 etc.)

I want to know that :

1. What is the possiblity of hash collision in this case (Considering if somehow I find a collison in case of file A, I still can generate the hex and binary dump of that file to see if hashes of B{A} and H{A} matches or not).

2. Will it still be 1/256* 256* 256? Or

3. Will there be 0 collision ? (Considering collision between exactly same size of files)

encoding scheme – What would be the simplest and quickest way to convert Morse code to “strict” binary?

I’m trying to find a way to easily convert strings of morse code into strings of “strict” binary, in the way that it is described in this answer. Specifically, where:

  • A dot is represented by 1.
  • A dash is represented by 111.
  • An inter-element space (between each dot or dash) is represented by 0.
  • An inter-letter space is represented by 000.
  • An inter-word space is represented by 0000000.

What would be the easiest way to achieve this conversion quickly?

python 3.x – When the target variable are not the in binary format the how to solve t

ValueError

Traceback (most recent call last)
in

1 classifier = LogisticRegression (random_state=0)

—-> 2 classifier.fit(x_train,y_train)

~anaconda3libsite-packagessklearnlinear_model_logistic.py in fit(self, x, y, sample_weight)
order=”C”,

1345

1346

-> 1347

1348

1349

accept_large_sparse-solver != ‘liblinear’)

check_classification_targets (y)
self.classes = np.unique (y)

~anaconda3libsite-packagessklearnutilsmulticlass.py in check_classification_targets(y)
181 if y type not in (‘binary’, ‘multiclass’, ‘multiclass-multioutput”,
182
‘multilabel-indicator’, ‘multilabel-sequences’):

–> 183

184

185

ValueError: Unknown label type: ‘continuous’

binary search tree – BST implementation in rust

I am looking for some feedback on my implementation of binary search tree in rust and I would appreciate someone taking the time to go through it and suggest any improvements or corrections as they see fit. More specifically I am concerned about if I should have Clone derives in the BST and Node structs since I am not using them here.

#!(allow(unused))

use std::fmt::Debug;
fn main() {
    let mut bst = BST::new(3_i32);
    bst.append(4);
    bst.append(1);
    bst.append(12);
    bst.display();
}
#(derive(Debug))
pub struct BST<T> {
    root: Box<Node<T>>,
}
#(derive(Clone, Debug))
pub struct Node<T> {
    val: T,
    left: Option<Box<Node<T>>>,
    right: Option<Box<Node<T>>>,
}

impl<T> BST<T>
where
    T: PartialOrd + Debug + Clone,
{
    pub fn new(val: T) -> Self {
        let root = Box::new(Node {
            val,
            left: None,
            right: None,
        });
        Self { root }
    }
    pub fn append(&mut self, new_val: T) {
        let new_node = Box::new(Node {
            val: new_val,
            left: None,
            right: None,
        });
        Self::push_node(new_node, &mut self.root);
    }
    // Private and recursive method
    // recursively search through every node until the value is inserted
    fn push_node(new_node: Box<Node<T>>, current_node: &mut Box<Node<T>>) {
        let ref new_val = new_node.val;
        let ref current_val = current_node.val;
        if *current_val <= *new_val {
            if let Some(ref mut left) = current_node.left {
                Self::push_node(new_node, left);
            } else {
                current_node.left = Some(new_node);
            }
        } else if *current_val > *new_val {
            if let Some(ref mut right) = current_node.right {
                Self::push_node(new_node, right);
            } else {
                current_node.right = Some(new_node);
            }
        }
    }

    fn display(&self) {
        println!("{:#?}", self);
    }
}

algorithms – Prove by induction that the height of a complete binary tree with n nodes is $⌈log_2(n+1)⌉ – 1 $

Proposition: $$ ⌈log_2(n+1)⌉ – 1 = h, quad forall n in mathbb{N}$$

I am trying to prove this proposition via proof by induction; $h$ represents the height of any complete binary tree with $n$ nodes.

What I have gotten so far:

  1. Base case: let $ n = 1 $
    begin{align}
    ⌈log_2(1+1)⌉ – 1 = 0 \
    1 – 1 = 0 \
    0 = 0
    end{align}
  2. Inductive hypothesis: let $n = k quad$ Essentially: $ n = k implies n = k + 1$
    begin{align}
    ⌈log_2(k+1)⌉ – 1 = h implies ⌈log_2(k+2)⌉ – 1 = h
    end{align}
  3. Proof by induction: I noticed that for any complete binary tree $$ 2^h leq n leq 2^{h+1} – 1$$
    Substituting $n = k$:
    begin{align}
    2^h leq k leq 2^{h+1} – 1 \
    k = ⌈2^h⌉, quad k = ⌊2^{h+1} – 1⌋
    end{align}
  4. I think that the above values for $k$ represent two separate cases: a case where the number of nodes is a power of 2, and a case where the number of nodes is essentially a full binary tree to the $hth$ level. I am unsure how to include these in the inductive hypothesis and prove the proposition via induction

Any ideas/suggestions?
Thanks!

c++ – Binary search algorithm for logarithm

c++ – Binary search algorithm for logarithm – Software Engineering Stack Exchange

DreamProxies - Cheapest USA Elite Private Proxies 100 Private Proxies 200 Private Proxies 400 Private Proxies 1000 Private Proxies 2000 Private Proxies 5000 Private Proxies ExtraProxies.com - Buy Cheap Private Proxies Buy 50 Private Proxies Buy 100 Private Proxies Buy 200 Private Proxies Buy 500 Private Proxies Buy 1000 Private Proxies Buy 2000 Private Proxies ProxiesLive.com Proxies-free.com New Proxy Lists Every Day Proxies123.com Buy Cheap Private Proxies; Best Quality USA Private Proxies