## algorithms – Minimum number of moves puzzle

Quite simple if time complexity O(K*N) is acceptable:

For each of the N towns, you calculate how long it takes for everyone to reach that town. First, you add everyone’s distance to that town. That’s one minimum requirement. Second, since nobody can do two turns in a row, find the person furthest away. If the person is X steps away, then they can’t reach that town earlier than after 2X-1 moves. So you calculate max (sum of all distances, 2*largest distance – 1). You do that for each town and chose the smallest value.

You can get the time complexitiy a lot lower by counting how many players are in each town initially, calculating the numbers for the first time, and for each of the following towns calculate the numbers in constant time by using the numbers of the previous town. (For example if you know the sum of distances to town 3, then for town 4 you increase that sum by K since everyone goes one step further, then subtract N * number of players in town 4, because these don’t move N steps but no steps at all. )

## logic – Question about a puzzle in ch. 2 of “to mock a mockingbird”

In chapter 2, the author introduced Nelson Goodman Principle, which says if you ask someone who either always lies or always tells the truth: “Are you the type who could claim A is true?”, he/she will always tell the truthfulness of A. So for problem 3, the given correct answer is “Is Arthur truthful?”, which is supposed to be equivalent to the sentence formulated with Nelson Goodman Principle: “Are you the type who could claim that you are Arthur?”

However, it is really hard for me see the equivalence of the two formulations. I mean, the consequences of the two formulations are the same. But on the surface, I couldn’t tell the equivalence just by transforming the text from one to the other. Can anyone help me to understand it? Thank you!

PS: Ch. 2 Problem 3 in the book: you meet two identical twins, one of whom is Arthur. One of the two always lies. The other always tells the truth. You have no idea who is who or who lies who doesn’t. You are only allowed to ask one question with 3 words to either of the two in order to find out who is Arthur.

## performance – Linear conflicts heuristic for 15 puzzle game

I’m trying to solve the 15 Puzzle problem using IDA* algorithm with a Linear Conflicts heuristic. I already implemented the heuristic from what I understood : link

Here’s my goal state (“snail” format) and initial state :

``````GOAL_STATE =
(( 1  2  3  4)
(12 13 14  5)
(11  0 15  6)
(10  9  8  7))

INITIAL STATE =
((11  3  4  2)
(14  8 12  9)
( 5  0 13  6)
( 7 15  1 10))

``````

I’m wondering how I can optimize my code (the linear_conflict_heuristic() function) which seems to be very redondant.

Also I’m not sure how I should be counting these slides (3, 4, 2) on the initial state. Does that count for 2, 3 or 4 conflicts ?

Here’s my code so far :

``````
import numpy as np

