TEXTに投稿されたコード一覧

TEXT [Prolog]論理パズル/条件から住人と部屋の位置を推定する問題

:- op(700, xfx, ∈).
∈(X, Y) :- contains(Y, X).

contains([Val|_], Val).
contains([_|Tail], Val) :- contains(Tail, Val).

部分集合([], _).
部分集合([E|L], R) :- E ∈ R, 部分集合(L, R).
集合同値(L, R) :- 部分集合(L, R), 部分集合(R, L).

階層(Room, 0) :- Room ∈ [g, h, i].
階層(Room, 1) :- Room ∈ [d, e, f].
階層(Room, 2) :- Room ∈ [a, b, c].
右隣(a, b). 右隣(b, c).
右隣(d, e). 右隣(e, f).
右隣(g, h). 右隣(h, i).
左隣(L, R) :- 右隣(R, L).
隣(X, Y) :- 右隣(X, Y) ; 左隣(X, Y).
右側(X, Y) :- X ∈ [a, d, g], Y ∈ [b, c, e, f, h, i].
右側(X, Y) :- X ∈ [b, e, h], Y ∈ [c, f, i].
左側(X, Y) :- 右側(Y, X).
真下(a, d). 真下(b, e). 真下(c, f).
真下(d, g). 真下(e, h). 真下(f, i).
真上(D, U) :- 真下(U, D).
上階(X, Y) :- 階層(X, XRank), 階層(Y, YRank), XRank > YRank.

?-	A = [Akamatsu, Aoki, Kihara, Shirasawa, Kuroi, Haitani, Kaneco, Nobody0, Nobody1],
	右側(Haitani, Kuroi),
	上階(Kihara, Aoki),
	左隣(Akamatsu, _), 右隣(Akamatsu, _),
	左側(Kaneco, Aoki),
	隣(Kihara, Shirasawa),
	階層(Haitani, 2),
	隣(Kuroi, X1),
	隣(Akamatsu, X2),
	真上(Kaneco, X3),
	集合同値([X1, X2, X3], [Nobody0, Nobody1]),
	\+(真上(Aoki, Shirasawa)),
	\+(真下(Kihara, Akamatsu)),
	\+(隣(Kaneco, Shirasawa)),
	\+(隣(Haitani, Shirasawa)),
	集合同値(A, [a, b, c, d, e, f, g, h, i]).
/*

A:
[h,d,b,c,e,a,i, g,f]
[h,d,b,c,e,a,i, f,g]
[h,d,b,c,e,a,i, g,f]
[h,d,b,c,e,a,i, f,g]

すなわち
A: ハイタニ, B: キハラ,   C: シラサワ,
D: アオキ,   E: クロイ,   F: (空),
G: (空),     H: アカマツ, I: カネコ,
*/

TEXT [Prolog]各部分の和が等しいように輪を分割するパズル

append([], List, List).
append([Head|Tail], List, [Head|TailR]) :- append(Tail, List, TailR).

部分リスト(List, (I, I), []).
部分リスト(List, (0, End), SubList) :-
	number(End), End > 0, 部分リスト_(List, End, SubList).
部分リスト([Head|Tail], (Bgn, End), SubList) :-
	number(Bgn), Bgn > 0, Bgn1 is Bgn - 1,
	number(End), End > 0, End1 is End - 1,
	部分リスト(Tail, (Bgn1, End1), SubList).
部分リスト_(_, 0, []).
部分リスト_([Head|Tail], Cnt, [Head|TailAcc]) :-
	Cnt > 0, Cnt1 is Cnt - 1, 部分リスト_(Tail, Cnt1, TailAcc).

整数閉区間(L, L, R) :- L =< R.
整数閉区間(N, L, R) :- L =< R, L1 is L + 1, 整数閉区間(N, L1, R).

和([Head|Tail], Sum) :- 和_acc(Tail, Sum, Head).
和_acc([], Sum, SumAcc) :- Sum is SumAcc.
和_acc([Head|Tail], Sum, SumAcc) :- 和_acc(Tail, Sum, Head + SumAcc).

