Skip to content

Instantly share code, notes, and snippets.

/*
Problem:
A group of 2n people, consisting of n individuals from Team A and n individuals from Team B, are seated in a row of 2n+1 chairs in the following arrangement:
A...A_B...B (where "_" represents an empty seat)
The task is to find a method to rearrange the seating positions of each person to achieve the following order:
B...B_A...B
Rules:
- In each step, only one person can be moved to an empty seat.
@quangnle
quangnle / astar.js
Created August 31, 2023 03:48
A* Demo for Path Finding
var AStar = function(){
this.getBestState = function(states){
var bestState = states[0];
var bestIdx = 0;
for (var i = 0; i < states.length; i++){
if (states[i].distance + states[i].estimate < bestState.distance + bestState.estimate){
bestState = states[i];
bestIdx = i;
}
@quangnle
quangnle / astar.js
Created August 31, 2023 03:44
A* 8-puzzle
var AStar = function(){
this.getBestState = function(states){
var bestState = states[0];
var bestIdx = 0;
for (var i = 0; i < states.length; i++){
if (states[i].distance + states[i].estimate < bestState.distance + bestState.estimate){
bestState = states[i];
bestIdx = i;
}
@quangnle
quangnle / index.html
Created July 26, 2023 11:59
Riemann's Zeta function polar representation
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/p5.js"></script>
</head>
<body>
<script>
let t = 0;
let minT = -15; // Minimum value of t (imaginary part)
let maxT = 15; // Maximum value of t (imaginary part)
var Board = function(_m) {
this.m = _m;
this.rowCheck = function(r, v) {
for (let i = 0; i < 9; i++) {
if (this.m[r][i] == v) return false;
}
return true;
}
@quangnle
quangnle / padlock_riddle.cs
Last active May 12, 2022 10:09
padlock riddle
using System;
using System.Collections.Generic;
/// <summary>
///Gargamel is an evil notorious witch. He has a chest full of treasures that he had plundered from the Smurf.
///One day, the Smurfs sneaked into the Gargamel's mansion and stole the chest.
///However, this chest was locked with a three-digit padlock and the Smurfs cannot break the chest.
///Finally, they found a recipe that engraved on the chest tobe the clue for the pasword:
/// (i) 1,4,7 - one digit is right but in the wrong place
/// (ii) 1,8,9 - one digit is right and in the correct place
@quangnle
quangnle / Randao.sol
Last active August 28, 2022 13:36
Randao
// SPDX-License-Identifier: Quang Le
pragma solidity ^0.8.9;
contract RANDAOLottery {
enum round_states {
Commit,
Reveal,
Finished,
Rolledback
}
void Solve(int[,] m, int sCol, int eCol, int sRow, int eRow, int br, int bc)
{
// determine the direction of the tile based on the mising block
var direction = GetDirection(sCol, eCol, sRow, eRow, br, bc);
// solve for size = 1
if ((eCol - sCol == 1) && (eRow - sRow == 1))
{
PlaceOne(m, sCol, eCol, sRow, eRow, direction, cIdx);
cIdx += 1;
}
public class RSA
{
private int _n;
private int _e;
private int _d;
private int _phi;
public RSA(int p, int q)
{
_n = p * q;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tuenti12
{
class Node : IComparable<Node>