m = ((0) * 4 for i in range(4))
dx, dy = (0, 1, 0, -1), (1, 0, -1, 0)
x, y, c = 0, -1, 1
for i in range(4 + 4 - 2):
for j in range((4 + 4 - i) // 2):
x += dx(i % 4)
y += dy(i % 4)
m(x)(y) = c
c += 1

BOARD_LENGTH = 4
GOAL_STATE = np.array(m)

def goal_on_row(num, i):
for j in range(BOARD_LENGTH):
if num == GOAL_STATE(i)(j):
return j

def goal_on_column(num, j):
for i in range(BOARD_LENGTH):
if num == GOAL_STATE(i)(j):
return i

def linear_conflict_heuristic(state):
result = 0
for i in range(BOARD_LENGTH):
for j in range(BOARD_LENGTH):
num = state(i)(j)
if num != 0:
position = goal_on_row(num, i)
if position is not None:
if position <= j:
for k in reversed(range(j)):
num2 = state(i)(k)
if num2 != 0:
position2 = goal_on_row(num2, i)
if position2 is not None:
if position < position2:
result += 1
else:
for k in range(j + 1, BOARD_LENGTH):
num2 = state(i)(k)
if num2 != 0:
position2 = goal_on_row(num2, i)
if position2 is not None:
if position > position2:
result += 1

position = goal_on_column(num, j)
if position is not None:
if position <= i:
for k in reversed(range(i)):
num2 = state(k)(j)
if num2 != 0:
position2 = goal_on_column(num2, j)
if position2 is not None:
if position < position2:
result += 1
else:
for k in range(i + 1, BOARD_LENGTH):
num2 = state(k)(j)
if num2 != 0:
position2 = goal_on_column(num2, j)
if position2 is not None:
if position > position2:
result += 1

return result

def main():
state = np.array(((11, 3, 4, 2), (14, 8, 12, 9), (5, 0, 13, 6), (7, 15, 1, 10)))
result = linear_conflict_heuristic(state)
print(f"RESULT = {result}")

if __name__ == '__main__':
main()

``````

## python – Breadth First Search Block Puzzle

I am creating a program that will be given a text file as output with the board’s dimension and the piece id along with the piece width and length. The goal is to arrange all blocks in the board correctly. Currently, my program takes forever to come up with a solution. I need help optimizing or figuring out what I need to fix. I am trying to implement Breadth First Search to do this correctly.
I will attach the text file and source file.
I added pictures at the bottom to show the input and what the output should be.
TEXT FILE – first line is the board dimensions and the rest are piece ID, piece width, piece length.

``````10,10
1,10,1
2,1,10
3,1,5
4,3,5
5,20,2
6,1,5
7,1,5
8,2,5
``````

SOURCE FILE The Solve method does all of the heavy work and implements BFS

``````import argparse, copy
import queue
import copy
import numpy as np

class PuzzleBoard():

def __init__(self, board_length, board_width ):
self.l = board_length
self.w = board_width
self.state = ((0 for _ in range(board_width)) for _ in range(board_length))
self.used_piece = ()

# Input: point - tuple cotaining (row_index, col_index) of point in self.state
# Returns true if point is out of bounds; otherwise, returns false
def __out_of_bounds(self, point):
# TODO: Implement this function
if(point < 0 or point > (len(self.state)) or (point > (self.state(0)))):
return True
return False

# Finds the next available open space in the PuzzleBoard (looking from the top-left in row-major order)
def __next(self):
for i in range(len(self.state)) :
for j in range(len(self.state(0))):
if (self.state(i)(j) == 0):
return (i, j)
return False

# Input: piece - PuzzlePiece object
# Check if piece fits in the next available space (determined by __next method above)

def fits(self, piece):

position = self.__next()
if not position:
return False

#TODO: Check if any part of the piece is out of bounds
#if piece will be out bounds when place rotate to see if that helps
if((( piece.w + position(0) ) > len( self.state )) or (( piece.l + position(1) )> len( self.state(0) ))):
piece.rotate()

if((( piece.w + position(0) ) > len( self.state )) or (( piece.l + position(1) )> len( self.state(0) ))):
return False
#TODO: Check if piece can be placed without intersecting another placed piece

return True

# Input: piece - PuzzlePiece object
# Insert piece into the next available position on the board and update state
def place(self, piece):
# TODO: Bug in this function. Pieces not being placed correctly.
position = self.__next()
if self.fits(piece):
for i in range(position(0), position(0) + piece.w ):
for j in range(position(1), position(1) + piece.l):
if((( piece.w + position(0) ) > len( self.state )) or (( piece.l + position(1) )> len( self.state(0) ))):
return
if(self.state(i)(j)== 0):
#self.used_piece.append(piece)
self.state(i)(j) = piece.id
else:
continue
return position

def check(self, piece):
position = self.__next()
if(position(0) + piece.w > self.w or position(1) + piece.l > self.l):
return False
return True

# Returns whether the board has been filledwith pieces
def completed(self):
return True if not self.__next() else False

def copy(self):
copied = PuzzleBoard(self.l, self.w)
copied.state = copy.deepcopy(self.state)
return copied

class PuzzlePiece():

def __init__(self, pid, length, width):
self.id = pid
self.l = length
self.w = width
itfits = False

def rotate(self):
#TODO: Bug in this function. Pieces are not rotating correctly
temp = self.l
self.l = self.w
self.w = temp

def orientation(self):
return "H" if self.w >= self.l else "V"

def __str__(self):
return f"ID: {self.id}, LENGTH: {self.l}, WIDTH: {self.w}, ROTATED: {self.rotated}"

def parse_input(filepath) :

#TODO: Bug in this function. Error raised when called
parsed = {'board' : {}, 'pieces' : {}}
with open(filepath, 'r') as f:
file_contents = f.read().strip().split("n")
board_length, board_width = file_contents(0).strip().split(",")
parsed('board')('length') = int(board_length)
parsed('board')('width') = int(board_width)
for i in range(1, len(file_contents)):
#FIX: the issue was fix
pid, l, w = file_contents(i).strip().split(",")
pid, l, w = int(pid), int(l), int(w)
parsed('pieces')(pid) = {}
parsed('pieces')(pid)('length') = l
parsed('pieces')(pid)('width') = w
return parsed

def helper(board, piece):
unused = ()
#for piece in pieces:
if board.fits(piece):
position = board.place(piece)
board.used_piece.append((piece, position))

return board

def solve(board, remaining, used_pieces=()):
# TODO: Implement a solution for a variable amount of pieces and puzzle board size.
# HINT: Recursion might help.7
poss = queue.Queue()
poss.put(board)

currboard = PuzzleBoard(len(board.state), len(board.state(0)))
while not currboard.completed():
currboard = poss.get()
#print(currboard.state)
for piece in remaining:
fakeboard = copy.deepcopy(currboard)
if(not (piece.id in np.array(fakeboard.state))):
#if( fakeboard.check(piece)):
poss.put(helper(fakeboard, piece))

print("Suff done")
return currboard

'''if(len(remaining) != 0):
board, used_pieces, unused_pieces = helper(board, remaining, used_pieces)
if board.completed():
return board, used_pieces
for i in board.state:
print(i)
print("n n")
return solve(board, unused_pieces, used_pieces)
return board'''

def main():
#TODO: Bug in this function. Positions are not correct after solution is found.
parser = argparse.ArgumentParser()
parser.add_argument('input')
args = parser.parse_args()
parsed = parse_input(args.input)
board = PuzzleBoard(parsed('board')('length'), parsed('board')('width'))
pieces = ()
for k, v in parsed('pieces').items():
pieces.append(PuzzlePiece(k, v('length'), v('width')))
solved = solve(board, pieces)
if not solved:
print("No solution found for given input.")
else:
print("Solution found.")
board = solved
for u, position in solved.used_piece:
print(f"Piece ID: {u.id}, Position:{position}, Orientation: {u.orientation()}")

if __name__ == "__main__":
main()
``````

## encryption – I have a hex string and hex key, but I’m not sure how it was encrypted. It may be a puzzle

I found the following message written by a developer in a video game:

``````{"msg":{
"key": "0xa6",
"txt":"eb82e98cacc5b696e28aefcf9ce999eb8ee386a6e58ae78aeb85e184f6d6b9dfff8be386a6f585e487e2c296ff92f7d794fb95e188e693e68ba585c2a7c9acdebfd3bfc6e687a7c9a0c3a686e78be7caabd9b6c3adc9e98efb82ac"}}
``````

The “txt” string is obviously hexadecimal, and the key is only a single byte. I’ve tried the XOR cipher (and several others), but haven’t been able to get the bytes to decode to any legible string. I’ve tried all the common character encodings.

It’s a 91 byte array, and one interesting thing to note is that no byte is repeated more than 3 times, which leads me to believe it’s not a straight “byte to char” conversion and is most likely encrypted in some way (plus, I mean there’s a key).

As for the key itself, I’m unaware of many encryption algorithms that use 8 bit keys. I’ve tried using 0xA6 (166) as the ordinal position in the string, which curiously enough takes the final 16 characters of the message (c3adc9e98efb82ac) but I haven’t been able to find out what to do with that either.

## webassembly – N-Queens Puzzle in AEC

This is my solution to the N-Queens Puzzle.

Here is the AEC code (compiled to WebAssembly):

``````/*
* My solution to the n-queens puzzle, one of the classical problems of the
* structural programming. It asks in how many ways you can arrange n chess
* queens on an n-times-n chessboard without breaking the rules that no two
* chess queens can be in the same row, column or diagonal.
*/

// Import some functions we need to communicate with the outside world from
// JavaScript...
Function printString(CharacterPointer str)
Which Returns Nothing Is External;
Function clearScreen() Which Returns Nothing Is External;
Function shouldWePrintChessBoards() Which Returns Integer32 Is External;

// Declare the "Queen" structure and write relevant functions.
Structure Queen Consists Of
Integer32 row, column;
EndStructure

Function areQueensInTheSameColumn(QueenPointer first, QueenPointer second)
Which Returns Integer32 Does
Return first->column = second->column;
EndFunction

Function areQueensInTheSameRow(QueenPointer first, QueenPointer second)
Which Returns Integer32 Does
Return first->row = second->row;
EndFunction

Function areQueensOnTheSameDiagonal(QueenPointer first,
QueenPointer second)
Which Returns Integer32 Does
Return first->row + first->column = second->row + second->column or
first->row - first->column = second->row - second->column;
EndFunction

Function areQueensAttackingEachOther(QueenPointer first,
QueenPointer second)
Which Returns Integer32 Does
Return areQueensInTheSameRow(first, second) or
areQueensInTheSameColumn(first, second) or
areQueensOnTheSameDiagonal(first, second);
EndFunction

// Let's write a structure representing an array of queens...
Structure ChessBoard Consists Of
Integer32 length;
Queen queens(12); // There are too many solutions for over 12 queens.
EndStructure

Function chessBoardContainsThatQueen(ChessBoardPointer chessBoard,
QueenPointer queen)
Which Returns Integer32 Does
Integer32 i := 0;
While i < chessBoard->length Loop
If chessBoard->queens(i).column = queen->column and
chessBoard->queens(i).row    = queen->row    Then
Return 1;
EndIf
i += 1;
EndWhile
Return 0;
EndFunction

// Now, let's forward-declare the functions we will write later.
// Putting them here would make the code less legible.
Function recursiveFunction(ChessBoardPointer chessBoard,
Integer32 n) Which Returns Integer32 Is Declared;

Function convertIntegerToString(CharacterPointer str,
Integer32 n)
Which Returns Nothing Is Declared;

Function strcat(CharacterPointer dest,
CharacterPointer src) Which Returns Nothing Is Declared;

Function strlen(CharacterPointer str) Which Returns Integer32 Is Declared;

// Let's write the function that JavaScript is supposed to call...
Function nQueensPuzzle(Integer32 n) Which Returns Integer32 Does
clearScreen();
If n < 1 or n > 12 Then
printString("Please enter a number between 1 and 12!");
Return -1;
EndIf
InstantiateStructure ChessBoard chessBoard;
Character stringToBePrinted(64) := {0};
CharacterPointer stringToBePrinted := AddressOf(stringToBePrinted(0));
strcat(stringToBePrinted, "Solving the n-queens puzzle for ");
convertIntegerToString(stringToBePrinted + strlen(stringToBePrinted),
n);
strcat(stringToBePrinted,":n");
printString(stringToBePrinted);
Integer32 result := recursiveFunction(AddressOf(chessBoard), n);
stringToBePrinted(0) := 0;
strcat(stringToBePrinted, "Found ");
convertIntegerToString(stringToBePrinted + strlen(stringToBePrinted),
result);
strcat(stringToBePrinted, " solutions!");
printString(stringToBePrinted);
Return result;
EndFunction

// I guess moving this code out of "recursiveFunction" makes the
// code more legible.
Function printAsASolution(ChessBoardPointer chessBoard)
Which Returns Nothing Does
Character stringToBePrinted(64) := {0};
Character stringToBeAdded(8);
Integer32 i := 0;
While i < chessBoard->length Loop
stringToBeAdded(0) := 'A' + chessBoard->queens(i).column;
convertIntegerToString(AddressOf(stringToBeAdded(1)),
chessBoard->queens(i).row + 1);
strcat(AddressOf(stringToBeAdded(0)), " ");
strcat(AddressOf(stringToBePrinted(0)),
AddressOf(stringToBeAdded(0)));
i += 1;
EndWhile
strcat(AddressOf(stringToBePrinted(0)), "n");
printString(AddressOf(stringToBePrinted(0)));
If shouldWePrintChessBoards() Then
stringToBePrinted(0) := 0;
CharacterPointer stringToBePrinted := AddressOf(stringToBePrinted(0));
strcat(stringToBePrinted, "  +");
i := 0;
While i < chessBoard->length Loop
strcat(stringToBePrinted, "-+");
i += 1;
EndWhile
strcat(stringToBePrinted, "n");
printString(stringToBePrinted);
i := chessBoard->length;
While i > 0 Loop
stringToBePrinted(0) := 0;
// Align the row numbers to the right.
If i < 10 Then
strcat(stringToBePrinted, " ");
EndIf
convertIntegerToString(stringToBePrinted + strlen(stringToBePrinted), i);
strcat(stringToBePrinted, "|");
Integer32 j := 0;
While j < chessBoard->length Loop
InstantiateStructure Queen newQueen;
newQueen.column :=     j;
newQueen.row    := i - 1;
strcat(stringToBePrinted,
chessBoardContainsThatQueen(chessBoard, AddressOf(newQueen))?
"Q|":
mod(i + j - 1, 2)?
" |": // White field.
"*|"  // Black field.
);
j += 1;
EndWhile
strcat(stringToBePrinted, "n");
printString(stringToBePrinted);
stringToBePrinted(0) := 0;
strcat(stringToBePrinted, "  +");
j := 0;
While j < chessBoard->length Loop
strcat(stringToBePrinted, "-+");
j += 1;
EndWhile
strcat(stringToBePrinted, "n");
printString(stringToBePrinted);
i -= 1;
EndWhile
stringToBePrinted(0) := 0;
CharacterPointer stringToBeAdded := AddressOf(stringToBeAdded(0));
stringToBeAdded(2) := 0;
stringToBeAdded(0) := ' ';
strcat(stringToBePrinted, "  ");
i := 0;
While i < chessBoard->length Loop
stringToBeAdded(1) := 'A' + i;
strcat(stringToBePrinted, stringToBeAdded);
i += 1;
EndWhile
strcat(stringToBePrinted, "n");
printString(stringToBePrinted);
EndIf
EndFunction

// Now, let's implement the brute-force algorithm.
Function recursiveFunction(ChessBoardPointer chessBoard,
Integer32 n) Which Returns Integer32 Does
// First, do some sanity checks useful for debugging...
If chessBoard->length > n Then
printString("Bug: Chessboard length too large!");
Return 0;
EndIf
Integer32 i := 0, j := 0;
While i < chessBoard->length Loop
If chessBoard->queens(i).column < 0 or
chessBoard->queens(i).row    < 0 or
chessBoard->queens(i).column > n or
chessBoard->queens(i).row    > n Then
printString("Bug: Corrupt chessboard!");
Return 0;
EndIf
i += 1;
EndWhile
// Check if there is a contradiction (queens attacking
// each other) in what we have thus far...
i := j := 0;
While i < chessBoard->length Loop
j := i + 1;
While j < chessBoard->length Loop
If not(i = j) and areQueensAttackingEachOther(
AddressOf(chessBoard->queens(i)),
AddressOf(chessBoard->queens(j))
) Then
Return 0;
EndIf
j += 1;
EndWhile
i += 1;
EndWhile
// Check if this is a solution...
If chessBoard->length = n Then
printAsASolution(chessBoard);
Return 1;
EndIf
// If this is not a complete solution, but there are no contradictions
// in it, branch the recursion into searching for complete solutions
// based on this one.
Integer32 result := 0;
i := 0;
While i<n Loop
InstantiateStructure ChessBoard newChessBoard := ValueAt(chessBoard);
newChessBoard.length += 1;
newChessBoard.queens(chessBoard->length).column := chessBoard->length;
newChessBoard.queens(chessBoard->length).row := i;
result += recursiveFunction(AddressOf(newChessBoard), n);
i += 1;
EndWhile
Return result;
EndFunction

// Now go the helper functions related to string manipulation,
// copied from the Dragon Curve program. They are named the same
// as the corresponding functions in the standard C library.
Function strlen(CharacterPointer str) Which Returns Integer32 Does
Integer32 length := 0;
While ValueAt(str + length) Loop
length := length + 1;
EndWhile
Return length;
EndFunction

Function strcpy(CharacterPointer dest,
CharacterPointer src) Which Returns Nothing Does
While ValueAt(src) Loop
ValueAt(dest) := ValueAt(src);
dest          :=     dest + 1;
src           :=      src + 1;
EndWhile
ValueAt(dest) := 0;
EndFunction

Function strcat(CharacterPointer dest,
CharacterPointer src) Which Returns Nothing Does
strcpy(dest + strlen(dest), src);
EndFunction

Function reverseString(CharacterPointer string) Which Returns Nothing Does
CharacterPointer pointerToLastCharacter := string + strlen(string) - 1;
While pointerToLastCharacter - string > 0 Loop
Character tmp                   := ValueAt(string);
ValueAt(string)                 := ValueAt(pointerToLastCharacter);
ValueAt(pointerToLastCharacter) := tmp;
string                          := string + 1;
pointerToLastCharacter          := pointerToLastCharacter - 1;
EndWhile
EndFunction

Function convertIntegerToString(CharacterPointer string,
Integer32 number)
Which Returns Nothing Does
Integer32 isNumberNegative := 0;
If number < 0 Then
number           := -number;
isNumberNegative :=       1;
EndIf
Integer32 i := 0;
While number > 9 Loop
ValueAt(string + i) := '0' + mod(number, 10);
number              :=           number / 10;
i                   :=                 i + 1;
EndWhile
ValueAt(string + i) := '0' + number;
i                   :=        i + 1;
If isNumberNegative Then
ValueAt(string + i) :=   '-';
i                   := i + 1;
EndIf
ValueAt(string + i) := 0;
reverseString(string);
EndFunction
``````

Here is my HTML code:

``````<!DOCTYPE html>
<!-- See Arithmetic Operators Test for explanations.-->
<html lang="en">
<head>
<title>AEC-to-WebAssembly compiler - N-Queens Puzzle</title>
<style type="text/css">
body {
font-family: sans-serif;
}
#format_as_code {
font-family: "Lucida Console", monospace;
white-space: pre;
width: 100%;
background: #eeeeee;
height: 75vh;
display: block;
overflow: scroll;
}
h1 {
text-align: center;
}
</style>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<h1>N-Queens Puzzle</h1>
I have decided to write a solution to the
<a href="https://en.wikipedia.org/wiki/Eight_queens_puzzle">
N-Queens Puzzle</a
>, one of the classic problems in computer science, in the
<a href="https://flatassembler.github.io/AEC_specification.html"
>AEC programming language</a
>. That puzzle asks in how many ways you can arrange <i>n</i> chess queens
on an <i>n</i>-times-<i>n</i> chessboard without breaking the rules that no
two chess queens can be in the same row, column or diagonal.
<br />
<b>This only works in very modern browsers.</b> I'm not too interested in
targeting archaic browsers here. This only works in Firefox 62 and newer or
Chrome 69 and newer. After a few years (if not months), all JavaScript
environments will become as capable as they are, rather than like Internet
Explorer.<br /><br />
<form>
<label for="enterTheNumber"
>Enter the numberi <i>n</i> (between 1 and 12):</label
><br />
<input type="text" id="enterTheNumber" name="enterTheNumber" /><br />
<input
type="checkbox"
id="printChessBoards"
name="printChessBoards"
/><label for="printChessBoards">Print chess-boards using ASCII art</label>
</form>
<button onclick="invokeAECfunctions()">Invoke AEC program!</button
><br /><br />
AEC program output:<br />
<span id="format_as_code"></span>
<br />
You can see the source code of the AEC program
<a href="nQueensPuzzle.aec.html">here</a>.
<script type="text/javascript">
const stack_pointer = new WebAssembly.Global(
{ value: "i32", mutable: true },
0
);
let memory = new WebAssembly.Memory({ initial: 1 });
function printString(ptr) {
let buffer = new Uint8Array(memory.buffer);
let str = "";
while (buffer(ptr)) {
str += String.fromCharCode(buffer(ptr));
ptr++;
}
document.getElementById("format_as_code").innerHTML += str;
}
function clearScreen() {
document.getElementById("format_as_code").innerHTML = "";
}
function shouldWePrintChessBoards() {
return document.getElementById("printChessBoards").checked;
}
let importObject = {
JavaScript: {
stack_pointer: stack_pointer,
memory: memory,
printString: printString,
clearScreen: clearScreen,
shouldWePrintChessBoards: shouldWePrintChessBoards,
},
};
let nQueensPuzzle;
fetch("nQueensPuzzle.wasm")
.then((response) => response.arrayBuffer())
.then((bytes) => WebAssembly.instantiate(bytes, importObject))
.then((results) => {
const exports = results.instance.exports;
nQueensPuzzle = exports.nQueensPuzzle;
});
function invokeAECfunctions() {
let originalNumber = parseInt(
document.getElementById("enterTheNumber").value
);
nQueensPuzzle(originalNumber);
}
</script>
</body>
</html>
``````

