This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def word_to_hash(word) | |
primes = { | |
'a' => 2, 'b' => 3, 'c' => 5, 'd' => 7, 'e' => 1, 'f' => 13, 'g' => 17, | |
'h' => 19, 'i' => 23, 'j' => 29, 'k' => 31, 'l' => 37, 'm' => 41, | |
'n' => 43, 'o' => 47, 'p' => 51, 'q' => 53, 'r' => 59, 's' => 61, | |
't' => 67, 'u' => 71, 'v' => 73, 'w' => 79, 'x' => 83, 'y' => 97, | |
'z' => 101 | |
} | |
sum = 1 | |
word.split('').each{|ch| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.cornerofseven.android.lwp.paint; | |
import android.graphics.Paint; | |
import android.hardware.SensorManager; | |
import android.service.wallpaper.WallpaperService; | |
import android.view.SurfaceHolder; | |
/** | |
* PaintService | |
* Basic setup to create an Android Live Wallpaper. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PaintEngine extends Engine implements SensorEventListener { | |
private final Paint[] mCardinalPaints = new Paint[4]; | |
private final Runnable mDrawWP = new Runnable(){ | |
public void run() { | |
drawFrame(); | |
} | |
}; | |
private SensorManager mSensMgr = | |
(SensorManager) getSystemService(SENSOR_SERVICE); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~ form_for(@race) do |f| | |
~ if @race.errors.any? | |
#error_explanation | |
%h2 #{pluralize(@race.errors.count, "error")} prohibited this race from being saved: | |
%ul | |
~@race.errors.full_messages.each do |msg| | |
%li= msg | |
.field | |
=f.label :name | |
%br |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fizzbuzz | |
fifteens = temp = 0 | |
0.upto(1000).collect do |x| | |
fifteens += x if x % 15 == 0 | |
temp += x if ((x % 3 == 0) ^ (x % 5 == 0)) | |
end | |
puts "Single fifteens: #{temp + fifteens}" | |
puts "Double fifteens: #{temp + (fifteens * 2)}" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mathn' | |
# Generates a list of primes below a given value | |
def primelist(n) | |
k = 1 | |
a = [2,3] | |
while 6*k < n | |
a.push(6*k-1) | |
a.push(6*k+1) | |
k += 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#adds the diagonals of a number spiral (where 1 is center) | |
def spiral(n) | |
sum = 1 | |
max = n**2 | |
corner = 1 | |
step = 2 | |
while corner < max | |
4.times do |i| | |
corner += step | |
sum += corner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sums(n) | |
(1..n).inject(0){|sum,i| sum + i**2} | |
end | |
def squares(n) | |
(1..n).inject(0){|sum, i| sum + i} ** 2 | |
end | |
puts squares(100) - sums(100) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import( | |
"fmt" | |
"gl" | |
"gl/glu" | |
"os" | |
"sdl" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include "letter_count.h" | |
int main (int argc, char const* argv[]) | |
{ | |
int i; | |
for (i=1;i<argc; i++){ | |
letter_distribution_of(argv[i]); |
OlderNewer