package main import ( "fmt" "math" ) // Only primes less than or equal to N will be generated const N = 10000 func main() { var x, y, n int nsqrt := math.Sqrt(N) fmt.Println("nsqrt=",nsqrt) is_prime := [N]bool{} fmt.Println("is_prime=",is_prime) for x = 1; float64(x) <= nsqrt; x++ { for y = 1; float64(y) <= nsqrt; y++ { n = 4*(x*x) + y*y if n <= N && (n%12 == 1 || n%12 == 5) { is_prime[n] = !is_prime[n] } n = 3*(x*x) + y*y if n <= N && n%12 == 7 { is_prime[n] = !is_prime[n] } n = 3*(x*x) - y*y if x > y && n <= N && n%12 == 11 { is_prime[n] = !is_prime[n] } } } for n = 5; float64(n) <= nsqrt; n++ { if is_prime[n] { for y = n * n; y < N; y += n * n { is_prime[y] = false } } } is_prime[2] = true is_prime[3] = true primes := make([]int, 0, 1270606) for x = 0; x < len(is_prime)-1; x++ { if is_prime[x] { primes = append(primes, x) } } // primes is now a slice that contains all primes numbers up to N // so let's print them for _, x := range primes { fmt.Println(x) } }
package main import "fmt" type ID int32 type Photo struct { ID ID AlbumID ID `json:"album_id"` OwberID ID UserID ID Text string Date int64 // ... } type Audio struct { ID ID OwnerID ID Artist string // ... } type Attachment struct { Type string Photo Photo Audio Audio } type Attachments []Attachment func main() { fmt.Printf("hello, world\n") }
entity UserProfile(t_user_profile) { creationDate Instant required, description String maxlength(255), name String maxlength(100), updateDate Instant } entity BankUser(t_user) { creationDate Instant required, msisdn String maxlength(20), email String required pattern(/^[^@\s]+@[^@\s]+\.[^@\s]+$/), firstname String maxlength(50), lastname String maxlength(50), updateDate Instant } relationship ManyToOne { BankUser{userProfile} to UserProfile } entity UserConnection(t_user_connection) { haction String, hresource String, hcreationDate Instant required, loginDate Instant required, logoutDate Instant } relationship ManyToOne { UserConnection{user} to BankUser } entity CustomerType(t_customer_type) { label String required maxlength(50) } entity Customer(t_customer) { active Boolean required, number String maxlength(25), corporateName String maxlength(50), tradeRegister String maxlength(50), firstname String maxlength(50), lastname String maxlength(50), birthdate String maxlength(10), gpsLatitude Double min(0), gpsLongitude Double min(0), email String pattern(/^[^@\s]+@[^@\s]+\.[^@\s]+$/), homePhone String maxlength(20), mobilePhone String maxlength(20), workPhone String maxlength(20), question String maxlength(150), qresponse String maxlength(150), address String maxlength(255), city String maxlength(50), postalCode String maxlength(10), version Integer } relationship ManyToOne { Customer{customerType} to CustomerType, Customer{bank} to Bank, Customer{user} to BankUser } enum TransactionChannel{ USSD, MOBILE, WEB, SMS, OTHERS } enum AccountSecurity{ NONE, SMS_OTP, EMAIL_OTP, SMS_EMAIL_OTP, SMS_PUSH_USSD } enum AccountType{ CUSTOMER, MERCHANT, CUSTOMER_AND_MERCHANT, OPERATION } enum TransactionType{ CASH_IN, CASH_OUT, PAYMENT, MoMo2MoMo, MoMo2Airtime, MoMo2Bank, MoMo2Card, Airtime2MoMo, Airtime2Airtime, Airtime2Bank, Airtime2Card, Bank2MoMo, Bank2Airtime, Bank2Bank, Bank2Card, Card2MoMo, Card2Airtime, Card2Bank, Card2Card } //----------------------------------- entity Currency(t_currency) { code String required maxlength(5), shortLabel String required maxlength(20), longLabel String required maxlength(50) } entity Country(t_country) { code String required maxlength(5), shortLabel String required maxlength(20), longLabel String required maxlength(50) } relationship ManyToOne { Country{currency} to Currency } entity BankAccount(t_account) { active Boolean required, number String required maxlength(30), accountType AccountType required, accountSecurity AccountSecurity required, phonenumber String maxlength(20), balance Double, pinNumber String maxlength(255), comment String maxlength(255) } relationship ManyToOne { BankAccount{bank} to Bank, BankAccount{currency} to Currency, BankAccount{customer} to Customer, } entity AccountBalance(t_account_balance) { active Boolean required, balance Double, situationDate Instant required } relationship ManyToOne { AccountBalance{bankAccount} to BankAccount } entity Bank(t_bank) { code String required maxlength(10), label String required maxlength(50) } relationship ManyToOne { Bank{country} to Country } entity Card(t_card) { active Boolean required, number String required maxlength(20), validityDate String required maxlength(8), cvv2 String required maxlength(5), pin String required maxlength(255) } relationship ManyToOne { Card{bankAccount} to BankAccount } entity Transaction(t_transaction) { transactionNumber String required maxlength(20), gatewayTransactionNumber String maxlength(20), externalMeansofpayment String maxlength(255), transactionType TransactionType required, transactionChannel TransactionChannel required, active Boolean required, transactionAmount Double, feesSupported Boolean required, changeFeesSupported Boolean required, transactionFees Double min(0), transactionChangeFees Double min(0), direction String required maxlength(1), transactionDate Instant required, comment String maxlength(255) } relationship ManyToOne { Transaction{bankAccount} to BankAccount, Transaction{transactionStatus} to TransactionStatus } entity TransactionStatus(t_transaction_status) { label String required maxlength(50) } entity Language(t_language) { lkey String required maxlength(20), lmessage String required maxlength(255) }
package main import ( //"io/ioutil" "encoding/json" "fmt" ) func main() () { content := []byte(`[ {"acl": "ACLLLLLL"}, {"acl": "ABCCCCCC"} ]`) type AclBodyPut struct { acl string `json:"acl"` } var users []AclBodyPut fmt.Printf("Initiate user=_%s_\n", users) err := json.Unmarshal(content, &users) if err != nil { fmt.Println(err) return } fmt.Printf("Initiate decode=_%s_\n json=%s\n", users, content) }
package main import "fmt" func main() { arr := []string{"one","two","three"} idx := func()int { for i , cmd := range arr { if cmd == "three" { return i } } return -1 }() arr = append(arr[:idx], arr[idx+1:]...) fmt.Printf("%v", arr) }
// MODIFY THIS AREA // [filename]: a1_q1.go // [question]: [question number] // [instagram username]: [username] package main import ("fmt" ) func main() { vowels := []string{"a", "e", "u", "i", "o"} scores := []int{12, 8, 1, 4, 3} usernames := []string{"westdabestdb", "elonmusk", "vancityreynolds", "porkbundomains", "yourusernamehere"} for _, username := range usernames { score := scoreCalculator(vowels, scores, username) fmt.Printf("%v score: %v \n",username,score) } } func scoreCalculator(vowels []string, scores []int, usernames string) int { if len(vowels) != len(scores) { return 0 } score := 0 for _, v := range usernames { for i, j := range vowels { if string(v) == j { score += scores[i] } } } return score }
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more