Skip to content

Instantly share code, notes, and snippets.

@firephil
firephil / NQueen.scala
Created March 11, 2021 22:31 — forked from pathikrit/NQueen.scala
O(n!) solution to the n-Queen puzzle (https://en.wikipedia.org/wiki/Eight_queens_puzzle)
/**
* Solves the n-Queen puzzle in O(n!)
* Let p[r] be the column of the queen on the rth row (must be exactly 1 queen per row)
* There also must be exactly 1 queen per column and hence p must be a permuation of (0 until n)
* There must be n distinct (col + diag) and n distinct (col - diag) for each queen (else bishop attacks)
* @return Vector p of length n such that p[i] is the column of the queen on the ith row in a solution
*/
def nQueens(n: Int) =
(0 until n)
.permutations
@firephil
firephil / nqueen.scala
Created March 11, 2021 22:26 — forked from ornicar/nqueen.scala
solution to the n-queens problem based on "Programming in Scala"
// Solves the n-queens problem for an arbitrary board size
// Run for a board size of ten: scala nqueen.scala 10
object Nqueen {
type Queen = (Int, Int)
type Solutions = List[List[Queen]]
def main(args: Array[String]) {
val size: Int = args match {
case Array() => sys.error("Provide a board size")
case Array(n) => n.toInt
@firephil
firephil / AutoCompleteTextBox.java
Created February 26, 2018 23:19 — forked from floralvikings/AutoCompleteTextBox.java
Simple JavaFX TextBox with AutoComplete functionality based on a supplied set.
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Side;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.CustomMenuItem;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
@firephil
firephil / JavaFXTrayIconSample.java
Created October 25, 2016 16:40 — forked from jewelsea/JavaFXTrayIconSample.java
Demonstrate using the System Tray (AWT) to control a JavaFX application.
import javafx.application.*;
import javafx.geometry.Pos;
import javafx.scene.*;
import javafx.scene.control.Label;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.stage.*;
import javax.imageio.ImageIO;
import java.io.IOException;
## Configure eth0
#
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
NM_CONTROLLED="yes"
ONBOOT=yes
HWADDR=A4:BA:DB:37:F1:04
TYPE=Ethernet
BOOTPROTO=static
package portScan
object Run extends App {
(21 to 22).par.map { case port =>
try {
val socket = new java.net.Socket("192.168.1.1", port)
socket.close()
println(port)