You can (hopefully) see it live here: https://flatassembler.github.io/nQueensPuzzle.html

So, what do you think, how can I make it better?

## algorithms – Ordering puzzle problem- It is NP?

Suppose there are ‘n’ number of food items in a party.
f1 , f2 ….,fn.
In which order we eat them matters. Each ordering should contain all items included.
Some order in which I choose the food items may give me cancer.( there can be more than one such ordering).

Every food item is made and represented by three categories of ingredients: vegetables, spices and meat.

Set of types of vegetables: {a,b,c}.

Set of types of spices: {e,f,g}

Set of types of meat: {x,y,z}

Detecting Cancer: If all vegetables or spices or meat of any one type are eaten at the start or at the end before any another type, then that ordering is cancerous.

For example,
(1) f1 is made of {a,f,x} ;
f2 is made of {a,e,y} ;
f3 is made of {c,g,z} ;
f4 is made of {b,f,y} ;

a) ordering f1,f2,f3,f4:
Based on vegetables:{a,a,c,b} all a’s are eaten at the start, therefore this ordering is cancerous.
Based on spices:{f,e,g,f} , meat:{x,y,z,y} not cancerous as no type is continuously eaten at the start or end. Therefore, this order is cancerous based on vegetables.

b) ordering f1,f3,f2,f4:
Based on vegetables:{a,c,a,b} not cancerous ;
Based on spices:{f,g,e,f} not cancerous ;
Based on meat:{x,z,y,y} cancerous because all meat of type ‘y’ are eaten continuously at the end.

