Skip to content

Instantly share code, notes, and snippets.

@mootoh
mootoh / gist:2766
Created July 27, 2008 08:37
バックトラック法による 8クイーンの解法
#
# exercise of backtracking algorithm.
# 2008.07.26
#
require 'pp'
# (x, y) のマスに置けるか
def test(x, y, board)
x.times do |i|
# 左
#!/usr/bin/env ruby
#
# knapsack problem solution by DP
#
# from:
# Cプログラマのためのアルゴリズムとデータ構造
# ISBN:4797304952
# pp. 349
#
# author:
#!/usr/bin/env ruby
#
# knapsack problem solution by backtracking.
#
# from:
# Cプログラマのためのアルゴリズムとデータ構造
# ISBN:4797304952
# pp. 348
#
# author:
Github T-shirts をいっしょに買って送料を節約しませんか?
2-200枚なら送料が一律 $11 だそうですよ。
http://rubyrags.com/products/10
東京近郊で渡せる方がよいです。
我もと思うかたは fork me.
@mootoh
mootoh / SortStringArray.m
Created August 30, 2008 22:39
snippet for sorting array of strings.
NSMutableArray *keys = [NSMutableArray arrayWithArray:[params allKeys]];
[keys sortUsingSelector:@selector(compare:)]; // compare: is a member of NSString.
/*
* hello world in Objective-C + Foundation framework.
*
* build:
* % cc -Wall -g -framework Foundation hello.m
*/
#import <Foundation/Foundation.h>
int main(int argc, char *argv[])
/*
* hello world in Objective-C + Foundation framework.
*
* build:
* % cc -Wall -g -framework Foundation hello.m
*/
#import <Foundation/Foundation.h>
int main(int argc, char *argv[])
/*
* compare [NSObject alloc] with malloc(sizeof(NSObject))
*
* build:
* cc -Wall -g -framework Foundation alloc_cost.m
*
* result:
* % ./a.out
* sizeof(NSObject)=4
* elapsed time of [NSObject alloc] = 0.235727
syn keyword CocoaClass NSString NSArray NSSet NSDictionary NSNumber NSInteger NSDate
syn keyword UIKitClass UIView UITableView UITableViewCell UINavigationController UIViewController UIApplication UITableViewController UIColor UIToolbar UIBarButtonItem
syn keyword CGStruct CGRect CGFloat
syn keyword CGMethod CGRectMake
HiLink CocoaClass objcType
HiLink UIKitClass objcType
HiLink CGStruct Type
HiLink CGMethod Function
@mootoh
mootoh / gcd.c
Created December 13, 2008 07:05
int gcd(int i, int j, int n)
{
while (i != j) {
if (i > j)
i -= j;
else
j -= i;
}
return i * n;
}