Set up this silly little thing
This commit is contained in:
commit
a0a38a91bd
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
elm-stuff
|
25
elm.json
Normal file
25
elm.json
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
{
|
||||||
|
"type": "application",
|
||||||
|
"source-directories": [
|
||||||
|
"src"
|
||||||
|
],
|
||||||
|
"elm-version": "0.19.1",
|
||||||
|
"dependencies": {
|
||||||
|
"direct": {
|
||||||
|
"elm/browser": "1.0.2",
|
||||||
|
"elm/core": "1.0.5",
|
||||||
|
"elm/html": "1.0.0",
|
||||||
|
"elm/random": "1.0.0"
|
||||||
|
},
|
||||||
|
"indirect": {
|
||||||
|
"elm/json": "1.1.3",
|
||||||
|
"elm/time": "1.0.0",
|
||||||
|
"elm/url": "1.0.0",
|
||||||
|
"elm/virtual-dom": "1.0.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"test-dependencies": {
|
||||||
|
"direct": {},
|
||||||
|
"indirect": {}
|
||||||
|
}
|
||||||
|
}
|
37
src/GenderFriends.elm
Normal file
37
src/GenderFriends.elm
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
module GenderFriends exposing (altBlumBlumShub, nextBlumBlumShub, BoringGender(..), PolyGender, getBoringGender, getPolygenderWithLength, renderBoringGender, renderPolygender)
|
||||||
|
|
||||||
|
m1 = 3042724273 -- Product of two 16 bit primes equivalent to 3 (mod 4)
|
||||||
|
m2 = 1922092321 -- A different product of two 16 bit primes equivalent to 3 (mod 4)
|
||||||
|
nextBlumBlumShub prev = modBy m1 (prev * prev)
|
||||||
|
altBlumBlumShub prev = modBy m2 (prev * prev)
|
||||||
|
|
||||||
|
type BoringGender = Girl | Boy
|
||||||
|
type alias PolyGender = List BoringGender
|
||||||
|
|
||||||
|
getBoringGender : Int -> (BoringGender, Int)
|
||||||
|
getBoringGender seed =
|
||||||
|
let
|
||||||
|
bitFromSeed = modBy 2 seed == 1
|
||||||
|
nextSeed = nextBlumBlumShub seed
|
||||||
|
in
|
||||||
|
(if bitFromSeed then Girl else Boy, nextSeed)
|
||||||
|
|
||||||
|
getPolygenderWithLength : Int -> Int -> (PolyGender, Int)
|
||||||
|
getPolygenderWithLength n seed = case n of
|
||||||
|
0 -> ([], seed)
|
||||||
|
_ ->
|
||||||
|
let
|
||||||
|
(recursiveCase, newSeed) = getPolygenderWithLength (n - 1) seed
|
||||||
|
(boringGender, finalSeed) = getBoringGender newSeed
|
||||||
|
in
|
||||||
|
(boringGender :: recursiveCase, finalSeed)
|
||||||
|
|
||||||
|
renderBoringGender : BoringGender -> String
|
||||||
|
renderBoringGender gender = case gender of
|
||||||
|
Boy -> "boy"
|
||||||
|
Girl -> "girl"
|
||||||
|
|
||||||
|
renderPolygender : PolyGender -> String
|
||||||
|
renderPolygender polygender = case polygender of
|
||||||
|
[] -> "friends"
|
||||||
|
head :: tail -> (renderBoringGender head) ++ (renderPolygender tail)
|
60
src/Main.elm
Normal file
60
src/Main.elm
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
module Main exposing (main)
|
||||||
|
|
||||||
|
import Browser
|
||||||
|
import Random
|
||||||
|
import Html exposing (Html, button, div, p, text)
|
||||||
|
import Html.Events exposing (onClick)
|
||||||
|
import GenderFriends exposing (altBlumBlumShub, getPolygenderWithLength, renderPolygender)
|
||||||
|
|
||||||
|
constant a b = a
|
||||||
|
|
||||||
|
main = Browser.element
|
||||||
|
{ init = init
|
||||||
|
, update = update
|
||||||
|
, subscriptions = constant Sub.none
|
||||||
|
, view = view
|
||||||
|
}
|
||||||
|
|
||||||
|
type Model
|
||||||
|
= AwaitingSeed
|
||||||
|
| Ready Int {- seed -} Int {- regeneration count -}
|
||||||
|
|
||||||
|
type Msg
|
||||||
|
= SetSeed Int
|
||||||
|
| Regenerate
|
||||||
|
|
||||||
|
init : () -> (Model, Cmd Msg)
|
||||||
|
init _ = (AwaitingSeed, Random.generate SetSeed (Random.int 2147483648 4294967296))
|
||||||
|
|
||||||
|
update : Msg -> Model -> (Model, Cmd Msg)
|
||||||
|
update msg model =
|
||||||
|
let
|
||||||
|
newModel =
|
||||||
|
case msg of
|
||||||
|
SetSeed seed -> Ready seed 0
|
||||||
|
Regenerate -> case model of
|
||||||
|
AwaitingSeed -> AwaitingSeed
|
||||||
|
Ready oldSeed regenCount -> Ready (altBlumBlumShub oldSeed) (regenCount + 1)
|
||||||
|
in
|
||||||
|
(newModel, Cmd.none)
|
||||||
|
|
||||||
|
viewStr : Model -> String
|
||||||
|
viewStr model = case model of
|
||||||
|
AwaitingSeed -> "...loading..."
|
||||||
|
Ready seed regenCount ->
|
||||||
|
let
|
||||||
|
(gender, newSeed) = getPolygenderWithLength regenCount seed
|
||||||
|
genderStr = renderPolygender gender
|
||||||
|
in "do u think a wuppie and a kitties could be " ++ genderStr ++ ",,?"
|
||||||
|
|
||||||
|
view : Model -> Html Msg
|
||||||
|
view model =
|
||||||
|
div []
|
||||||
|
[ p [] [ text (viewStr model) ]
|
||||||
|
, button
|
||||||
|
( case model of
|
||||||
|
AwaitingSeed -> []
|
||||||
|
Ready _ _ -> [onClick Regenerate]
|
||||||
|
)
|
||||||
|
[ text "make it gayer" ]
|
||||||
|
]
|
Loading…
Reference in a new issue