c) ordering f1,f2,f4,f3 :
Based on meat:{x,y,y,z} not cancerous(based on meat) because all meat of type ‘y’ are eaten in the middle, not at the start or end.
Based on vegetables:{a,a,b,c} all a’s are eaten at the start, therefore this ordering is cancerous.

There is a doctor at the party who can take a look at any given order (one at a time) and checks if it is cancerous or not (based on above conditions) in O(n).

Question 1: Can I detect if the given food items are given such that all orders are be cancerous?

Question 2: If somehow I find that there exist non-cancerous orders, how to make a cancerous order into non-cancerous order by swapping food items?

Question 3: Can I optimize the swappings in Question 2?

## encryption – Would confidential computing/hardware-based TEE be the missing security jigsaw puzzle to counter data exfiltration?

Is confidential computing/hardware-based trusted execution environment (TEE) the missing security jigsaw puzzle to counter data exfiltration?

Today, we already have data encrypted at rest and data encrypted in transit (TLS) widely adopted. However, “data encrypted in use” is still far and between.

Will data encrypted in use through confidential computing/hardware-based trusted execution environment (TEE) be the solution to data exfiltration?

## permutations – Food item-cancer puzzle problem

Suppose there are ‘n’ number of food items in a party.
f1 , f2 ….,fn.
In which order we eat them matters. Each ordering should contain all items included.
Some order in which I choose the food items may give me cancer.( there can be more than one such ordering).

