Skip to content

Instantly share code, notes, and snippets.

@plonk
plonk / aliquot.rb
Created November 18, 2015 03:59
アリコット数列を求めるプログラム
# アリコット数列を求めるプログラム
#
# アリコット数列はある項が前の項の真の約数の和になっているような数列で
# す。
#
# 276で始まるアリコット数列が有限かどうかはわかっていないらしいです。
require 'prime'
def aliquot_function(n)
@plonk
plonk / router-reconnect.rb
Created November 8, 2022 11:16
ルーターのping値が悪くなったらインターネットを再接続するスクリプト
#!/usr/bin/ruby
require 'net/http'
def router_online
puts "router_online"
uri = URI('http://192.168.0.1/hgi-bin/Setup/main_index.cgi')
req = Net::HTTP::Post.new(uri)
req.basic_auth('admin', 'qtnetbbiq')
req.set_form_data({
'o' => 'online',
@plonk
plonk / bfs.lisp
Created March 3, 2014 17:41
breadth-first search in Common Lisp
(setf (get 'A 'adjacent) '(B C)
(get 'B 'adjacent) '(A C D)
(get 'C 'adjacent) '(A B E)
(get 'D 'adjacent) '(B E F)
(get 'E 'adjacent) '(C D G)
(get 'F 'adjacent) '(D)
(get 'G 'adjacent) '(E))
(defun bfs (goal start)
(labels ((next-path (path)
@plonk
plonk / prim.lisp
Created August 4, 2022 20:03
プリム法による迷路作成
;; プリム法による迷路作成。
(defparameter *w* 10) ; 頂点グリッドの幅。
(defparameter *h* 10) ; 頂点グリッドの高さ。
(defparameter *adj* (make-array (* *w* *h*) :initial-element '())) ; 隣接配列。
(defparameter *cost* (make-array (* *w* *h*) :initial-element nil))
;; 印刷に使う文字。
(defconstant +floor-char+ #\・)
(defconstant +wall-char+ #\鬱)
@plonk
plonk / kruskal.lisp
Created August 4, 2022 18:28
クラスカル法による迷路作成
;; クラスカル法による迷路作成。
(defparameter *w* 10) ; 頂点グリッドの幅。
(defparameter *h* 10) ; 頂点グリッドの高さ。
(defparameter *edges* '()) ; 辺のリスト。
;; 印刷に使う文字。
(defconstant +floor-char+ #\・)
(defconstant +wall-char+ #\鬱)
;; 印刷する内容。
@plonk
plonk / reverse-delete.lisp
Last active August 4, 2022 10:57
逆削除法による迷路作成
;; 逆削除法による迷路作成。
(defparameter *w* 10) ; 頂点グリッドの幅。
(defparameter *h* 10) ; 頂点グリッドの高さ。
(defparameter *adj* (make-array (* *w* *h*) :initial-element '())) ; 隣接配列。
(defparameter *edges* '()) ; 辺のリスト。
;; 印刷に使う文字。
(defconstant +floor-char+ #\・)
(defconstant +wall-char+ #\田)
@plonk
plonk / pentomino.html
Created January 16, 2021 19:08
ペントミノパズルソルバー
<!doctype html>
<html lang=ja>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>ペントミノパズルソルバー</title>
<style>
table { border-spacing: 0; border-collapse: separate }
table.board-table { margin-bottom: 32px; }
table.board-table td { width: 32px; height: 32px; border: 3px solid #ccc; text-align: center; font-family: monospace }
@plonk
plonk / pentomino.rb
Last active January 16, 2021 12:07
ペントミノパズルソルバー
#!/usr/bin/ruby
require 'colorize'
COLOR_SCHEME = {
'F' => [:light_yellow, :light_black],
'I' => [:blue, :light_white],
'L' => [:yellow, :light_white],
'N' => [:light_yellow, :light_black],
'P' => [:cyan, :light_white],
@plonk
plonk / ping.c
Last active June 6, 2020 19:02
Simple ping
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>
#include <netdb.h>
@plonk
plonk / neko-chokin.rb
Created December 17, 2019 03:40
一年分の猫貯金チェックリストを印刷するためのエクセルファイルを生成するスクリプト
require 'spreadsheet'
year, filename = ARGV
if year
year = year.to_i
else
year = Time.now.year
end
unless filename
filename = "out.xls"