弧(List, (I, I), []).
弧(List, (0, End), Arc) :- 部分リスト(List, (0, End), Arc).
弧(List, (Bgn, 0), Arc) :- length(List, N), 部分リスト(List, (Bgn, N), Arc).
弧(List, (Bgn_, End_), Arc) :-
	number(Bgn_), number(End_), Bgn_ =\= 0, End_ =\= 0,
	length(List, N),
	Bgn is ((Bgn_ mod N) + N) mod N,	% 非負最小剰余
	End is ((End_ mod N) + N) mod N,
	( Bgn < End
		->	部分リスト(List, (Bgn, End), Arc)
		;	弧(List, (Bgn, 0), ArcLead), 部分リスト(List, (0, End), ArcTrail),
			append(ArcLead, ArcTrail, Arc)
	).

輪の等和分割(List, [X|Answer], Div) :-
	和(List, ListSum), ArcSum is ListSum / Div,
	length(List, N),
	整数閉区間(X, 0, N),	% 第一の切断点(の右)
	輪の等和分割(List, [X|Cut], Div, ArcSum, N, N),
	append(Answer, [X], Cut).

輪の等和分割(_, [_], 0, _, _, 0).
輪の等和分割(List, [Bgn, End|Cut], Div, Sum, LenFull, LenRemain) :-
	整数閉区間(Len, 1, LenRemain), End is (Bgn + Len) mod LenFull,
	弧(List, (Bgn, End), Arc),
	和(Arc, Sum),
	Div1 is Div - 1, LenRemain1 is LenRemain - Len,
	輪の等和分割(List, [End|Cut], Div1, Sum, LenFull, LenRemain1).

% 例題
	?- 輪の等和分割( [1, 12, 5, 8, 10, 3, 11, 9, 6, 7, 4, 2], Answer, 3 ).
/*
Answer = [2,6,9].	% つまり 5, 11, 7 の左側 B, F, I で切断する
*/

% ---------------------
% おまけ:特殊バージョン (3分割、数値に重複がないことが条件)
between(L, L, R) :- L < R.
between(N, L, R) :- L < R, L1 is L + 1, between(N, L1, R).

隣接(1, 12). 隣接(12, 5). 隣接(5, 8). 隣接(8, 10). 隣接(10, 3). 隣接(3, 11).
隣接(11, 9). 隣接(9, 6). 隣接(6, 7). 隣接(7, 4). 隣接(4, 2). 隣接(2, 1).

区間(X, R) :- 隣接(X, R) ; (X \== R, 隣接(R1, R), 区間(X, R1)).

弧和(X, R, Sum) :- 区間(X, R), 弧和_acc(X, R, Sum, 0).
弧和_acc(X, X, Sum, SumAcc) :- !, Sum is SumAcc.
弧和_acc(X, R, Sum, SumAcc) :- 隣接(X, X1), 弧和_acc(X1, R, Sum, SumAcc + X).

3分割( [X, Y, Z], Sum ) :-
	between(X, 1, 13),
	弧和(X, Y, Sum), 弧和(Y, Z, Sum), 弧和(Z, X, Sum).

?- Sum is ((12*(12 + 1))/2) / 3, 3分割(A, Sum).
% A = [5,11,7]	% B, F, I

TEXT [Prolog]魔法陣<4×4> (入る値が与えられている場合)

% 4×4 行列分解
groups_4x4(
	[
		[M00, M01, M02, M03],	% 行ベクトルのリスト
		[M10, M11, M12, M13],
		[M20, M21, M22, M23],
		[M30, M31, M32, M33]
	], [
		[M00, M10, M20, M30],	% 列ベクトルのリスト
		[M01, M11, M21, M31],
		[M02, M12, M22, M32],
		[M03, M13, M23, M33]
	],
	[ M00, M11, M22, M33 ],		% 主対角線 (左上→右下)
	[ M30, M12, M21, M03 ],		%  対角線 (左下←右上)
	[ M00, M01, M02, M03,
	  M10, M11, M12, M13,
	  M20, M21, M22, M23,
	  M30, M31, M32, M33 ]	% 全成分のリスト
).

