Skip to content

Instantly share code, notes, and snippets.

View mryoshio's full-sized avatar

YOSHIOKA A mryoshio

View GitHub Profile
@mryoshio
mryoshio / hash_map.cpp
Created May 27, 2013 16:35
Hashmap sample
#include <iostream>
#include <string>
using namespace std;
typedef struct {
string english;
string japanese;
} WORDSET;
@mryoshio
mryoshio / simple_search.cpp
Created June 17, 2013 13:35
string simple search algorithm
#include <iostream>
#include <string>
using namespace std;
unsigned char original_text[] = "Team Swift";
unsigned char original_pattern[] = "if";
unsigned char *simple_search(unsigned char* text, unsigned char* pattern) {
int i;
@mryoshio
mryoshio / kmp_search.cpp
Created June 17, 2013 13:46
KMP algorithm
#include <iostream>
#include <string>
using namespace std;
#define PATTERN_LENGTH 13
unsigned char original_text[] = "a eighty-eighty-eighth key";
unsigned char original_pattern[] = "eighty-eighth";
@mryoshio
mryoshio / bm_search.cpp
Created June 17, 2013 13:47
BM algorithm
#include <iostream>
#include <string>
using namespace std;
#define PATTERN_LENGTH 12
unsigned char original_text[] = "List<Event> events = EventService.get().search(query, category, sortOrder, Boolean.parseBoolean(beforeDeadlineOnly), maxNum);";
unsigned char original_pattern[] = "parseBoolean";
@mryoshio
mryoshio / eight_queen.cpp
Created June 19, 2013 16:32
Eight Queens Puzzle
#include <iostream>
using namespace std;
int board[8][8];
int check(int x, int y) {
int p, q;
for (p = 0; p < x; p++)
@mryoshio
mryoshio / scope_error.rb
Last active December 18, 2015 21:59
scope error sample
a = 'found!'
class ScopeTest
puts a
def my_method
puts a
end
@mryoshio
mryoshio / scope_error2.rb
Created June 24, 2013 15:32
scope error sample2
a = 'found!'
ScopeTest = Class.new do
puts a
def my_method
puts a
end
@mryoshio
mryoshio / scope_ok.rb
Created June 24, 2013 15:35
scope ok sample
a = 'found!'
ScopeTest = Class.new do
puts a
define_method :my_method do
puts a
end
@mryoshio
mryoshio / ten_puzzle.cpp
Created July 4, 2013 15:52
ten puzzle (practice of stack, backtracking)
#include <iostream>
#define STACK_SIZE 10
//#define DEBUG
using namespace std;
typedef struct t_fraction {
int numerator;
int denominator;
@mryoshio
mryoshio / use_state_machine.rb
Last active December 19, 2015 11:29
use state_machine
# sample class
class Book < ActiveRecord::Base
attr_accessible :author, :status, :title
state_machine :status, :initial => :draft do
state :draft, :public, :suspending, :archived
state :draft do
def published?; false end