Every food item is made and represented by three categories of ingredients: vegetables, spices and meat.

Set of types of vegetables: {a,b,c}.

Set of types of spices: {e,f,g}

Set of types of meat: {x,y,z}

Detecting Cancer: If all vegetables or spices or meat of any one type are eaten at the start or at the end before any another type, then that ordering is cancerous.

For example,
(1) f1 is made of {a,f,x} ;
f2 is made of {a,e,y} ;
f3 is made of {c,g,z} ;
f4 is made of {b,f,y} ;

a) ordering f1,f2,f3,f4:
Based on vegetables:{a,a,c,b} all a’s are eaten at the start, therefore this ordering is cancerous.
Based on spices:{f,e,g,f} , meat:{x,y,z,y} not cancerous as no type is continuously eaten at the start or end. Therefore, this order is cancerous based on vegetables.

b) ordering f1,f3,f2,f4:
Based on vegetables:{a,c,a,b} not cancerous ;
Based on spices:{f,g,e,f} not cancerous ;
Based on meat:{x,z,y,y} cancerous because all meat of type ‘y’ are eaten continuously at the end.

c) ordering f1,f2,f4,f3 :
Based on meat:{x,y,y,z} not cancerous(based on meat) because all meat of type ‘y’ are eaten in the middle, not at the start or end.
Based on vegetables:{a,a,b,c} all a’s are eaten at the start, therefore this ordering is cancerous.

There is a doctor at the party who can take a look at any given order (one at a time) and checks if it is cancerous or not (based on above conditions) in O(n).

Question 1: Can I detect if the given food items are given such that all orders are be cancerous?

Question 2: If somehow I find that there exist non-cancerous orders, how to make a cancerous order into non-cancerous order by swapping food items?

Question 3: Can I optimize the swappings in Question 2?

## Please review my new Puzzle blog

I am looking for an honest review of my Puzzle blog for kids here. Please have a look and share your thoughts:

Best Puzzle for kids