% addelem(S, E, S2): 集合Sに元Eを加えたものが、集合S2に等しいこと (ただし、主に S2 から E を取り除くために使う)
addelem(E, Set, [E|Set]).
addelem(E, [X|Set1], [X|Set2]) :- addelem(E, Set1, Set2).

% 多重集合の部分集合 '⊆'
multi_subset([], Rhs).
multi_subset([E|LhsTail], Rhs) :- addelem(E, Rhs1, Rhs), multi_subset(LhsTail, Rhs1).
multi_set_eq(L, R) :- multi_subset(L, R), multi_subset(R, L).	% 集合 '=' :⇔ '⊆' ∧ '⊇'

% 総和 Σ (sum(L, S): リストLの元の総和が数値Sumに等しい)
sum([Head|Tail], Sum) :- sum_acc(Tail, Sum, Head).
sum_acc([], Sum, Sum).
sum_acc([Head|Tail], Sum, SumAcc) :- SumAcc2 is SumAcc + Head, sum_acc(Tail, Sum, SumAcc2).

% 魔法陣
magic_matrix_4x4(M, A, Src) :-
	sum(Src, SumSrc), Sum is SumSrc / 4,
	M = A,
	M = [Row0, Row1, Row2, Row3],
	groups_4x4( M, [Clm0, Clm1, Clm2, Clm3], DiagL, DiagR, Flat ),
	magic_matrix_4x4_( [
		DiagL, DiagR,
		Row0, Row1, Row2, Row3,
		Clm0, Clm1, Clm2, Clm3 %,
	], Sum, Src ),
	multi_set_eq(Flat, Src).	% 成分列が Src の順列になること

magic_matrix_4x4_( [], _, _ ).
magic_matrix_4x4_( [Head|Tail], Sum, Src ) :-
	multi_subset(Head, Src),
	sum(Head, Sum),
	magic_matrix_4x4_(Tail, Sum, Src).

% 例題
?- magic_matrix_4x4( [
		[_, 18, _, _],
		[7, _, _, 10],
		[_, _, 9, _],
		[_, 5, _, _]
	], A, [2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 16, 17, 18, 19] ).

% A = [[6,18,17,2],[7,12,14,10],[11,8,9,15],[19,5,3,16]] (唯一解)

TEXT [Prolog]魔法陣 (入る値が与えられている場合)

append([], List, List).
append([Head|Tail], List, [Head|TailR]) :- append(Tail, List, TailR).

at([Val|Tail], 0, Val).
at([Head|Tail], Idx, Val) :- number(Idx), Idx > 0, Idx1 is Idx - 1, at(Tail, Idx1, Val).

% 平坦化 (リストのリスト(2次配列)を、リストの垣根を崩して1次元配列にする)
flatten( Matrix, List ) :- flatten_acc( Matrix, List, [] ).
flatten_acc( [], List, List ).
flatten_acc( [Head|Tail], List, ListAcc ) :- append( ListAcc, Head, ListAcc2 ), flatten_acc( Tail, List, ListAcc2 ).

% 行列
matrix([[Val]]).
matrix([H|Tail]) :- list(H), length(H, CntColumns), matrix_(Tail, CntColumns).

matrix_([X|[]], CntColumns) :- list(X), length(X, CntColumns).
matrix_([H|Tail], CntColumns) :- list(H), length(H, CntColumns), matrix_(Tail, CntColumns).

matrix_size([H|Tail], (X, Y)) :- matrix([H|Tail]), length([H|Tail], X), length(H, Y).

% 対角成分
main_diag(M, L) :- matrix_size(M, (N, N)), diag_(M, L, 0, 1).
 sub_diag(M, L) :- matrix_size(M, (N, N)), Idx is N - 1, diag_(M, L, Idx, -1).

diag_( [], [], _, _ ).
diag_( [Row|TailRows], [H|T], Idx, Step ) :- at(Row, Idx, H), Idx1 is Idx + Step, diag_( TailRows, T, Idx1, Step ).

% 列ベクトル
columns(M, Idx, List) :- number(Idx), columns_acc(M, Idx, List, []).
columns_acc([], Idx, List, List).
columns_acc([Row|MTail], Idx, List, ListAcc) :- at(Row, Idx, Val), append(ListAcc, [Val], ListAcc2), columns_acc( MTail, Idx, List, ListAcc2 ).

