Skip to content

Instantly share code, notes, and snippets.

View draftcode's full-sized avatar

Masaya Suzuki draftcode

View GitHub Profile
delta(q0, a, q1).
delta(q1, a, q1).
delta(q1, a, q2).
delta(q1, b, q1).
delta(q2, b, q3).
ndfa(L) :- ndfa(q0, L, q3).
ndfa(Q, [], Q).
ndfa(Q0, [A|L], Q) :-
first([X|_], X).
second([_,X|_], X).
nth(1, [X|_], X).
nth(N, [_|L], X) :-
N > 1, N1 is N-1, nth(N1, L, X).
len([], 0).
len([_|L], N) :-
len(L, N1), N is N1+1.
fact(0, 1).
fact(N, F) :-
N > 0,
N1 is N-1,
fact(N1, F1),
F is N*F1.
fib(0, 0).
fib(1, 1).
fib(N, F) :-
arc(a1, v1, v2).
arc(a2, v2, v3).
arc(a3, v3, v4).
arc(a4, v4, v1).
arc(a5, v3, v5).
walk(U, U).
walk(U, V) :- arc(_, U, U1), walk(U1, V).
path(U, U, _, []).
write_siki(X) :-
atomic(X), write(X).
write_siki(X+Y) :-
write_siki(X), write(' と '),
write_siki(Y), write(' との和').
write_siki(X*Y) :-
write_siki(X), write(' と '),
write_siki(Y), write(' との積').
d(x, 1).
father(naoyuki, hyogo).
father(saburo, naoyuki).
father(saburo, shinji).
father(yoshihisa, hisako).
mother(hisako, hyogo).
mother(yoko, naoyuki).
mother(yoko, shinji).
mother(nobuko, hisako).
parent(P, C) :- father(P, C).
class Test {
public static void main(String[] args) {
Object[] array = new String[10];
Object o = array[0]; // OK
array[1] = new Integer(9); // Throw an ArrayStoreException.
}
}
.class test
.super java/lang/Object
.method public static main([LString;)V
.limit stack 10
.limit locals 2
iconst_5
istore_1
loop:
iinc 1 -1
#import <Foundation/Foundation.h>
@interface ClassA : NSObject
@end
@implementation ClassA
@end
@interface ClassB : NSObject
@end
#import <Foundation/Foundation.h>
@class A;
@protocol P
- (A*)f;
@end
@interface A : NSObject <P>
- (A*)f;