% 転置行列
transpose([], []).
transpose(M, Mt) :- matrix_size(M, (N, N)), transpose_( M, Mt, 0 ).
transpose_(M, [Head|Tail], Idx) :-
	number(Idx), Idx >= 0,
	columns(M, Idx, Head), Idx1 is Idx + 1,
	( length(M, Idx1) -> Tail = [] ; transpose_(M, Tail, Idx1) ).

% 集合操作
elem(E, [E|Others]).			% '∈'
elem(E, [_|Others]) :- elem(E, Others).

addelem(E, Set, [E|Set]).		% a.k.a. select
addelem(E, [X|Set1], [X|Set2]) :- addelem(E, Set1, Set2).

% 多重集合の部分集合 '⊆'
multi_subset([], Rhs).
multi_subset([E|LhsTail], Rhs) :- addelem(E, Rhs1, Rhs), multi_subset(LhsTail, Rhs1).

multi_set_eq([], []).
multi_set_eq([E|LhsTail], Rhs) :- addelem(E, Rhs1, Rhs), multi_set_eq(LhsTail, Rhs1).

% 総和 Σ
sum([Head|Tail], Sum) :- sum_acc(Tail, Sum, Head).
sum_acc([], Sum, SumAcc) :- Sum is SumAcc.
sum_acc([Head|Tail], Sum, SumAcc) :- sum_acc(Tail, Sum, Head + SumAcc).

% 魔法陣
magic_matrix(M, A, Src) :- matrix_size(M, (N, N)),
	M = A,
	sum(Src, SumSrc), Sum is SumSrc / N,	% 総和が実数で求まる
	transpose(A, T), main_diag(A, DiagL), sub_diag(A, DiagR),
	append( A, T, P0 ), append( [DiagL, DiagR], P0, P ),	% P : 和が Sum になるリストのリスト
%	write(P), nl,
	magic_lists(P, Sum, Src),
	flatten(A, Flat), multi_set_eq(Flat, Src).	% 成分列が Src の順列になること

magic_lists([], _, _).
magic_lists([Head|Tail], Sum, Src) :-
	multi_subset(Head, Src),
	sum(Head, Sum),
%	write(Head), nl,
	magic_lists(Tail, Sum, Src).

% 例題
?- magic_matrix( [
		[_, 18, _, _],
		[7, _, _, 10],
		[_, _, 9, _],
		[_, 5, _, _]
	], A, [2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 16, 17, 18, 19] ).

/*
A = [[6,18,17,2],[7,12,14,10],[11,8,9,15],[19,5,3,16]]	% (唯一解; 約8秒)
*/

TEXT [Prolog]十字型にライトをスイッチしてすべてのライトを点けるパズル

% 0 = 点灯(on), 1 = 消灯(off)とする。
% 解答として、すべて点灯させるためにスイッチすべきライトの成分のリストを返す。

% リスト・行列に関する諸述語
append( [], List, List ).
append( [Head|Tail], List, [Head|TailR] ) :- append(Tail, List, TailR).

at( [Head|Tail], 0, Head ).
at( [Head|Tail], Idx, Val ) :- number(Idx), Idx > 0, Idx1 is Idx - 1, at( Tail, Idx1, Val ).

at( [Head|Tail], (0, Y), Val ) :- at(Head, Y, Val).
at( [Head|Tail], (X, Y), Val ) :- X > 0, X1 is X - 1, at( Tail, (X1, Y), Val ).

reverse( [], [] ).
reverse( [Head|Tail], Reversed ) :- reverse( Tail, Remains ), append( Remains, [Head], Reversed ).

zero_list([]).
zero_list([0|Tail]) :- zero_list(Tail).
zero_matrix([]).
zero_matrix([Head|Tail]) :- zero_list(Head), zero_matrix(Tail).

between(L, L, R) :- L < R.
between(N, L, R) :- L < R, L1 is L + 1, between(N, L1, R).

% マンハッタン距離
abs( X, A ) :- number(X), X >= 0 -> A is X ; A is -X.
manhattan_distance( (Ax, Ay), (Bx, By), D ) :-
	X is Ax - Bx, abs( X, Dx ),
	Y is Ay - By, abs( Y, Dy ),
	D is Dx + Dy.

% 成分の順序 (辞書式順序)
positionLess( (X1, _), (X2, _) ) :- X1 < X2.
positionLess( (X, Y1), (X, Y2) ) :- Y1 < Y2.

% パズル
light_switch_pazzle( Q, A ) :- light_switch_pazzle( Q, A, (0, 1000) ).	% 省略引数
light_switch_pazzle( Q, A, (MinLv, MaxLv) ) :-
	length(Q, M), Q = [QHead|_], length(QHead, N),
	between(Limit, MinLv, MaxLv),		% 反復深化
%	write(Limit), nl,
	light_switch_pazzle_acc( (0, Limit), Q, (M, N), ARev, [] ),
	reverse(ARev, A).

light_switch_pazzle_acc( (Limit, Limit), Board, _, Path, Path ) :-
	zero_matrix(Board).
light_switch_pazzle_acc( (Lv, Limit), Board1, (M, N), A, Path ) :-
	Lv < Limit, Lv1 is Lv + 1,
	between(X, 0, M),
	between(Y, 0, N),
	( Path = [] ; Path = [PrevPath|_], positionLess( PrevPath, (X, Y) ) ),	% 順番違いの解を排除 (成分列を単調増加に限定する)
	light_switch( Board1, Board2, (X, Y) ),
	light_switch_pazzle_acc( (Lv1, Limit), Board2, (M, N), A, [(X, Y)|Path] ).

% 成分(X, Y)および上下左右(マンハッタン距離1以下)がスイッチした行列
light_switch( Board1, Board2, (X, Y) ) :-
	light_switch_matrix_( Board1, Board2, (X, Y), (0, 0) ).

light_switch_matrix_( [], [], _, _ ).
light_switch_matrix_( [Head1|Tail1], [Head2|Tail2], Point, (X, 0) ) :-
	light_switch_list_( Head1, Head2, Point, (X, 0) ),
	X1 is X + 1,
	light_switch_matrix_( Tail1, Tail2, Point, (X1, 0) ).

light_switch_list_( [], [], _, _ ).
light_switch_list_( [Head1|Tail1], [Head2|Tail2], Point, (X, Y) ) :-
	manhattan_distance( Point, (X, Y), D ),
	( D =< 1 -> Head2 is (1 - Head1); Head1 = Head2 ),
	Y1 is Y + 1,
	light_switch_list_( Tail1, Tail2, Point, (X, Y1) ).

% 例題
% 問題文で「最短4手」と明言されているので、実際は4手の解を探すだけで十分。
?- light_switch_pazzle( [
	[ 1, 0, 1, 1 ],
	[ 0, 0, 1, 0 ],
	[ 1, 1, 0, 1 ],
	[ 1, 0, 1, 1 ] ], Answer ).
/*
Answer:
[(0,0),(0,2),(2,0),(3,3)]	 % 最短
[(0,0),(0,3),(1,1),(2,1),(2,3),(3,1)]
[(0,0),(1,1),(1,2),(1,3),(3,0),(3,2)]
[(0,1),(1,1),(1,3),(2,0),(2,2),(2,3)]
[(0,2),(1,0),(1,1),(2,2),(3,1),(3,2)]
[(0,0),(0,1),(0,3),(1,0),(1,2),(2,1),(3,0),(3,3)]
[(0,0),(0,1),(1,0),(1,3),(2,3),(3,1),(3,2),(3,3)]
[(0,1),(0,2),(0,3),(1,3),(2,1),(2,2),(3,1),(3,3)]
[(0,1),(0,2),(1,2),(2,2),(2,3),(3,0),(3,2),(3,3)]
[(0,3),(1,0),(2,0),(2,1),(2,2),(2,3),(3,2),(3,3)]
[(1,0),(1,2),(1,3),(2,0),(2,2),(3,0),(3,1),(3,3)]
...
*/

TEXT 特定のマスを特定の歩数目で踏んで迷路を抜けるパズル

append( [], List, List ).
append( [Head|Tail], List, [Head|TailR] ) :- append(Tail, List, TailR).

at( [Head|Tail], (0, Y), Val ) :- at(Head, Y, Val).
at( [Head|Tail], (X, Y), Val ) :- X > 0, X1 is X - 1, at( Tail, (X1, Y), Val ).

at( [Head|Tail], 0, Head ).
at( [Head|Tail], Idx, Val ) :- number(Idx), Idx > 0, Idx1 is Idx - 1, at( Tail, Idx1, Val ).
	?- at( [[1,2,3],[4,5],[6,7]], (0,2), 3 ).

% ルール
walk_maze(Q, A) :-
	Q = A,
	length(Q, M), Q = [H|_],
	length(H, N),
	walk_maze( Q, A, (M, N), (0, 0), 1 ).	% 左上を入口として入る

walk_maze( _, _, (M, N),      _, StepEnd ) :- StepEnd is M * N.
walk_maze( Q, A, (M, N), (X, Y), Step ) :-
%	number(M), number(N), number(X), number(Y), number(Step),
	0 =< X, X < M, 0 =< Y, Y < N,
	at( Q, (X, Y), Step ),
	StepNext is Step + 1,
	(	% 次の一歩
		X1 is X - 1, walk_maze( Q, A, (M, N), (X1, Y), StepNext );
		Y1 is Y - 1, walk_maze( Q, A, (M, N), (X, Y1), StepNext );
		X2 is X + 1, walk_maze( Q, A, (M, N), (X2, Y), StepNext );
		Y2 is Y + 1, walk_maze( Q, A, (M, N), (X, Y2), StepNext )
	).

% 例題
	?- walk_maze( [
		[ 1, _, _, _, _, 36 ],
		[ _, _, _, _, _, _ ],
		[ _, _, _, _, _, _ ],
		[ _, 9, _,27, _, _ ],
		[ _,18, _, _, _, _ ],
		[ _, _, _, _, _, _ ] ], Answer ).
/*
Answer = [
	[  1,  2,  3,  4, 35, 36 ],
	[ 12, 11,  6,  5, 34, 33 ],
	[ 13, 10,  7, 28, 29, 32 ],
	[ 14,  9,  8, 27, 30, 31 ],
	[ 15, 18, 19, 26, 25, 24 ],
	[ 16, 17, 20, 21, 22, 23 ]
]
*/

TEXT CountLFSR.vhd

library IEEE;
use IEEE.std_logic_1164.all;

package SUB_PACK is

function m_gen(
	D : integer
)
return std_logic_vector;

end;

package body SUB_PACK is

function m_gen(
	D : integer
)
return std_logic_vector is
variable TMP : std_logic_vector(15 downto 0);
begin
	TMP := X"0001";
	for I in 1 to D loop
		TMP := (TMP(7) xor TMP(0)) & TMP(15 downto 1);
	end loop;
	return TMP;
end;

end SUB_PACK;

library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
use work.SUB_PACK.all;

entity CountLFSR is
port(
	RST, CLK : in std_logic;
	UP : out std_logic
);
end;

architecture RTL of CountLFSR is

signal count : std_logic_vector(15 downto 0);
signal count_up : std_logic;

begin

	process(RST, CLK) begin
		if(RST='0') then
			count <= X"0001";
		elsif(CLK'event and CLK='1') then
			if(count_up='1') then
				count <= X"0001";
			elsif(count_up='0') then
				count <= (count(7) xor count(0)) & count(15 downto 1);
			end if;
		end if;
	end process;

-- そのままだとよく分からない値を指定する必要がある
--	count_up <= '1' when count=X"8040" else '0';
-- m_gen()使用で20000カウントというのが分かりやすい
	count_up <= '1' when count=m_gen(20000) else '0';

	UP <= count_up;

end RTL;

TEXT excelデータをplistに変換用エクセルVBA

Sub main()

    'iOS用でエクセルファイルをplistで読み込むためのExcelVBAファイル

    'xml用変数
    Dim xmlDoc          As MSXML.DOMDocument                'XMLドキュメント
    Dim xmlPI           As IXMLDOMProcessingInstruction     'XML宣言
    Dim node(4)         As IXMLDOMNode                      '要素
    Dim plist_node(2)   As IXMLDOMNode                      '要素
    Dim attr            As MSXML.IXMLDOMAttribute           '属性

    'セルからのデータ取得用変数
    Dim file_name       As Variant  'File_Name
    Dim xml_des         As Variant  'XML_Description
    Dim name            As Variant  'Marker_Name
    Dim snip            As Variant  'Snippet
    Dim des             As Variant  'Marker_description
    Dim lat             As Variant  'latitude
    Dim lng             As Variant  'longitude

    Dim str             As String   'HTML記述
    Dim imgWidh         As String   '画像の横幅

    Dim max             As Integer  '読み込む店舗数の最大値
    Dim j               As Integer  'ForLoop Nest用
    Dim jMax            As Integer  '横方向ループ処理

    '変数の初期化
    max = 21
    j = 1
    jMax = 3
    imgWidth = " width=" & 3
    imgWidth02 = " width=" & 5

    'table用変数
    'border = " border=" & "0"
    'cellspacing = " cellspacing=" & "0"
    cellpadding = " cellpadding=" & "1"

   'XMLドキュメントを作成します。
    Set xmlDoc = New MSXML.DOMDocument

    'XML宣言を追加します。
    Set xmlPI = xmlDoc.appendChild(xmlDoc.createProcessingInstruction("xml", "version=""1.0"" encoding=""UTF-8"""))

    'XML宣言を追加します。
    Set xmlPI = xmlDoc.appendChild(xmlDoc.createProcessingInstruction("plist", "version=""1.0"""))

    '<dict>要素の宣言を追加します。
    Set node(1) = xmlDoc.appendChild(xmlDoc.createNode(NODE_ELEMENT, "dict", ""))

    For i = 2 To max '=125
        des01 = Cells(i, j)     'NSArrayの中身(オブジェクト) : Cell(行,列)
        str = des01

        If i = 2 Then
            '<key>要素を追加します。
            Set node(2) = node(1).appendChild(xmlDoc.createNode(NODE_ELEMENT, "key", ""))
             node(2).Text = Cells(1, j)
            '<array>要素を追加します。
            Set node(2) = node(1).appendChild(xmlDoc.createNode(NODE_ELEMENT, "array", ""))
        Else
        End If

        'dictionary要素ここから------------
        '<string>要素を追加します。

        Set node(3) = node(2).appendChild(xmlDoc.createNode(NODE_ELEMENT, "string", ""))
        node(3).Text = str
        'ここまで------------

        'ネストここから------------
        If i = max Then
            i = 1

            If j < jMax Then
                j = j + 1
            Else
                i = max
            End If
        Else
        End If
        '----------------------------------

    Next

    'XML
    'ドキュメントの出力
    xmlDoc.Save ("\\vmware-host\Shared Folders\デスクトップ\\popup_db.xml")

End Sub

TEXT DDSで50MHzから約1789772.5Hzを生成する

/*
 50MHzから約1789772.5Hzを生成する
 加算値 63  しきい値 1697  誤差 0.254272Hz
*/

circuit DDS_50to17897725
{
	sel max<12>, add<6>;
	reg_wr count<12>;
	instrout run;
	sel sa<12>;

	par{
		add = 0b111111;
		max = 0x6A1;

		sa = count - max;
		if(sa<11>){ // count < max
			count += (0b000000 || add);
		}
		else{
			count := sa;
			run();
		}
	}
}

TEXT 同期DPRAM

module dpram_8x512 (
	p_reset, m_clock, radrs, wadrs, din, dout, write, read
);

input p_reset, m_clock;
input [8:0] radrs, wadrs;
input [7:0] din;
output [7:0] dout;
reg [7:0] dout_reg;
input write, read;

	reg [7:0] cells [0:511];

	assign dout = dout_reg;

	always @(posedge m_clock) begin
		if(read) dout_reg <= cells[radrs];
	end

	always @(posedge m_clock) begin
		if(write) cells[wadrs] <= din;
	end

endmodule
Total Pages: 3 / 512345

よく投稿されているコード

タグ

最近投稿されたコード